~parinporecha/gtg/config_parser_bug

« back to all changes in this revision

Viewing changes to GTG/gtk/plugins.py

  • Committer: Izidor Matušov
  • Date: 2013-02-25 07:35:07 UTC
  • Revision ID: izidor.matusov@gmail.com-20130225073507-vgts69uthx7z2run
PEP8ification by Nimit

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
PLUGINS_COL_ACTIVATABLE = 4
37
37
 
38
38
 
39
 
def plugin_icon(column, cell, store, iterator): # pylint: disable-msg=W0613
 
39
def plugin_icon(column, cell, store, iterator):  # pylint: disable-msg=W0613
40
40
    """ Callback to set the content of a PluginTree cell.
41
41
 
42
42
    See PluginsDialog._init_plugin_tree().
43
43
    """
44
44
    cell.set_property('icon-name', 'gtg-plugin')
45
45
    cell.set_property('sensitive',
46
 
        store.get_value(iterator, PLUGINS_COL_ACTIVATABLE))
 
46
                      store.get_value(iterator, PLUGINS_COL_ACTIVATABLE))
47
47
 
48
48
 
49
49
def plugin_error_short_text(plugin):
126
126
 
127
127
    cell.set_property('markup', text)
128
128
    cell.set_property('sensitive',
129
 
        store.get_value(iterator, PLUGINS_COL_ACTIVATABLE))
 
129
                      store.get_value(iterator, PLUGINS_COL_ACTIVATABLE))
130
130
 
131
131
 
132
132
class PluginsDialog:
146
146
        self.plugin_depends = builder.get_object('PluginDepends')
147
147
 
148
148
        self.pengine = PluginEngine()
149
 
        #plugin config initiation, if never used
 
149
        # plugin config initiation, if never used
150
150
        if "plugins" in self.config:
151
151
            if "enabled" not in self.config["plugins"]:
152
152
                self.config["plugins"]["enabled"] = []
156
156
        elif self.pengine.get_plugins():
157
157
            self.config["plugins"] = {}
158
158
            self.config["plugins"]["disabled"] = \
159
 
              [p.module_name for p in self.pengine.get_plugins("disabled")]
 
159
                [p.module_name for p in self.pengine.get_plugins("disabled")]
160
160
            self.config["plugins"]["enabled"] = \
161
 
              [p.module_name for p in self.pengine.get_plugins("enabled")]
 
161
                [p.module_name for p in self.pengine.get_plugins("enabled")]
162
162
 
163
163
        # see constants PLUGINS_COL_* for column meanings
164
164
        self.plugin_store = gtk.ListStore(str, bool, str, str, bool)
165
165
 
166
166
        builder.connect_signals({
167
 
          'on_plugins_help':
168
 
            self.on_help,
169
 
          'on_plugins_close':
170
 
            self.on_close,
171
 
          'on_PluginsDialog_delete_event':
172
 
            self.on_close,
173
 
          'on_PluginTree_cursor_changed':
174
 
            self.on_plugin_select,
175
 
          'on_plugin_about':
176
 
            self.on_plugin_about,
177
 
          'on_plugin_configure':
178
 
            self.on_plugin_configure,
179
 
          'on_PluginAboutDialog_close':
180
 
            self.on_plugin_about_close,
181
 
          })
 
167
                                'on_plugins_help':
 
168
                                self.on_help,
 
169
                                'on_plugins_close':
 
170
                                self.on_close,
 
171
                                'on_PluginsDialog_delete_event':
 
172
                                self.on_close,
 
173
                                'on_PluginTree_cursor_changed':
 
174
                                self.on_plugin_select,
 
175
                                'on_plugin_about':
 
176
                                self.on_plugin_about,
 
177
                                'on_plugin_configure':
 
178
                                self.on_plugin_configure,
 
179
                                'on_PluginAboutDialog_close':
 
180
                                self.on_plugin_about_close,
 
181
                                })
182
182
 
183
183
    def _init_plugin_tree(self):
