summaryrefslogtreecommitdiff
path: root/kberylsettings
diff options
context:
space:
mode:
authornatural <natural>2006-12-30 02:28:44 +0000
committernatural <natural>2006-12-30 02:28:44 +0000
commitb3bd6e4163a79f03edf2c2c6935b530d2af21e14 (patch)
tree9300073e0adaf4ab4c42ec3f0436d49527163d81 /kberylsettings
parentd5c0b65e73186b30cdf2ab7e5ebf72cddc852a2a (diff)
downloadkberylsettings-b3bd6e4163a79f03edf2c2c6935b530d2af21e14.tar.gz
kberylsettings-b3bd6e4163a79f03edf2c2c6935b530d2af21e14.tar.bz2
Added numbered profile selections.
Added profile import (still not working). Completed all docstrings.
Diffstat (limited to 'kberylsettings')
-rw-r--r--kberylsettings/beryl.py7
-rw-r--r--kberylsettings/contentframe.py6
-rw-r--r--kberylsettings/main.py34
-rw-r--r--kberylsettings/settingwidget.py217
4 files changed, 226 insertions, 38 deletions
diff --git a/kberylsettings/beryl.py b/kberylsettings/beryl.py
index ff21e99..870f77d 100644
--- a/kberylsettings/beryl.py
+++ b/kberylsettings/beryl.py
@@ -12,7 +12,6 @@ from kberylsettings.lib import App, Signals, icon
from qt import QImage, QPixmap, QObject
-
class Context(QObject):
""" Context -> wraps berylsetting.Context instances with extra
methods and properties.
@@ -28,6 +27,12 @@ class Context(QObject):
context.Read()
self.context = context
+ def __getattr__(self, value):
+ """ x.__getattr__('name') <==> x.name
+
+ """
+ return getattr(self.context, value)
+
def __repr__(self):
""" x.__repr__() <==> repr(x)
diff --git a/kberylsettings/contentframe.py b/kberylsettings/contentframe.py
index e9b096a..edab4f9 100644
--- a/kberylsettings/contentframe.py
+++ b/kberylsettings/contentframe.py
@@ -240,6 +240,12 @@ class SettingPage:
self.emit(Signals.berylSettingChanged, ())
def settingExcDialog(self, exceptions, caption):
+ """ show an error dialog
+
+ @param exceptions list of three-tuples
+ @param caption dialog caption
+ @return None
+ """
if not exceptions:
return
excstrs = QStringList()
diff --git a/kberylsettings/main.py b/kberylsettings/main.py
index ee6f16b..da7a905 100644
--- a/kberylsettings/main.py
+++ b/kberylsettings/main.py
@@ -175,15 +175,23 @@ class KBerylSettings(KMainWindow):
""" creates a new Named Profiles menu
"""
+ try:
+ profileMap = self.profileMap
+ except (AttributeError, ):
+ profileMap = self.profileMap = {}
+
pop = Popup(self)
names = [n for n in listdir(expanduser('~/.beryl'))
if n.endswith('.Profile')]
names.sort()
for name in names:
- pop.insertItem(name)
+ popid = pop.insertItem(name)
+ index = hash(name)
+ profileMap[index] = name
+ pop.setItemParameter(popid, index)
+ pop.connectItem(popid, self.onProfileSelect)
return pop
-
def viewMenu(self):
""" creates a new View menu
@@ -299,6 +307,15 @@ class KBerylSettings(KMainWindow):
context.active = active
self.emit(Signals.berylContextChanged, (context, ))
+ def onProfileSelect(self, itemId):
+ """ sets current profile
+
+ @param itemId profile popup menu item id
+ @return None
+ """
+ self.context.Profile = self.profileMap[itemId]
+ self.emit(Signals.berylContextChanged, (self.context, ))
+
def onQuitSelected(self):
""" sets quit flag and calls application to quit
@@ -339,23 +356,30 @@ class KBerylSettings(KMainWindow):
@return None
"""
- filename = KFileDialog.getOpenFileName(self.startDir, None, self,
+ filename = KFileDialog.getOpenFileName(self.startDir, '', None,
'Select Profile to Import')
if filename:
- print 'importing file...', filename
+ self.context.Import(filename, True) # overwrite
+ self.emit(Signals.berylContextChanged, (self.context, ))
+ self.showMessage('Settings imported.')
def onExport(self):
""" shows dialog to select filename for profile export
@return None
"""
- filename = KFileDialog.getSaveFileName(self.startDir, None, self,
+ filename = KFileDialog.getSaveFileName(self.startDir, '', None,
'Select File to Export Profile')
if filename:
print 'exporting file...', filename
def showMessage(self, text):
+ """ show a message in the status bar
+
+ @param text value to show
+ @return None
+ """
self.statusBar().message(text, 3000)
diff --git a/kberylsettings/settingwidget.py b/kberylsettings/settingwidget.py
index 1ef4487..570bd9c 100644
--- a/kberylsettings/settingwidget.py
+++ b/kberylsettings/settingwidget.py
@@ -120,6 +120,10 @@ class SettingWidget(QFrame):
query = classmethod(query)
def setFromValue(self):
+ """ set the setting value to the value of this widget
+
+ @return None
+ """
value = self.value()
self.setting.set(value)
self.initial = value
@@ -137,19 +141,41 @@ class SettingWidget(QFrame):
self.setting.set(current)
self.reset()
self.initial = current
-
-## MARKER
+
+ def cbText(self, widget):
+ """ gets the text of a checkbox widget (minus amperstands)
+
+ @return widget text
+ """
+ return str(widget.text()).replace('&', '')
+
+ ##
+ # Subclasses specify their value and reset methods when they build
+ # their widgets. We get a bit of reuse and a bit more clarity by
+ # grouping these methods here.
def checkBoxValue(self):
+ """ checked state of our checkbox widget
+
+ """
return self.checkBox.isChecked()
def checkBoxReset(self):
+ """ reset checked state of our checkbox widget
+
+ """
self.checkBox.setChecked(self.initial)
def comboText(self):
+ """ current text of our combo widget
+
+ """
return str(self.combo.currentText())
def comboTextReset(self):
+ """ reset our combo widget text
+
+ """
combo = self.combo
combo.clear()
for r in self.setting.Restrictions:
@@ -157,48 +183,84 @@ class SettingWidget(QFrame):
combo.setCurrentItem(self.initial)
def comboIndex(self):
+ """ index of our combo widget current item
+
+ """
return self.combo.currentItem()
def comboIndexReset(self):
- ## this method does not clear the combo,
- ## it only sets the current item.
+ """ sets our current combo widget item by index
+
+ This method does not clear the combo, it only sets the current
+ item.
+ """
self.combo.setCurrentItem(self.setting.Value)
def numInputValue(self):
+ """ current value of our numeric input widget
+
+ """
return self.numInput.value()
def numInputReset(self):
+ """ reset value of our numeric input widget
+
+ """
self.numInput.setValue(self.initial)
def lineText(self):
+ """ current value of our line edit widget
+
+ """
return str(self.line.text())
def lineTextReset(self):
+ """ resets value of our line edit widget
+
+ """
self.line.setText(self.initial)
def checkBoxesValue(self):
+ """ list of strings for all checked checkboxs
+
+ """
boxes = self.queryList('QCheckBox')
return [self.cbText(box) for box in boxes if box.isChecked()]
def checkBoxesReset(self):
+ """ checks checkboxes for each string in our value
+
+ """
initial = self.initial
for cb in self.queryList('QCheckBox'):
cb.setChecked(self.cbText(cb) in initial)
def listEditorValue(self):
+ """ list of strings in our listEditor widget
+
+ """
box = self.listEditor.listBox()
return [str(box.text(i)) for i in range(box.count())]
def listEditorReset(self):
+ """ clears and sets our listEditor widget
+
+ """
self.listEditor.clear()
for value in self.initial:
self.listEditor.insertItem(value)
def radioGroupValue(self):
+ """ index of selected radio item
+
+ """
radioId = self.radioGroup.selectedId()
return self.setting.Restrictions[radioId]
def radioGroupReset(self):
+ """ sets or radio item
+
+ """
group = self.radioGroup
initial = self.initial
restrictions = self.setting.Restrictions
@@ -210,14 +272,22 @@ class SettingWidget(QFrame):
group.setButton(restrictions.index(value))
def requesterValue(self):
+ """ current value of our requester widget
+
+ """
return str(self.requester.url())
def requesterReset(self):
+ """ sets url in our requester widget
+
+ """
self.requester.clear()
self.requester.setURL(self.initial)
- def cbText(self, widget):
- return str(widget.text()).replace('&', '')
+ def noOp(self):
+ """ does nothing
+
+ """
class SpecificNames(SettingWidget):
@@ -289,11 +359,6 @@ class SpecificNames(SettingWidget):
self.setFromValue = self.setDefault = self.noOp
return (None, None, self.noOp, self.noOp)
- def noOp(self):
- """ does nothing
-
- """
-
class MatchNames(SettingWidget):
""" Setting widget for settings with matching names.
@@ -338,6 +403,13 @@ class MatchNames(SettingWidget):
query = classmethod(query)
def fileSelector(self, parent, plugin, setting):
+ """ create a file selector widget
+
+ @param parent parent object of this widget
+ @param plugin berylsettings Plugin instance
+ @param setting berylsettings Setting instance
+ @return four-item tuple of (widget, signal, valuemethod, resetmethod)
+ """
self.requester = KURLRequester(self)
layout = self.labeledLayout(setting)
layout.addWidget(self.requester, 2)
@@ -345,6 +417,13 @@ class MatchNames(SettingWidget):
self.requesterValue, self.requesterReset)
def filesSelector(self, parent, plugin, setting):
+ """ create a multiple file selector widget
+
+ @param parent parent object of this widget
+ @param plugin berylsettings Plugin instance
+ @param setting berylsettings Setting instance
+ @return four-item tuple of (widget, signal, valuemethod, resetmethod)
+ """
self.requester = urlreq = KURLRequester(self)
editor = KEditListBox.CustomEditor(urlreq, urlreq.lineEdit())
self.listEditor = KEditListBox(setting.ShortDesc, editor, self)
@@ -354,6 +433,13 @@ class MatchNames(SettingWidget):
self.listEditorValue, self.listEditorReset)
def wmTypeSelector(self, parent, plugin, setting):
+ """ create a widget for selecting window types
+
+ @param parent parent object of this widget
+ @param plugin berylsettings Plugin instance
+ @param setting berylsettings Setting instance
+ @return four-item tuple of (widget, signal, valuemethod, resetmethod)
+ """
self.group = GroupBox(3, Qt.Horizontal, setting.ShortDesc, self)
for text in setting.Restrictions:
checkBox = QCheckBox(text, self.group)
@@ -431,14 +517,27 @@ class Color(SettingWidget):
return (colorButton, None, self.colorValue, self.colorReset)
def updateColor(self, color):
+ """ slot for receiving new color
+
+ @param color QColor instance
+ @return None
+ """
self.color = color
def colorValue(self):
+ """ color value of this widget
+
+ @return four-item tuple of (r, g, b, a)
+ """
c = self.color
rgba = (c.red(), c.green(), c.blue(), self.opacityInput.value())
return tuple([v*256 for v in rgba])
def colorReset(self):
+ """ resets color to initial value
+
+ @return None
+ """
self.color = color = QColor()
color.setRgb(*[a/256 for a in self.setting.Value[0:3]])
self.colorButton.setColor(color)
@@ -482,11 +581,22 @@ class Number(SettingWidget):
class FewChoices(SettingWidget):
- queryTypes = ('String', )
+ """ Radio group widget for choosing among just a few items.
+ """
+ queryTypes = ('String', )
+ maxRestrictions = 5
+
def query(cls, plugin, setting):
+ """ matches string types with fewer than max restrictions
+
+ @param cls class object
+ @param plugin berylsettings Plugin instance
+ @param setting berylsettings Setting instance
+ @return unbound method if found on class, None otherwise
+ """
if setting.Type in cls.queryTypes and setting.Restrictions:
- return (len(setting.Restrictions) < 5) and cls
+ return (len(setting.Restrictions) < cls.maxRestrictions) and cls
query = classmethod(query)
def build(self, parent, plugin, setting):
@@ -546,8 +656,6 @@ class StringList(SettingWidget):
@param setting berylsettings Setting instance
@return four-item tuple of (widget, signal, valuemethod, resetmethod)
"""
- #if plugin.Name == '_' and setting.Name == 'active_plugins':
- # self.setEnabled(False)
self.listEditor = KEditListBox(setting.ShortDesc, self)
layout = QVBoxLayout(self)
layout.addWidget(self.listEditor, 2)
@@ -634,7 +742,7 @@ class Binding(SettingWidget):
return (None, None, self.bindingValue, self.bindingReset)
def bindingValue(self):
- """
+ """ gets value of this widet
"""
val = ['Disabled', 'Disabled', False, []]
@@ -663,7 +771,7 @@ class Binding(SettingWidget):
return tuple(val)
def bindingReset(self):
- """
+ """ resets this widget
"""
value = self.initial
@@ -718,6 +826,12 @@ class Binding(SettingWidget):
reset(key)
def bindingWidget(self, text, which):
+ """ create a key or mouse binding widget
+
+ @param text value for binding type label
+ @param which binding type; see 'idxs' attribute
+ @return object with binding widget attributes
+ """
connect = self.connect
ctl = self.control()
toggled = Signals.toggled
@@ -740,7 +854,7 @@ class Binding(SettingWidget):
ctl.keyButton = keyButton = GrabKeyButton(self)
lineLayout.addWidget(keyButton)
connect(keyLine, Signals.textChanged, self, someChange)
- connect(keyButton, Signals.capturedShortcut, self.grabKey)
+ connect(keyButton, Signals.capturedShortcut, self.onKeyCapture)
connect(keyButton, Signals.capturedShortcut, self, someChange)
connect(enableCheck, toggled, keyLine.setEnabled)
connect(enableCheck, toggled, keyButton.setEnabled)
@@ -755,22 +869,13 @@ class Binding(SettingWidget):
connect(ctl.modifierList, Signals.itemSelected, self, someChange)
connect(enableCheck, toggled, ctl.modifierList.setEnabled)
return ctl
-
- def grabKey(self, key):
- skey = str(key.toString())
- skey = skey.replace('Win', 'Super')
- skey = skey.replace('Ctl', 'Control')
- skey = skey.split('+')
- if len(skey) == 1:
- skey = skey[0]
- else:
- skey = str.join('', ['<%s>' % i for i in skey[:-1]]) + skey[-1]
- init = list(self.initial)
- init[self.idxKey] = skey
- self.initial = tuple(init)
- self.reset()
def edgeBindingWidget(self, text):
+ """ create an edge binding widget
+
+ @param text value for binding type label
+ @return object with binding widget attributes
+ """
connect = self.connect
ctl = self.control()
ctl.typeLabel = QLabel(text, self)
@@ -779,6 +884,11 @@ class Binding(SettingWidget):
return ctl
def bellWidget(self, text):
+ """ create a bell binding widget
+
+ @param text value for binding type label
+ @return object with binding widget attributes
+ """
ctl = self.control()
ctl.bellFrame = QFrame(self)
layout = QHBoxLayout(ctl.bellFrame)
@@ -786,6 +896,25 @@ class Binding(SettingWidget):
layout.addWidget(ctl.bellCheck)
self.connect(ctl.bellCheck, Signals.toggled, self, Signals.someChange)
return ctl
+
+ def onKeyCapture(self, key):
+ """ slot to receive changed key binding
+
+ @param key KKey instance with new key binding
+ @return None
+ """
+ skey = str(key.toString())
+ skey = skey.replace('Win', 'Super')
+ skey = skey.replace('Ctl', 'Control')
+ skey = skey.split('+')
+ if len(skey) == 1:
+ skey = skey[0]
+ else:
+ skey = str.join('', ['<%s>' % i for i in skey[:-1]]) + skey[-1]
+ init = list(self.initial)
+ init[self.idxKey] = skey
+ self.initial = tuple(init)
+ self.reset()
class control(object):
""" add attributes to instances of this handy-and-empty class
@@ -835,6 +964,9 @@ class Unknown(SettingWidget):
class GrabKeyButton(KKeyButton):
+ """ GrabKeyButton -> KKeyButton without extra painting or dialog buttons
+
+ """
def __init__(self, parent):
KKeyButton.__init__(self, parent)
self.setText(i18n('Grab'))
@@ -842,13 +974,34 @@ class GrabKeyButton(KKeyButton):
self.connect(self, Signals.clicked, self.captureShortcut)
def drawButton(self, painter):
+ """ draw the face of this button
+
+ This implementation skips the KKeyButton drawButton method and instead
+ defers painting directly to the QPushButton ancestor class.
+
+ @param painter QPainter instance
+ @return None
+ """
QPushButton.drawButton(self, painter)
def setText(self, text):
+ """ set the button text
+
+ Like the drawButton method, we skip over the KKeyButton
+ implementation so that this button size can be set like other
+ buttons.
+
+ @param text value for button
+ @return None
+ """
QPushButton.setText(self, text)
self.setFixedSize(self.sizeHint().width(), self.sizeHint().height())
def captureShortcut(self):
+ """ shows a simplified KShortcutDialog for shortcut capture
+
+ @return None
+ """
dlg = KShortcutDialog(self.shortcut(), True, self)
dlg.showButton(KShortcutDialog.Details, False)
res = dlg.exec_loop()