summaryrefslogtreecommitdiff
path: root/kberylsettings/plugindialog.py
diff options
context:
space:
mode:
authornatural <natural>2006-12-17 10:06:18 +0000
committernatural <natural>2006-12-17 10:06:18 +0000
commit99b44818d60794aae11dca5f67722ab32c98f137 (patch)
tree8e54863077d35d0cbb88925c3fd012827d328a80 /kberylsettings/plugindialog.py
parentfcfa23f8e1b16bc68329c9e9aa3cb31d906ee572 (diff)
downloadkberylsettings-99b44818d60794aae11dca5f67722ab32c98f137.tar.gz
kberylsettings-99b44818d60794aae11dca5f67722ab32c98f137.tar.bz2
Implemented search -- search for plugin settings by keyword.
Refactored views and content frames. Many docstrings.
Diffstat (limited to 'kberylsettings/plugindialog.py')
-rw-r--r--kberylsettings/plugindialog.py69
1 files changed, 64 insertions, 5 deletions
diff --git a/kberylsettings/plugindialog.py b/kberylsettings/plugindialog.py
index 5c395a2..dc97831 100644
--- a/kberylsettings/plugindialog.py
+++ b/kberylsettings/plugindialog.py
@@ -1,8 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+""" kberylsettings.plugindialog -> defines a dialog box for selecting plugins.
+
+"""
from qt import QCheckListItem, QLabel
from kdecore import i18n
-from kdeui import KDialogBase, KListView
+from kdeui import KDialogBase, KListView, KMessageBox
from kberylsettings.lib import Signals
@@ -51,7 +54,7 @@ class PluginList(KListView):
"""
height = count * self.fontMetrics().height()
self.setMinimumHeight(height * 0.5)
- width = maxlen * self.fontMetrics().maxWidth() * 0.25
+ width = maxlen * self.fontMetrics().maxWidth() * 0.2
self.setMinimumWidth(width)
@@ -69,13 +72,69 @@ class PluginDialog(KDialogBase):
self.connect(self.listView, Signals.itemClicked, self.changePlugin)
self.pluginMap = self.listView.addPlugins(context, parent.loader)
-
def changePlugin(self, item):
+ """ handle a possible change to the plugins checkbox
+
+ @param item QCheckListItem instance
+ @return None
+ """
if not item:
return
- state = item.state()
plugin = self.context.plugin(item.text(0))
+ state = item.state()
if state == item.On:
self.pluginMap[plugin.Name] = 1
+ self.satisfy(plugin)
elif state == item.Off:
- self.pluginMap[plugin.Name] = 0
+ remaining = self.needs(plugin)
+ if remaining:
+ item.setState(item.On)
+ text = 'Cannot remove plugin "%s" required by %s.'
+ need = ['"%s"' % r.ShortDesc for r in remaining]
+ text %= (plugin.ShortDesc, str.join(', ', need))
+ KMessageBox.sorry(self, text)
+ else:
+ self.pluginMap[plugin.Name] = 0
+
+ def satisfy(self, plugin):
+ """ enable requirement for plugin if necessary
+
+ @param plugin berylsettings Plugin instance
+ @return None
+ """
+ for requirement in plugin.Requires:
+ for p in self.context.plugins:
+ if requirement in p.Provides:
+ if not self.pluginMap[p.Name]:
+ self.pluginMap[p.Name] = 1
+ item = self.listView.findItem(p.ShortDesc, 0)
+ if item:
+ item.setState(item.On)
+ for req in p.Requires:
+ self.satisfy(p)
+
+ def needs(self, plugin):
+ """ check that all requirements for plugin are met
+
+ @param plugin berylsettings Plugin instance
+ @return sequence of required plugins
+ """
+ pending = self.pending(plugin)
+ allProvided = []
+ for p in pending:
+ allProvided.extend(p.Provides)
+ notMet = []
+ for p in pending:
+ for req in p.Requires:
+ if req not in allProvided:
+ notMet.append(p)
+ return notMet
+
+ def pending(self, exclude):
+ """ generates a sequence of enabled plugins, based on current selections
+
+ @param exclude plugin to exclude from returned list
+ @return list of berylsetting Plugin instances
+ """
+ names = [name for name, enabled in self.pluginMap.items() if enabled]
+ return [self.context.plugin(n) for n in names if n != exclude.Name]