Zim

Merge lp:~johannes-reinhardt/zim/fixes into lp:~jaap.karssenberg/zim/pyzim

Proposed by Johannes Reinhardt
Status: Merged
Merged at revision: not available
Proposed branch: lp:~johannes-reinhardt/zim/fixes
Merge into: lp:~jaap.karssenberg/zim/pyzim
Diff against target: 377 lines (+93/-37)
14 files modified
data/manual/Plugins.txt (+1/-3)
tests/plugins.py (+12/-0)
zim/formats/wiki.py (+5/-1)
zim/gui/pageview.py (+1/-1)
zim/gui/preferencesdialog.py (+41/-9)
zim/gui/widgets.py (+2/-1)
zim/plugins/__init__.py (+8/-0)
zim/plugins/diagrameditor.py (+1/-5)
zim/plugins/equationeditor.py (+2/-6)
zim/plugins/linkmap/__init__.py (+5/-3)
zim/plugins/scrot.py (+4/-2)
zim/plugins/spell.py (+2/-6)
zim/plugins/trayicon.py (+4/-0)
zim/plugins/versioncontrol/__init__.py (+5/-0)
To merge this branch: bzr merge lp:~johannes-reinhardt/zim/fixes
Reviewer Review Type Date Requested Status
Jaap Karssenberg Approve
Review via email: mp+20815@code.launchpad.net

Description of the change

This branch contains fixes for several bugs, including
https://bugs.launchpad.net/zim/+bug/529360
https://bugs.launchpad.net/zim/+bug/505743
https://bugs.launchpad.net/zim/+bug/515752

It introduces a way for plugins to communicate if their dependencies are met.

To post a comment you must log in.
Revision history for this message
Jaap Karssenberg (jaap.karssenberg) :
review: Approve
lp:~johannes-reinhardt/zim/fixes updated
210. By Jaap Karssenberg

Merged latex export code

211. By Jaap Karssenberg

