diff options
author | natural <natural> | 2006-12-20 13:04:14 +0000 |
---|---|---|
committer | natural <natural> | 2006-12-20 13:04:14 +0000 |
commit | a4fcfeb8b855e88d8e662c562dfbd6c9370793a1 (patch) | |
tree | 358a4613daa335395615c6e77bba5b85716f7f95 /kberylsettings | |
parent | 9a71cc9d01fc4eb398aea5efdd1b9b7f85824898 (diff) | |
download | kberylsettings-a4fcfeb8b855e88d8e662c562dfbd6c9370793a1.tar.gz kberylsettings-a4fcfeb8b855e88d8e662c562dfbd6c9370793a1.tar.bz2 |
Reworked setting widgets.
Added depcheck script.
Diffstat (limited to 'kberylsettings')
-rw-r--r-- | kberylsettings/beryl.py | 1 | ||||
-rw-r--r-- | kberylsettings/contentframe.py | 41 | ||||
-rw-r--r-- | kberylsettings/lib.py | 7 | ||||
-rw-r--r-- | kberylsettings/main.py | 38 | ||||
-rw-r--r-- | kberylsettings/settingframe.py | 18 | ||||
-rw-r--r-- | kberylsettings/settingwidget.py | 456 |
6 files changed, 348 insertions, 213 deletions
diff --git a/kberylsettings/beryl.py b/kberylsettings/beryl.py index 8814b68..5bb91b6 100644 --- a/kberylsettings/beryl.py +++ b/kberylsettings/beryl.py @@ -89,6 +89,7 @@ class Context(QObject): """ self.emit(Signals.statusMessage, ('Saving Beryl settings....', )) self.context.write() + self.reload() def reload(self): """ messages the extension to reload the new settings diff --git a/kberylsettings/contentframe.py b/kberylsettings/contentframe.py index 1ce0728..9880925 100644 --- a/kberylsettings/contentframe.py +++ b/kberylsettings/contentframe.py @@ -65,14 +65,12 @@ class ContentFrame(WidgetStack): return button self.helpButton = contentButton('help') - self.helpButton.setEnabled(False) self.defaultsButton = contentButton('defaults') - self.defaultsButton.setEnabled(False) layout.addStretch(100) self.applyButton = contentButton('apply') - #self.applyButton.setEnabled(False) + self.applyButton.setEnabled(False) self.resetButton = contentButton('reset') - self.resetButton.setEnabled(False) + self.resetButton.setEnabled(False) self.addWidget(self.settingsPage, self.settingsPageId) def buildConnections(self): @@ -83,10 +81,17 @@ class ContentFrame(WidgetStack): connect = self.connect connect(self.helpButton, Signals.clicked, self.settingHelp) connect(self.defaultsButton, Signals.clicked, self.settingDefaults) + connect(self.resetButton, Signals.clicked, self.settingsReset) connect(self.applyButton, Signals.clicked, self.settingApply) root = self.topLevelWidget() - connect(self, Signals.berylSettingChanged, root.onSettingChanged) + connect(self, Signals.berylSettingChanged, root.onContextChanged) connect(self, Signals.statusMessage, root.showMessage) + connect(self.settingsMain, Signals.somethingChanged, + self.onSomethingChanged) + + def onSomethingChanged(self): + self.applyButton.setEnabled(True) + self.resetButton.setEnabled(True) def showAbout(self, plugin): """ displays the About Plugin page with information from the plugin @@ -125,6 +130,8 @@ class ContentFrame(WidgetStack): extra = '' self.pluginNameLabel.setText('<b>%s%s</b>' % (plugin.ShortDesc, extra)) self.settingsMain.addSettings(plugin, settings) + self.applyButton.setEnabled(False) + self.resetButton.setEnabled(False) self.raiseWidget(self.settingsPageId) def settingHelp(self): @@ -137,18 +144,30 @@ class ContentFrame(WidgetStack): """ + def settingsReset(self): + frame = self.settingsPage + widgets = frame.queryList('SettingWidgetBase') + for widget in widgets: + try: + widget.reset() + except (Exception, ), exc: + print 'reset exception:', exc + self.applyButton.setEnabled(True) + self.resetButton.setEnabled(False) + def settingApply(self): """ not implemented """ frame = self.settingsPage - widgets = frame.queryList('BaseSettingWidget') + widgets = frame.queryList('SettingWidgetBase') exceptions = [] for widget in widgets: try: - widget.setting.set(widget.value()) + value = widget.value() + widget.setting.set(value) + widget.initial = value print '****', widget.setting.ShortDesc, widget.setting.Value - except (Exception, ), exc: exceptions.append((widget.plugin.Name, widget.setting.Name, exc)) if exceptions: @@ -158,6 +177,8 @@ class ContentFrame(WidgetStack): ## KMessageBox.errorList isn't available! KMessageBox.informationList(None, 'Exceptions Saving Settings', exclist) + self.applyButton.setEnabled(False) + self.resetButton.setEnabled(False) self.emit(Signals.statusMessage, ('Saving settings...', )) self.emit(Signals.berylSettingChanged, ()) @@ -174,7 +195,9 @@ class SettingsMainFrame(QFrame): frame = SettingFrame(self, plugin, setting) self.settingFrames.append(frame) layout.addWidget(frame, 0, Qt.AlignTop) - frame.show() + frame.show() + self.connect(frame, Signals.somethingChanged, + self, Signals.somethingChanged) layout.addStretch(100) def clearFrames(self): diff --git a/kberylsettings/lib.py b/kberylsettings/lib.py index 17b14d7..16096a8 100644 --- a/kberylsettings/lib.py +++ b/kberylsettings/lib.py @@ -40,15 +40,22 @@ class Signals: pluginAbout = PYSIGNAL('pluginAbout') showSettings = PYSIGNAL('showSettings') statusMessage = PYSIGNAL('statusMessage') + somethingChanged = PYSIGNAL('somethingChanged') clicked = SIGNAL('clicked()') + changed = SIGNAL('changed()') itemClicked = SIGNAL('clicked(QListViewItem *)') itemSelected = SIGNAL('selectionChanged(QListViewItem *)') okClicked = SIGNAL('okClicked()') activated = SIGNAL('activated()') + activatedIndex = SIGNAL('activated(int)') textChanged = SIGNAL('textChanged(const QString&)') quitSelected = SIGNAL("quitSelected()") actionStatusText = SIGNAL('actionStatusText(const QString &)') clearStatusText = SIGNAL('clearStatusText()') + toggled = SIGNAL('toggled(bool)') + intValueChanged = SIGNAL('valueChanged(int)') + doubleValueChanged = SIGNAL('valueChanged(double)') + colorChanged = SIGNAL('changed(const QColor &)') contextMenuRequest = \ SIGNAL('contextMenuRequested(QListViewItem*,const QPoint&,int)') diff --git a/kberylsettings/main.py b/kberylsettings/main.py index 118c001..10c2752 100644 --- a/kberylsettings/main.py +++ b/kberylsettings/main.py @@ -19,7 +19,7 @@ from kberylsettings.pluginframe import PluginFrame from kberylsettings.widget import Frame, Popup, SmallPushButton, Splitter -class KBerylSetttings(KMainWindow): +class KBerylSettings(KMainWindow): """ The main window. """ @@ -66,7 +66,7 @@ class KBerylSetttings(KMainWindow): menu.insertItem(i18n('&File'), self.fileMenu()) menu.insertItem(i18n('&View'), self.viewMenu()) menu.insertItem(i18n('&Settings'), self.settingsMenu()) - menu.insertItem(i18n('&Help'), self.helpMenu()) + menu.insertItem(i18n('&Help'), self.helpMenu()) def buildSystray(self): """ builds the system tray icon for this instance @@ -75,10 +75,16 @@ class KBerylSetttings(KMainWindow): """ self.quitFlag = False self.sysTray = KSystemTray(self) - path = App.basedir + '/pixmaps/kberylsettings.svg' - self.sysTray.setPixmap(icon(path, size=KIcon.SizeSmallMedium)) - self.sysTray.show() - + pixmap = icon(self.iconFile(), size=KIcon.SizeSmallMedium) + self.sysTray.setPixmap(pixmap) + pop = self.sysTray.contextMenu() + pop.changeTitle(pop.idAt(0), pixmap, + KApplication.kApplication().caption()) + self.sysTray.show() + + def iconFile(self): + return App.basedir + '/pixmaps/kberylsettings.svg' + def buildConnections(self): """ builds the connections for this instance @@ -110,8 +116,8 @@ class KBerylSetttings(KMainWindow): connect = self.connect connect(context, Signals.statusMessage, self.showMessage) KWin.setIcons(self.winId(), - icon('configure', size=KIcon.SizeLarge), - icon('configure', size=KIcon.SizeSmall)) + icon(self.iconFile(), size=KIcon.SizeLarge), + icon(self.iconFile(), size=KIcon.SizeSmall)) config = self.config('mainwindow') self.restoreWindowSize(config) self.mainSplitter.setSizes([self.width()*0.35, self.width()*0.65]) @@ -238,15 +244,6 @@ class KBerylSetttings(KMainWindow): @return None """ self.context.write() - self.context.reload() - - def onSettingChanged(self): - """ writes the beryl context - - @return None - """ - self.context.write() - self.context.reload() def onIconSize(self, value): """ changes the View Icon Size menu @@ -345,15 +342,14 @@ def main(): """ runs the KBerylSettings window with a KApplication @return None -p """ + """ aboutdata = about() KCmdLineArgs.init(argv, aboutdata) app = KApplication() - obj = KBerylSetttings() + obj = KBerylSettings() obj.show() app.exec_loop() - - + if __name__ == '__main__': main() diff --git a/kberylsettings/settingframe.py b/kberylsettings/settingframe.py index c84ae75..c888f4c 100644 --- a/kberylsettings/settingframe.py +++ b/kberylsettings/settingframe.py @@ -6,8 +6,8 @@ berylsettings.Setting instances. """ from qt import Qt, QFrame, QHBoxLayout, QSizePolicy, QToolTip -from kberylsettings.lib import App, iconSet -from kberylsettings.settingwidget import settingWidgetBuilder +from kberylsettings.lib import App, Signals, iconSet +from kberylsettings.settingwidget import settingWidget from kberylsettings.widget import SmallPushButton @@ -24,10 +24,18 @@ class SettingFrame(QFrame): QSizePolicy.Minimum)) self.infoButton = SmallPushButton(iconSet('help'), '', self) self.resetButton = SmallPushButton(iconSet('reload'), '', self) - self.settingWidget = settingWidgetBuilder(self, plugin, setting) + self.settingWidget = settingWidget(self, plugin, setting) + + if isinstance(self.settingWidget.layout(), QHBoxLayout): + align = Qt.AlignLeft | Qt.AlignVCenter + else: + align = Qt.AlignLeft | Qt.AlignTop + tooltip = QToolTip.add(self.infoButton, setting.LongDesc or '') - layout.addWidget(self.infoButton, 0, Qt.AlignLeft|Qt.AlignVCenter) - layout.addWidget(self.resetButton, 0, Qt.AlignLeft|Qt.AlignVCenter) + layout.addWidget(self.infoButton, 0, align) + layout.addWidget(self.resetButton, 0, align) layout.addWidget(self.settingWidget, 10) + self.connect(self.settingWidget, Signals.somethingChanged, + self, Signals.somethingChanged) if App.debug: self.setFrameStyle(QFrame.Box|QFrame.Plain) diff --git a/kberylsettings/settingwidget.py b/kberylsettings/settingwidget.py index 975775f..b954ea3 100644 --- a/kberylsettings/settingwidget.py +++ b/kberylsettings/settingwidget.py @@ -8,60 +8,100 @@ from re import match from kdecore import KShortcut, KKey, i18n from kdeui import KIntNumInput, KDoubleNumInput, KComboBox, KLineEdit, \ - KKeyButton, KColorButton + KKeyButton, KColorButton, KEditListBox from kfile import KURLRequester, KURLComboBox, KURLComboRequester from qt import QCheckBox, QFrame, QLabel, QObject, QWidget, QHBoxLayout, \ - QVBoxLayout, QGridLayout, QColor, qRgba + QVBoxLayout, QGridLayout, QColor, qRgba, Qt, QGroupBox from sip import wrappertype +from kberylsettings.lib import Signals -## -# grown with BaseSettingWidget subclass definitions by the metaclass -# below. -settingWidgetTypes = [] +def settingWidget(parent, plugin, setting): + """ client interface to this module. -class MetaSettingWidget(wrappertype): - """ Small metaclass to gather subclasses of BaseSettingWidget as - they're created. Also turns any 'inspect' attribute into a - classmethod. Lazy * 2. + @param parent parent of setting widget + @param plugin berylsettings Plugin instance + @param setting berylsettings Setting instance + @return new widget suitable for display and edit of setting """ + for typ in SettingWidgetDetector.types: + if typ.inspect(plugin, setting): + return typ(parent, plugin, setting) + + +class SettingWidgetDetector(wrappertype): + """ Small metaclass to gather subclasses of SettingWidgetBase as + they're created. + """ + types = [] + def __init__(cls, name, bases, ns): - super(MetaSettingWidget, cls).__init__(name, bases, ns) - if name != 'BaseSettingWidget' and cls not in settingWidgetTypes: - settingWidgetTypes.append(cls) - try: - setattr(cls, 'inspect', classmethod(ns['inspect'])) - except (KeyError, ): - pass + super(SettingWidgetDetector, cls).__init__(name, bases, ns) + types = SettingWidgetDetector.types + if name != 'SettingWidgetBase' and cls not in types: + types.append(cls) -class BaseSettingWidget(QWidget): +class SettingWidgetBase(QWidget): """ Base class for setting widgets. + Subclasses must define a 'build' method to construct their + widgets. This method must return a tuple of: + + (primary widget, widget change signal, value method, reset method) + + The last two items may be None. + + Additionally, subclasses must define (or set at runtime) methods + named 'value' and 'reset'. The 'value' method will be called to + retrieve the new value for the setting, and the 'reset' method + will be called to reset the widget to its initial value. + Setting Widget classes inherit this class to participate in automatic discovery. They also recieve a default implementation for 'inspect', which is quite handy. """ - ## - # specifies the metaclass for this class and it's derived classes. - __metaclass__ = MetaSettingWidget + __metaclass__ = SettingWidgetDetector def __init__(self, parent, plugin, setting): QWidget.__init__(self, parent) self.plugin = plugin self.setting = setting + try: + self.initial = setting.Value + except (IndexError, ): + self.initial = '' + primaryWidget, changeSignal, self.value, self.reset = \ + self.build(parent, plugin, setting) + if self.reset: + self.reset() + if changeSignal: + self.connect(primaryWidget, changeSignal, + self, Signals.somethingChanged) + + def commonSetup(self, setting, stretch=1, layoutType=QVBoxLayout): + """ create a layout object and a label for the setting + @param setting berylsetting Setting instance + @return QLayout instance with QLabel added + """ + layout = layoutType(self) + label = self.label = QLabel(setting.label, self) + layout.addWidget(label, stretch) + return layout + ## # subclasses can redefine this attribute to make use of the - # default inspect method. + # default inspect method below. inspectTypes = () def inspect(cls, plugin, setting): """ determines if this class can be used to display plugin setting - The default implementation here checks for inclusion of the - setting.Type in the inspectTypes sequence. + The default implementation checks for inclusion of the + setting.Type in the inspectTypes sequence. Subclasses can + override inspectTypes, or override this method completely. @param cls class object @param plugin berylsettings Plugin instance @@ -70,33 +110,77 @@ class BaseSettingWidget(QWidget): specified plugin and setting, false value otherwise. """ return setting.Type in cls.inspectTypes + inspect = classmethod(inspect) - ## - # subclasses can change this to adjust the behavior of the - # commonSetup method below. - layoutType = QVBoxLayout +## MARKER + + def checkBoxValue(self): + return self.checkBox.isChecked() - def commonSetup(self, setting, stretch=0): - """ create a layout object and a label for the setting + def checkBoxReset(self): + self.checkBox.setChecked(self.initial) - @param setting berylsetting Setting instance - @return QLayout instance with QLabel added - """ - layout = self.layoutType(self) - label = self.label = QLabel(setting.label, self) - layout.addWidget(label, stretch) - return layout - + def comboText(self): + return str(self.combo.currentText()) + + def comboTextReset(self): + combo = self.combo + combo.clear() + for r in self.setting.Restrictions: + combo.insertItem(r) + combo.setCurrentItem(self.initial) + + def comboIndex(self): + return self.combo.currentItem() + + def comboIndexReset(self): + self.combo.setCurrentItem(self.setting.Value) + + def inputValue(self): + return self.input.value() + + def inputReset(self): + self.input.setValue(self.initial) + + def lineText(self): + return str(self.line.text()) + + def lineTextReset(self): + self.line.setText(self.initial) + + def checkBoxesValue(self): + boxes = self.queryList('QCheckBox') + return [cbText(box) for box in boxes if box.isChecked()] + + def checkBoxesReset(self): + initial = self.initial + for cb in self.queryList('QCheckBox'): + cb.setChecked(cbText(cb) in initial) -class NamedSettingWidget(BaseSettingWidget): + def listEditorValue(self): + box = self.listEditor.listBox() + return [str(box.text(i)) for i in range(box.count())] + + def listEditorReset(self): + self.listEditor.clear() + for value in self.initial: + self.listEditor.insertItem(value) + + def requesterValue(self): + return str(self.requester.url()) + + def requesterReset(self): + self.requester.clear() + self.requester.setURL(self.initial) + + +class NamedSettingWidget(SettingWidgetBase): """ Setting widget for specific named settings. Method names are in the form 'pluginname_settingname'. """ - def __init__(self, parent, plugin, setting): - BaseSettingWidget.__init__(self, parent, plugin, setting) - meth = self.inspect(plugin, setting) - meth(self, parent, plugin, setting) + def build(self, parent, plugin, setting): + return self.inspect(plugin, setting)(self, parent, plugin, setting) def inspect(cls, plugin, setting): """ matches plugin and setting names to local method names @@ -108,9 +192,9 @@ class NamedSettingWidget(BaseSettingWidget): """ name = '%s_%s' % (plugin.Name, setting.Name, ) return getattr(cls, name, None) - - iconCorners = list(enumerate(('BottomRight', 'BottomLeft', 'TopRight', - 'TopLeft', 'Center'))) + inspect = classmethod(inspect) + + iconCorners = 'BottomRight', 'BottomLeft', 'TopRight', 'TopLeft', 'Center' def switcher_icon_corner(self, parent, plugin, setting): """ creates a combo box for the Switcher Icon Corner setting @@ -120,18 +204,17 @@ class NamedSettingWidget(BaseSettingWidget): @param setting better be a icon_corner setting instance @return None """ - layout = self.commonSetup(setting) - self.view = view = KComboBox(self) - layout.addWidget(view) - for index, text in self.iconCorners: - view.insertItem(text, index) - self.value = self.viewValue - - def viewValue(self): - return self.view.currentItem() + self.combo = KComboBox(self) + for index, text in enumerate(self.iconCorners): + self.combo.insertItem(text, index) + #self.combo.setCurrentItem(setting.Value) + layout = self.commonSetup(setting) + layout.addWidget(self.combo, 2) + return (self.combo, Signals.activatedIndex, + self.comboIndex, self.comboIndexReset) -class MatchNamedSettingWidget(BaseSettingWidget): +class MatchNamedSettingWidget(SettingWidgetBase): """ Setting widget for settings with matching names. """ @@ -141,13 +224,12 @@ class MatchNamedSettingWidget(BaseSettingWidget): (('.*', 'skydome_image'), 'fileSelector'), (('.*', 'default_icon'), 'fileSelector'), (('.*', '(.*_)?window_types'), 'wmTypeSelector'), - (('.*', 'images_(.*)'), 'filesSelector'), + (('.*', 'images_top|images_bottom'), 'filesSelector'), ) - def __init__(self, parent, plugin, setting): - BaseSettingWidget.__init__(self, parent, plugin, setting) + def build(self, parent, plugin, setting): meth = self.inspect(plugin, setting) - meth(self, parent, plugin, setting) + return meth(self, parent, plugin, setting) def inspect(cls, plugin, setting): """ matches plugin and setting names to local method names @@ -160,80 +242,69 @@ class MatchNamedSettingWidget(BaseSettingWidget): for (plugpat, setpat), callname in cls.lookups: if match(plugpat, plugin.Name) and match(setpat, setting.Name): return getattr(cls, callname, None) - + inspect = classmethod(inspect) + def fileSelector(self, parent, plugin, setting): - layout = self.commonSetup(setting) - self.view = KURLRequester(setting.Value, self) - layout.addWidget(self.view) - self.value = self.urlValue - + self.requester = KURLRequester(self) + layout = self.commonSetup(setting) + layout.addWidget(self.requester, 2) + return (self.requester, Signals.textChanged, + self.requesterValue, self.requesterReset) + def filesSelector(self, parent, plugin, setting): - layout = self.commonSetup(setting) - #self.files = KURLComboBox(KURLComboBox.Files, self) - self.files = KURLComboRequester(self) - - layout.addWidget(self.files) - + self.requester = urlreq = KURLRequester(self) + editor = KEditListBox.CustomEditor(urlreq, urlreq.lineEdit()) + self.listEditor = KEditListBox(setting.ShortDesc, editor, self) + layout = QVBoxLayout(self) + layout.addWidget(self.listEditor, 2) + return (self.listEditor, Signals.changed, + self.listEditorValue, self.listEditorReset) + def wmTypeSelector(self, parent, plugin, setting): types = setting.Restrictions current = setting.Value - grid = QGridLayout(len(types)/3, 3) + group = LocalGroupBox(3, Qt.Horizontal, setting.ShortDesc, self) items = range(len(types)) - for row, indexes in enumerate([items[i:i+3] for i in items[::3]]): - for col, index in enumerate(indexes): - typ = types[index] - cb = QCheckBox(typ, self) - cb.setChecked(typ in current) - grid.addWidget(cb, row, col) - layout = self.commonSetup(setting) - layout.addLayout(grid) - self.value = self.checkboxValues - - def urlValue(self): - return str(self.view.url()) - - def checkboxValues(self): - def fix(o): - return str(o.text()).replace('&', '') - return [fix(cb) for cb in self.queryList('QCheckBox') if cb.isChecked()] - - -class ColorSettingWidget(BaseSettingWidget): - """ Setting widget for colors. - - """ - inspectTypes = ('Color', ) - layoutType = QHBoxLayout - - def __init__(self, parent, plugin, setting): - BaseSettingWidget.__init__(self, parent, plugin, setting) - layout = self.commonSetup(setting, 100) - self.color = QColor(qRgba(*[a/256 for a in setting.Value])) - self.colorButton = KColorButton(self) - self.colorButton.setColor(self.color) - layout.addWidget(self.colorButton) + for typ in types: + cb = QCheckBox(typ, group) + self.connect(cb, Signals.clicked, self, Signals.somethingChanged) + layout = QVBoxLayout(self) + layout.addWidget(group, 2) + return (self, None, self.checkBoxesValue, self.checkBoxesReset) -class BoolSettingWidget(BaseSettingWidget): +class BoolSettingWidget(SettingWidgetBase): """ Setting widget for true/false values. """ - inspectTypes = ('Bool', ) + inspectTypes = 'Bool' - def __init__(self, parent, plugin, setting): - BaseSettingWidget.__init__(self, parent, plugin, setting) + def build(self, parent, plugin, setting): layout = QHBoxLayout(self) - self.cb = QCheckBox(self) - self.cb.setChecked(setting.Value) - layout.addWidget(self.cb) + self.checkBox = QCheckBox(self) + layout.addWidget(self.checkBox) label = QLabel(setting.ShortDesc, self) layout.addWidget(label, 100) + return (self.checkBox, Signals.toggled, + self.checkBoxValue, self.checkBoxReset) - def value(self): - return self.cb.isChecked() +class ColorSettingWidget(SettingWidgetBase): + """ Setting widget for colors. -class NumericSettingWidget(BaseSettingWidget): + """ + inspectTypes = 'Color' + + def build(self, parent, plugin, setting): + self.color = QColor(qRgba(*[a/256 for a in setting.Value])) + self.colorButton = KColorButton(self) + self.colorButton.setColor(self.color) + layout = self.commonSetup(setting, 100, QHBoxLayout) + layout.addWidget(self.colorButton) + return (self.colorButton, Signals.colorChanged, None, None) + + +class NumericSettingWidget(SettingWidgetBase): """ Setting widget for numeric ranges. Integers and floats supported. """ @@ -241,76 +312,109 @@ class NumericSettingWidget(BaseSettingWidget): 'Int' : KIntNumInput, 'Float' : KDoubleNumInput, } + + changeSignals = { + 'Int' : Signals.intValueChanged, + 'Float' : Signals.doubleValueChanged, + } - def __init__(self, parent, plugin, setting): - BaseSettingWidget.__init__(self, parent, plugin, setting) + def build(self, parent, plugin, setting): + self.input = self.inspectTypes[setting.Type](self) try: minvalue, maxvalue, stepvalue = setting.Restrictions except (ValueError, ): minvalue, maxvalue = setting.Restrictions stepvalue = 1 - current = setting.Value - self.input = self.inspectTypes[setting.Type](current, self) self.input.setRange(minvalue, maxvalue, stepvalue, True) - layout = self.commonSetup(setting) - layout.addWidget(self.input) - - def value(self): - return self.input.value() + layout = self.commonSetup(setting, layoutType=QHBoxLayout) + layout.addWidget(self.input, 2) + return (self.input, self.changeSignals[setting.Type], + self.inputValue, self.inputReset) -class StringSettingWidget(BaseSettingWidget): +class StringSettingWidget(SettingWidgetBase): """ Setting widget for strings. """ - inspectTypes = ('String', ) + inspectTypes = 'String' - def __init__(self, parent, plugin, setting): - BaseSettingWidget.__init__(self, parent, plugin, setting) - layout = self.commonSetup(setting) - try: - s = setting.Value - except (IndexError, ): # some berylsettings bug??? - s = '' + def build(self, parent, plugin, setting): if setting.Restrictions: - other = self.combo = KComboBox(False, self) - self.value = self.comboValue - for r in setting.Restrictions: - other.insertItem(r) - if s == r: - other.setCurrentItem(other.count()-1) + self.combo = KComboBox(self) + res = (self.combo, Signals.activatedIndex, + self.comboText, self.comboTextReset) else: - other = self.line = KLineEdit(s, self) - self.value = self.lineValue - - layout.addWidget(other) + self.line = KLineEdit(self) + res = (self.line, Signals.textChanged, + self.lineText, self.lineTextReset) + layout = self.commonSetup(setting, layoutType=QHBoxLayout) + layout.addWidget(res[0], 2) + return res - def lineValue(self): - return str(self.line.text()) - def comboValue(self): - return str(self.combo.currentText()) - +class StringListSettingWidget(SettingWidgetBase): + """ Setting widget for lists of strings. + + """ + inspectTypes = 'List of String' -class BindingSettingWidget(BaseSettingWidget): + def build(self, parent, plugin, setting): + self.listEditor = KEditListBox(setting.ShortDesc, self) + layout = QVBoxLayout(self) + layout.addWidget(self.listEditor, 2) + return (self.listEditor, Signals.changed, + self.listEditorValue, self.listEditorReset) + + +## binding restrictions, e.g.: [1, 1, 0, 1] +## [cansetkey, cansetbutton, cansetedgemask, cansetbell] +## +## binding values: [keystr, buttonstr, bell, edgelist] +""" +print p.Settings[0] +initiate setting + +in [77]: s = p.Settings[0] + +in [78]: s +out[78]: <berylsettings.Setting object at 0xb54d962c> + +in [79]: s.Value +out[79]: ('<Alt>F7', '<Alt>Button1', False, []) + +in [80]: s.Type +out[80]: 'Binding' +""" + +class BindingSettingWidget(SettingWidgetBase): """ Setting widget for keyboard/mouse/edge bindings. """ - inspectTypes = ('Binding', ) - layoutType = QHBoxLayout + inspectTypes = 'Binding' + + keyMods = ('Shift', 'Control', 'Alt', 'Super', 'Hyper', + 'Meta', 'Mode', 'Mod1', 'Mod2', 'Mod3', 'Mod4', 'Mod5') - def __init__(self, parent, plugin, setting): - BaseSettingWidget.__init__(self, parent, plugin, setting) - layout = self.commonSetup(setting) + def build(self, parent, plugin, setting): + layout = self.commonSetup(setting, layoutType=QHBoxLayout) self.line = KLineEdit('%s || %s' % (setting.Value, setting.Restrictions, ), self) self.keybutton = KKeyButton(self) self.keybutton.setShortcut(KShortcut(toKKey(setting.Value[0]))) self.keybutton.setText(setting.Value[0]) - layout.addWidget(self.line) - layout.addWidget(self.keybutton) + layout.addWidget(self.line, 3) + layout.addWidget(self.keybutton, 2) + return (self.keybutton, Signals.clicked, None, None) + + catsetkey, cansetbutton, cansetedge, cansetbell = setting.Restrictions + keystr, buttonstr, bell, edgeseq = setting.Value + group = LocalGroupBox(3, Qt.Horizontal, setting.ShortDesc, self) + if cansetkey: + pass + + -class UnknownSettingWidget(BaseSettingWidget): +class UnknownSettingWidget(SettingWidgetBase): """ Setting widget for unknown values. Because this class is defined last, it's caught by the metaclass @@ -318,13 +422,12 @@ class UnknownSettingWidget(BaseSettingWidget): Whenever a setting object cannot be otherwise matched to a SettingWidget, this class will be called. """ - layoutType = QHBoxLayout - def __init__(self, parent, plugin, setting): - BaseSettingWidget.__init__(self, parent, plugin, setting) - layout = self.commonSetup(setting) + def build(self, parent, plugin, setting): + layout = self.commonSetup(setting, layoutType=QHBoxLayout) text = '%s (Unknown Type %s)' % (setting.ShortDesc, setting.Type, ) self.label.setText(text) + return (self.label, Signals.clicked, None, None) def inspect(cls, plugin, setting): """ matches plugin and setting names to local method names @@ -335,22 +438,7 @@ class UnknownSettingWidget(BaseSettingWidget): @return True """ return True - - def value(self): - raise RuntimeError('Cannot get value of unknown setting.') - - -def settingWidgetBuilder(parent, plugin, setting): - """ client interface to this module. - - @param parent parent of setting widget - @param plugin berylsettings Plugin instance - @param setting berylsettings Setting instance - @return new widget suitable for display and edit of setting - """ - for typ in settingWidgetTypes: - if typ.inspect(plugin, setting): - return typ(parent, plugin, setting) + inspect = classmethod(inspect) def toKKey(v): @@ -363,3 +451,15 @@ def toKKey(v): v = v.replace('<', '') v = v.replace('>', '+') return KKey(v) + + +def cbText(o): + return str(o.text()).replace('&', '') + + +class LocalGroupBox(QGroupBox): + def __init__(self, strips, orient, text, parent, margin=0, spacing=0): + QGroupBox.__init__(self, strips, orient, text, parent) + self.setFlat(True) + self.setInsideMargin(margin) + self.setInsideSpacing(spacing) |