Partially populate the Plugin tab in the prefs UI so plugins can be enabled and disabled
This commit is contained in:
parent
6bc310d58c
commit
c649da9949
@ -39,6 +39,7 @@ class Plugin(object):
|
||||
|
||||
class PluginRegistry(borg.Borg):
|
||||
"""Definition of a class to store plugin instances"""
|
||||
available_plugins = None
|
||||
instances = None
|
||||
path = None
|
||||
done = None
|
||||
@ -61,6 +62,8 @@ class PluginRegistry(borg.Borg):
|
||||
self.path)
|
||||
if not self.done:
|
||||
self.done = False
|
||||
if not self.available_plugins:
|
||||
self.available_plugins = {}
|
||||
|
||||
def load_plugins(self, testing=False):
|
||||
"""Load all plugins present in the plugins/ directory in our module"""
|
||||
@ -85,12 +88,15 @@ class PluginRegistry(borg.Borg):
|
||||
try:
|
||||
module = __import__(plugin[:-3], None, None, [''])
|
||||
for item in getattr(module, 'AVAILABLE'):
|
||||
if item not in self.available_plugins.keys():
|
||||
func = getattr(module, item)
|
||||
self.available_plugins[item] = func
|
||||
|
||||
if not testing and item not in config['enabled_plugins']:
|
||||
dbg('plugin %s not enabled, skipping' % item)
|
||||
continue
|
||||
if item not in self.instances:
|
||||
func = getattr(module, item)
|
||||
self.instances[item] = func()
|
||||
self.instances[item] = func()
|
||||
except Exception, ex:
|
||||
err('PluginRegistry::load_plugins: Importing plugin %s \
|
||||
failed: %s' % (plugin, ex))
|
||||
@ -111,6 +117,27 @@ for %s' % (len(self.instances), capability))
|
||||
"""Return all plugins"""
|
||||
return(self.instances)
|
||||
|
||||
def get_available_plugins(self):
|
||||
"""Return a list of all available plugins whether they are enabled or
|
||||
disabled"""
|
||||
return(self.available_plugins.keys())
|
||||
|
||||
def is_enabled(self, plugin):
|
||||
"""Return a boolean value indicating whether a plugin is enabled or
|
||||
not"""
|
||||
return(self.instances.has_key(plugin))
|
||||
|
||||
def enable(self, plugin):
|
||||
"""Enable a plugin"""
|
||||
dbg("Enabling %s" % plugin)
|
||||
if plugin not in self.instances:
|
||||
self.instances[plugin] = self.available_plugins[plugin]()
|
||||
|
||||
def disable(self, plugin):
|
||||
"""Disable a plugin"""
|
||||
dbg("Disabling %s" % plugin)
|
||||
del(self.instances[plugin])
|
||||
|
||||
# This is where we should define a base class for each type of plugin we
|
||||
# support
|
||||
|
||||
|
@ -255,6 +255,14 @@
|
||||
</row>
|
||||
</data>
|
||||
</object>
|
||||
<object class="GtkListStore" id="PluginListStore">
|
||||
<columns>
|
||||
<!-- column-name Plugin -->
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name Enabled -->
|
||||
<column type="gboolean"/>
|
||||
</columns>
|
||||
</object>
|
||||
<object class="GtkDialog" id="prefswin">
|
||||
<property name="border_width">5</property>
|
||||
<property name="type_hint">normal</property>
|
||||
@ -2854,9 +2862,50 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label13">
|
||||
<object class="GtkHBox" id="hbox7">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Not yet implemented</property>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="pluginlist">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="model">PluginListStore</property>
|
||||
<property name="hadjustment">adjustment2</property>
|
||||
<property name="vadjustment">adjustment3</property>
|
||||
<property name="search_column">0</property>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn" id="plugincolumn1">
|
||||
<property name="title">Plugin</property>
|
||||
<property name="clickable">True</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererToggle" id="cellrenderertext15">
|
||||
<signal name="toggled" handler="on_plugin_toggled"/>
|
||||
</object>
|
||||
<attributes>
|
||||
<attribute name="active">1</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCellRendererText" id="cellrenderertext16"/>
|
||||
<attributes>
|
||||
<attribute name="text">0</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="pluginpanelabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">This plugin has no configuration options</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">4</property>
|
||||
|
@ -15,6 +15,7 @@ import config
|
||||
from keybindings import Keybindings, KeymapError
|
||||
from translation import _
|
||||
from terminator import Terminator
|
||||
from plugin import PluginRegistry
|
||||
|
||||
def color2hex(widget):
|
||||
"""Pull the colour values out of a Gtk ColorPicker widget and return them
|
||||
@ -26,6 +27,7 @@ def color2hex(widget):
|
||||
class PrefsEditor:
|
||||
"""Class implementing the various parts of the preferences editor"""
|
||||
config = None
|
||||
registry = None
|
||||
keybindings = None
|
||||
window = None
|
||||
builder = None
|
||||
@ -260,7 +262,19 @@ class PrefsEditor:
|
||||
keyval, mask])
|
||||
|
||||
## Plugins tab
|
||||
# FIXME: Implement this
|
||||
# Populate the plugin list
|
||||
widget = guiget('pluginlist')
|
||||
liststore = widget.get_model()
|
||||
self.registry = PluginRegistry()
|
||||
plugins = self.registry.get_available_plugins()
|
||||
self.pluginiters = {}
|
||||
for plugin in plugins:
|
||||
self.pluginiters[plugin] = liststore.append([plugin,
|
||||
self.registry.is_enabled(plugin)])
|
||||
selection = widget.get_selection()
|
||||
selection.connect('changed', self.on_plugin_selection_changed)
|
||||
if len(self.pluginiters) > 0:
|
||||
selection.select_iter(liststore.get_iter_first())
|
||||
|
||||
def set_profile_values(self, profile):
|
||||
"""Update the profile values for a given profile"""
|
||||
@ -985,6 +999,46 @@ class PrefsEditor:
|
||||
else:
|
||||
widget.set_sensitive(True)
|
||||
|
||||
def on_plugin_selection_changed(self, selection):
|
||||
"""A different plugin was selected"""
|
||||
(listmodel, rowiter) = selection.get_selected()
|
||||
if not rowiter:
|
||||
# Something is wrong, just jump to the first item in the list
|
||||
treeview = selection.get_tree_view()
|
||||
liststore = treeview.get_model()
|
||||
selection.select_iter(liststore.get_iter_first())
|
||||
return
|
||||
plugin = listmodel.get_value(rowiter, 0)
|
||||
self.set_plugin(plugin)
|
||||
self.previous_plugin_selection = plugin
|
||||
|
||||
widget = self.builder.get_object('plugintogglebutton')
|
||||
|
||||
def on_plugin_toggled(self, cell, path):
|
||||
"""A plugin has been enabled or disabled"""
|
||||
treeview = self.builder.get_object('pluginlist')
|
||||
model = treeview.get_model()
|
||||
plugin = model[path][0]
|
||||
|
||||
state = self.registry.is_enabled(plugin)
|
||||
if state:
|
||||
self.registry.disable(plugin)
|
||||
else:
|
||||
self.registry.enable(plugin)
|
||||
state = self.registry.is_enabled(plugin)
|
||||
# Update the treeview
|
||||
model[path][1] = state
|
||||
|
||||
enabled_plugins = self.registry.get_all_plugins().keys()
|
||||
self.config['enabled_plugins'] = enabled_plugins
|
||||
self.config.save()
|
||||
|
||||
def set_plugin(self, plugin):
|
||||
"""Show the preferences for the selected plugin, if any"""
|
||||
pluginpanelabel = self.builder.get_object('pluginpanelabel')
|
||||
pluginconfig = self.config.plugin_get_config(plugin)
|
||||
# FIXME: Implement this, we need to auto-construct a UI for the plugin
|
||||
|
||||
def on_profile_name_edited(self, cell, path, newtext):
|
||||
"""Update a profile name"""
|
||||
oldname = cell.get_property('text')
|
||||
|
Loading…
Reference in New Issue
Block a user