Merged various patches, including fix to check plugin dependencies

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/manual/Plugins.txt'
2--- data/manual/Plugins.txt 2010-01-19 18:41:47 +0000
3+++ data/manual/Plugins.txt 2010-03-07 14:45:49 +0000
4@@ -15,8 +15,6 @@
5 * [[+Tray Icon|Tray Icon]]
6 * [[+Version Control|Version Control]]
7
8-Plugins can be enabled and configured in the [[Help:Preferences|preferences dialog]].
9-
10-A number of plugins have additional dependencies, like specific external programs, that are not required for the core functionality of zim.
11+Plugins can be enabled and configured in the [[Help:Preferences|preferences dialog]]. A number of plugins have additional dependencies, like specific external programs, that are not required for the core functionality of zim. If one or more dependencies of a plugin are not fulfilled, these are marked red.
12
13 If you are looking for information on **writing plugins** please download the source package and have a look at the notes included in the "HACKING" folder.
14
15=== modified file 'tests/plugins.py'
16--- tests/plugins.py 2010-02-15 21:41:46 +0000
17+++ tests/plugins.py 2010-03-07 14:45:49 +0000
18@@ -22,3 +22,15 @@
19 self.assertTrue('spell' in plugins)
20 self.assertTrue('linkmap' in plugins)
21
22+ def testDependencies(self):
23+ '''test if all plugins provide correct dependency infos'''
24+ plugins = zim.plugins.list_plugins()
25+ for name in plugins:
26+ plugin = zim.plugins.get_plugin(name)
27+ dep = plugin.check_dependencies()
28+ assert isinstance(dep,list)
29+ for i in range(len(dep)):
30+ assert isinstance(dep[i],tuple)
31+ assert isinstance(dep[i][0],str)
32+ assert isinstance(dep[i][1],bool)
33+
34
35=== modified file 'zim/formats/wiki.py'
36--- zim/formats/wiki.py 2010-02-18 18:16:31 +0000
37+++ zim/formats/wiki.py 2010-03-07 14:45:49 +0000
38@@ -346,7 +346,11 @@
39 else:
40 output.append('[['+href+']]')
41 else:
42- output.append('[['+href+'|'+element.text+']]')
43+ if element.text:
44+ output.append('[['+href+'|'+element.text+']]')
45+ else:
46+ output.append('[['+href+']]')
47+
48 elif element.tag in dumper_tags:
49 tag = dumper_tags[element.tag]
50 output.append(tag+element.text+tag)
51
52=== modified file 'zim/gui/pageview.py'
53--- zim/gui/pageview.py 2010-02-26 22:18:42 +0000
54+++ zim/gui/pageview.py 2010-03-07 14:45:49 +0000
55@@ -3705,7 +3705,7 @@
56 def do_height_changed(self):
57 if self._block: return
58 self._image_data.pop('width', None)
59- self._image_data['height'] = self.get_field('height')
60+ self._image_data['height'] = float(self.get_field('height'))
61 w = int(self._ratio * self._image_data['height'])
62 self._block = True
63 self.inputs['width'].set_value(w)
64
65=== modified file 'zim/gui/preferencesdialog.py'
66--- zim/gui/preferencesdialog.py 2010-01-10 21:04:16 +0000
67+++ zim/gui/preferencesdialog.py 2010-03-07 14:45:49 +0000
68@@ -155,9 +155,6 @@
69
70 class PluginsTab(gtk.HBox):
71
72- # TODO defined checks for plugin dependencies and grey them out here if
73- # the check fails - or give an error popup with the result of the check
74-
75 def __init__(self, dialog):
76 gtk.HBox.__init__(self, spacing=12)
77 self.set_border_width(5)
78@@ -190,6 +187,10 @@
79 self.description_label = gtk.Label()
80 self.description_label.set_alignment(0.0, 0.5)
81 vbox.pack_start(self.description_label, False) # FIXME run through plain format to make links
82+ vbox.pack_start(heading('\n'+_('Dependencies')),False)
83+ self.dep_label = gtk.Label()
84+ self.dep_label.set_alignment(0.0, 0.5)
85+ vbox.pack_start(self.dep_label, False)
86 vbox.pack_start(heading('\n'+_('Author')), False)
87 # T: Heading in plugins tab of preferences dialog
88 self.author_label= gtk.Label()
89@@ -213,10 +214,31 @@
90
91 def do_row_activated(self, treeview, path, col):
92 active = treeview.get_model()[path][0]
93- klass = treeview.get_model()[path][2]
94+ activatable = treeview.get_model()[path][1]
95+ klass = treeview.get_model()[path][3]
96 self._klass = klass
97+ #construct dependency list, missing dependencies are marked red
98+ space = False
99+ depend_label = ''
100+ dependencies = klass.check_dependencies()
101+ for text, met in dependencies:
102+ if space:
103+ depend_label += ' '
104+ else:
105+ space = True
106+ if met:
107+ depend_label += text
108+ else:
109+ depend_label += '<span color="red">' + text + '</span>'
110+ if depend_label == '':
111+ depend_label = 'No dependencies'
112+
113 self.name_label.set_text(klass.plugin_info['name'].strip())
114 self.description_label.set_text(klass.plugin_info['description'].strip())
115+ if not activatable:
116+ self.dep_label.set_markup(depend_label)
117+ else:
118+ self.dep_label.set_text(depend_label)
119 self.author_label.set_text(klass.plugin_info['author'].strip() + '\n')
120 self.configure_button.set_sensitive(active and bool(klass.plugin_preferences))
121 self.plugin_help_button.set_sensitive('help' in klass.plugin_info)
122@@ -231,7 +253,8 @@
123 class PluginsTreeModel(gtk.ListStore):
124
125 def __init__(self, ui):
126- gtk.ListStore.__init__(self, bool, str, object)
127+ #columns are: loaded, activable, name, plugin instance
128+ gtk.ListStore.__init__(self, bool, bool, str, object)
129 self.ui = ui
130 loaded = [p.__class__ for p in self.ui.plugins]
131 for name in zim.plugins.list_plugins():
132@@ -242,10 +265,19 @@
133 continue
134 else:
135 l = klass in loaded
136- self.append((l, klass.plugin_info['name'], klass))
137+ dependencies = klass.check_dependencies()
138+ activatable = True
139+ for dep in dependencies:
140+ activatable = activatable and dep[1]
141+ if not activatable and l:
142+ self.ui.unload_plugin(klass.plugin_key)
143+ l = False
144+ self.append((l, activatable, klass.plugin_info['name'], klass))
145
146 def do_toggle_path(self, path):
147- loaded, name, klass = self[path]
148+ loaded, activatable, name, klass = self[path]
149+ if not activatable:
150+ return
151 if loaded:
152 self.ui.unload_plugin(klass.plugin_key)
153 self[path][0] = False
154@@ -265,10 +297,10 @@
155 cellrenderer = gtk.CellRendererToggle()
156 cellrenderer.connect('toggled', lambda o, p: model.do_toggle_path(p))
157 self.append_column(
158- gtk.TreeViewColumn(_('Enabled'), cellrenderer, active=0))
159+ gtk.TreeViewColumn(_('Enabled'), cellrenderer, active=0, activatable=1))
160 # T: Column in plugin tab
161 self.append_column(
162- gtk.TreeViewColumn(_('Plugin'), gtk.CellRendererText(), text=1))
163+ gtk.TreeViewColumn(_('Plugin'), gtk.CellRendererText(), text=2))
164 # T: Column in plugin tab
165
166
167
168=== modified file 'zim/gui/widgets.py'
169--- zim/gui/widgets.py 2010-02-22 21:34:10 +0000
170+++ zim/gui/widgets.py 2010-03-07 14:45:49 +0000
171@@ -634,7 +634,7 @@
172 def add_fields(self, fields, table=None, trigger_response=True):
173 '''Add a number of fields to the dialog, convenience method to
174 construct simple forms. The argument 'fields' should be a list of
175- field definitions; each definition is a tupple of:
176+ field definitions; each definition is a tuple of:
177
178 * The field name
179 * The field type
180@@ -676,6 +676,7 @@
181 v, min, max = value
182 button.set_value(v)
183 button.set_range(min, max)
184+ button.set_increments(1,5)
185 self.inputs[name] = button
186 table.attach(button, 1,2, i,i+1)
187 elif type == 'list':
188
189=== modified file 'zim/plugins/__init__.py'
190--- zim/plugins/__init__.py 2009-12-14 19:04:41 +0000
191+++ zim/plugins/__init__.py 2010-03-07 14:45:49 +0000
192@@ -117,6 +117,14 @@
193 for key, value in defaults.items():
194 self.uistate.setdefault(key, value)
195
196+ @classmethod
197+ def check_dependencies(klass):
198+ '''This method checks which dependencies are met'''
199+ #returns a list of tuples, one for each dependency.
200+ #each tuple contains a string with the name of the dependency and a
201+ #boolean indicating if it is fulfilled
202+ return []
203+
204 def do_preferences_changed(self):
205 '''Handler called when preferences are changed by the user.
206 Can be overloaded by sub classes to apply relevant changes.
207
208=== modified file 'zim/plugins/diagrameditor.py'
209--- zim/plugins/diagrameditor.py 2009-11-29 18:47:42 +0000
210+++ zim/plugins/diagrameditor.py 2010-03-07 14:45:49 +0000
211@@ -39,8 +39,6 @@
212 'description': _('''\
213 This plugin provides an diagram editor for zim based on GraphViz.
214
215-Depends on: the GraphViz 'dot' command
216-
217 This is a core plugin shipping with zim.
218 '''), # T: plugin description
219 'help': ':Plugins:Diagram Editor',
220@@ -49,9 +47,7 @@
221
222 @classmethod
223 def check_dependencies(klass):
224- return Application(dotcmd).tryexec()
225- # TODO feedback a readon for use in popup etc
226- # TODO nicer interface for this - note also test uses this
227+ return [("GraphViz 'dot' command",Application(dotcmd).tryexec())]
228
229 def __init__(self, ui):
230 PluginClass.__init__(self, ui)
231
232=== modified file 'zim/plugins/equationeditor.py'
233--- zim/plugins/equationeditor.py 2009-11-29 18:47:42 +0000
234+++ zim/plugins/equationeditor.py 2010-03-07 14:45:49 +0000
235@@ -42,8 +42,6 @@
236 'description': _('''\
237 This plugin provides an equation editor for zim based on latex.
238
239-Depends on: latex, dvipng
240-
241 This is a core plugin shipping with zim.
242 '''), # T: plugin description
243 'help': ':Plugins:Equation Editor',
244@@ -52,10 +50,8 @@
245
246 @classmethod
247 def check_dependencies(klass):
248- return Application(latexcmd).tryexec() \
249- and Application(dvipngcmd).tryexec()
250- # TODO feedback a readon for use in popup etc
251- # TODO nicer interface for this - note also test uses this
252+ return [('latex',Application(latexcmd).tryexec()), \
253+ ('dvipng',Application(dvipngcmd).tryexec())]
254
255 def __init__(self, ui):
256 PluginClass.__init__(self, ui)
257
258=== modified file 'zim/plugins/linkmap/__init__.py'
259--- zim/plugins/linkmap/__init__.py 2010-02-26 22:18:42 +0000
260+++ zim/plugins/linkmap/__init__.py 2010-03-07 14:45:49 +0000
261@@ -6,6 +6,7 @@
262
263 from zim.plugins import PluginClass
264 from zim.index import LINK_DIR_BOTH
265+from zim.applications import Application
266
267 class LinkMapPlugin(PluginClass):
268
269@@ -17,9 +18,6 @@
270 notebook. It can be used as a kind of "mind map"
271 showing how pages relate.
272
273-This plugin depends on GraphViz, please make
274-sure it is installed.
275-
276 This is a core plugin shipping with zim.
277 '''), # T: plugin description
278 'author': 'Jaap Karssenberg',
279@@ -34,6 +32,10 @@
280 else:
281 self.gui = False
282
283+ @classmethod
284+ def check_dependencies(klass):
285+ return [('GraphViz',Application(('dot',)).tryexec())]
286+
287 def disconnect(self):
288 pass
289
290
291=== modified file 'zim/plugins/scrot.py'
292--- zim/plugins/scrot.py 2009-12-06 19:36:49 +0000
293+++ zim/plugins/scrot.py 2010-03-07 14:45:49 +0000
294@@ -39,8 +39,6 @@
295 It allows taking a screenshot and directly insert it
296 in a zim page.
297
298-Depends on: scrot
299-
300 This is a core plugin shipping with zim.
301 '''), # T: plugin description
302 'author': 'Jaap Karssenberg',
303@@ -53,6 +51,10 @@
304 self.ui.add_actions(ui_actions, self)
305 self.ui.add_ui(ui_xml, self)
306
307+ @classmethod
308+ def check_dependencies(klass):
309+ return [('scrot',Application(('scrot',)).tryexec())]
310+
311 def insert_screenshot(self):
312 dialog = InsertScreenshotDialog.unique(self, self.ui)
313 dialog.show_all()
314
315=== modified file 'zim/plugins/spell.py'
316--- zim/plugins/spell.py 2009-12-06 19:36:49 +0000
317+++ zim/plugins/spell.py 2010-03-07 14:45:49 +0000
318@@ -41,7 +41,6 @@
319 'name': _('Spell Checker'), # T: plugin name
320 'description': _('''\
321 Adds spell checking support using gtkspell.
322-Please make sure gtkspell is installed.
323
324 This is a core plugin shipping with zim.
325 '''), # T: plugin description
326@@ -63,11 +62,8 @@
327 self.ui.connect_after('open-page', self.do_open_page)
328
329 @classmethod
330- def check(cls):
331- if gtkspell is None:
332- return False, 'Could not load gtkspell'
333- else:
334- return True
335+ def check_dependencies(klass):
336+ return [('gtkspell',not gtkspell is None)]
337
338 def toggle_spellcheck(self, enable=None):
339 action = self.actiongroup.get_action('toggle_spellcheck')
340
341=== modified file 'zim/plugins/trayicon.py'
342--- zim/plugins/trayicon.py 2010-01-24 19:23:38 +0000
343+++ zim/plugins/trayicon.py 2010-03-07 14:45:49 +0000
344@@ -44,6 +44,10 @@
345 self.icon = StandAloneTrayIcon(self.ui)
346 self.ui.hideonclose = True
347
348+ @classmethod
349+ def check_dependencies(klass):
350+ return [('GTK > 2.10',gtk.gtk_version > (2, 10, 0))]
351+
352 def disconnect(self):
353 if self.icon:
354 self.icon.set_visible(False)
355
356=== modified file 'zim/plugins/versioncontrol/__init__.py'
357--- zim/plugins/versioncontrol/__init__.py 2010-02-21 11:04:55 +0000
358+++ zim/plugins/versioncontrol/__init__.py 2010-03-07 14:45:49 +0000
359@@ -9,6 +9,7 @@
360 from zim.fs import File
361 from zim.plugins import PluginClass
362 from zim.errors import Error
363+from zim.applications import Application
364
365 from zim.gui.widgets import SingleClickTreeView, Dialog, PageEntry, IconButton, scrolled_text_view, QuestionDialog
366
367@@ -88,6 +89,10 @@
368 self.autosave()
369 self.ui.connect('quit', on_quit)
370
371+ @classmethod
372+ def check_dependencies(klass):
373+ return [('bzr',Application(('bzr',)).tryexec())]
374+
375 def detect_vcs(self):
376 dir = self._get_notebook_dir()
377 self.vcs = self._detect_vcs(dir)