184
184
        """ Initialize the PluginTree gtk.TreeView.
195
195
        renderer.connect('toggled', self.on_plugin_toggle)
196
196
        # toggle column
197
197
        column = gtk.TreeViewColumn(None, renderer, active=PLUGINS_COL_ENABLED,
198
 
          activatable=PLUGINS_COL_ACTIVATABLE,
199
 
          sensitive=PLUGINS_COL_ACTIVATABLE)
 
198
                                    activatable=PLUGINS_COL_ACTIVATABLE,
 
199
                                    sensitive=PLUGINS_COL_ACTIVATABLE)
200
200
        self.plugin_tree.append_column(column)
201
201
 
202
202
        # plugin name column
227
227
        for name, plugin in self.pengine.plugins.iteritems():
228
228
            # activateable if there is no error
229
229
            self.plugin_store.append((name, plugin.enabled, plugin.full_name,
230
 
              plugin.short_description, not plugin.error))
 
230
                                      plugin.short_description,
 
231
                                      not plugin.error))
231
232
 
232
233
    def activate(self):
233
234
        """ Refresh status of plugins and show the dialog """
237
238
            self._refresh_plugin_store()
238
239
        self.dialog.show_all()
239
240
 
240
 
    def on_close(self, widget, data=None): # pylint: disable-msg=W0613
 
241
    def on_close(self, widget, data=None):  # pylint: disable-msg=W0613
241
242
        """ Close the plugins dialog."""
242
243
        self.dialog.hide()
243
244
        return True
244
245
 
245
246
    @classmethod
246
 
    def on_help(cls, widget): # pylint: disable-msg=W0613
 
247
    def on_help(cls, widget):  # pylint: disable-msg=W0613
247
248
        """ In future, this will open help for plugins """
248
249
        return True
249
250
 
250
 
    def on_plugin_toggle(self, widget, path): # pylint: disable-msg=W0613
 
251
    def on_plugin_toggle(self, widget, path):  # pylint: disable-msg=W0613
251
252
        """Toggle a plugin enabled/disabled."""
252
253
        iterator = self.plugin_store.get_iter(path)
253
254
        plugin_id = self.plugin_store.get_value(iterator, PLUGINS_COL_ID)
254
255
        plugin = self.pengine.get_plugin(plugin_id)
255
256
        plugin.enabled = not self.plugin_store.get_value(iterator,
256
 
                                                PLUGINS_COL_ENABLED)
 
257
                                                         PLUGINS_COL_ENABLED)
257
258
        if plugin.enabled:
258
259
            self.pengine.activate_plugins([plugin])
259
260
            self.config["plugins"]["enabled"].append(plugin.module_name)
265
266
            if plugin.module_name in self.config["plugins"]["enabled"]:
266
267
                self.config["plugins"]["enabled"].remove(plugin.module_name)
267
268
        self.plugin_store.set_value(iterator, PLUGINS_COL_ENABLED,
268
 
                                                            plugin.enabled)
 
269
                                    plugin.enabled)
269
270
        self._update_plugin_configure(plugin)
270
271
 
271
272
        self.config_obj.save()
285
286
        configurable = plugin.active and plugin.is_configurable()
286
287
        self.plugin_configure.set_property('sensitive', configurable)
287
288
 
288
 
    def on_plugin_configure(self, widget): # pylint: disable-msg=W0613
 
289
    def on_plugin_configure(self, widget):  # pylint: disable-msg=W0613
289
290
        """ Show the dialog for plugin configuration """
290
291
        _, iterator = self.plugin_tree.get_selection().get_selected()
291
292
        if iterator is None:
294
295
        plugin = self.pengine.get_plugin(plugin_id)
295
296
        plugin.instance.configure_dialog(self.dialog)
296
297
 
297
 
    def on_plugin_about(self, widget): # pylint: disable-msg=W0613
 
298
    def on_plugin_about(self, widget):  # pylint: disable-msg=W0613
298
299
        """ Display information about a plugin. """
299
300
        _, iterator = self.plugin_tree.get_selection().get_selected()
300
301
        if iterator is None:
307
308
        authors = plugin.authors
308
309
        if isinstance(authors, str):
309
310
            authors = "\n".join(author.strip()
310
 
                    for author in authors.split(','))
 
311
                                for author in authors.split(','))
311
312
            authors = [authors, ]
312
313
        self.plugin_about.set_authors(authors)
313
314
        description = plugin.description.replace(r'\n', "\n")