summaryrefslogtreecommitdiff
path: root/kberylsettings/plugindialog.py
diff options
context:
space:
mode:
authornatural <natural>2006-12-16 03:19:59 +0000
committernatural <natural>2006-12-16 03:19:59 +0000
commitfcfa23f8e1b16bc68329c9e9aa3cb31d906ee572 (patch)
treee848ae85999e5221acd8d001317807fd35068403 /kberylsettings/plugindialog.py
parentc32078c7602fd7a32100188aaa6b3fef3115afce (diff)
downloadkberylsettings-fcfa23f8e1b16bc68329c9e9aa3cb31d906ee572.tar.gz
kberylsettings-fcfa23f8e1b16bc68329c9e9aa3cb31d906ee572.tar.bz2
Added LICENCE file.
Removed TODO -- don't really need to see what's on my plate. Added plugindialog.py for selecting plugins. Updated pluginframe.py and main.py to reflect. Tweaked plugin.html -- still needs much work. Added Signals.okClicked and Signals.activated to lib.py.
Diffstat (limited to 'kberylsettings/plugindialog.py')
-rw-r--r--kberylsettings/plugindialog.py81
1 files changed, 81 insertions, 0 deletions
diff --git a/kberylsettings/plugindialog.py b/kberylsettings/plugindialog.py
new file mode 100644
index 0000000..5c395a2
--- /dev/null
+++ b/kberylsettings/plugindialog.py
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+from qt import QCheckListItem, QLabel
+from kdecore import i18n
+from kdeui import KDialogBase, KListView
+
+from kberylsettings.lib import Signals
+
+
+class PluginList(KListView):
+ """ PluginList -> list view for the select plugins dialog
+
+ """
+ def __init__(self, parent):
+ KListView.__init__(self, parent)
+ self.addColumn(i18n('Plugin'))
+ self.addColumn(i18n('Description'))
+
+ def addPlugins(self, context, loader):
+ """ creates list view items from plugins in context
+
+ @param context berylsetting Context instance
+ @param loader KIconLoader instance
+ @return mapping of plugin names and their enabled state
+ """
+ stateMap = {}
+ active = context.active
+ count = textlen = 0
+ for p in context.plugins:
+ item = QCheckListItem(self, p.ShortDesc, QCheckListItem.CheckBox)
+ item.setEnabled(not p.isGeneral)
+ item.setText(1, p.LongDesc)
+ item.setPixmap(0, p.icon(16, loader))
+ if p.Name in active:
+ stateMap[p.Name] = 1
+ item.setState(QCheckListItem.On)
+ else:
+ stateMap[p.Name] = 0
+ count += 1
+ textlen = max(textlen, len(p.ShortDesc + p.LongDesc))
+
+ self.adjustMinSize(count, textlen)
+ return stateMap
+
+ def adjustMinSize(self, count, maxlen):
+ """ adjusts minimum size based on child count and text length
+
+ @param count number of items
+ @param maxlen maximum length of item text (all columns)
+ @return None
+ """
+ height = count * self.fontMetrics().height()
+ self.setMinimumHeight(height * 0.5)
+ width = maxlen * self.fontMetrics().maxWidth() * 0.25
+ self.setMinimumWidth(width)
+
+
+class PluginDialog(KDialogBase):
+ """ PluginDialog -> a dialog for enabling and disabling plugins
+
+ """
+ def __init__(self, parent, context):
+ KDialogBase.__init__(self, parent, '', True, i18n('Select Plugins'),
+ KDialogBase.Ok|KDialogBase.Cancel)
+ self.context = context
+ main = self.makeVBoxMainWidget()
+ self.label = QLabel('Enable or disable plugins below.', main)
+ self.listView = PluginList(main)
+ self.connect(self.listView, Signals.itemClicked, self.changePlugin)
+ self.pluginMap = self.listView.addPlugins(context, parent.loader)
+
+
+ def changePlugin(self, item):
+ if not item:
+ return
+ state = item.state()
+ plugin = self.context.plugin(item.text(0))
+ if state == item.On:
+ self.pluginMap[plugin.Name] = 1
+ elif state == item.Off:
+ self.pluginMap[plugin.Name] = 0