summaryrefslogtreecommitdiff
path: root/kberylsettings
diff options
context:
space:
mode:
authornatural <natural>2006-12-29 11:16:52 +0000
committernatural <natural>2006-12-29 11:16:52 +0000
commit83388f8fa04a23e09111d140f508d22667892202 (patch)
treebb3e1e2614da0a275ad19669fa52d4cb1d716df5 /kberylsettings
parente60bfbb3b724d5999d089ed952ae8a43c244e9ae (diff)
downloadkberylsettings-83388f8fa04a23e09111d140f508d22667892202.tar.gz
kberylsettings-83388f8fa04a23e09111d140f508d22667892202.tar.bz2
Added setting type icons, category icons.
More cleanup and docstrings.
Diffstat (limited to 'kberylsettings')
-rw-r--r--kberylsettings/beryl.py245
-rw-r--r--kberylsettings/contentframe.py3
-rw-r--r--kberylsettings/lib.py2
-rw-r--r--kberylsettings/main.py2
-rw-r--r--kberylsettings/pluginframe.py10
-rw-r--r--kberylsettings/settingwidget.py6
6 files changed, 159 insertions, 109 deletions
diff --git a/kberylsettings/beryl.py b/kberylsettings/beryl.py
index d07d89a..ff21e99 100644
--- a/kberylsettings/beryl.py
+++ b/kberylsettings/beryl.py
@@ -6,17 +6,18 @@
import berylsettings
from os.path import abspath, exists
-from re import sub
-from qt import QImage, QPixmap, QObject
from kdecore import KIcon
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.
+ This class inherits QObject so that instances can emit Qt signals.
"""
activePluginsSettingName = 'active_plugins'
@@ -28,17 +29,25 @@ class Context(QObject):
self.context = context
def __repr__(self):
+ """ x.__repr__() <==> repr(x)
+
+ """
args = (self.__module__, self.__class__.__name__, hex(abs(id(self))))
return "<%s.%s instance at %s>" % args
+ __str__ = __repr__
def getCategories(self):
+ """ sorted categories sequence
+
+ @return sorted list of Category instances
+ """
seq = [Category(c) for c in self.context.Categories]
seq.sort()
return seq
categories = property(getCategories)
def getPlugins(self):
- """ sorted plugin sequence
+ """ sorted plugins sequence
@return sequence of Plugin wrapper instances
"""
@@ -108,19 +117,50 @@ class Context(QObject):
class Category:
+ """ Category -> wraps berylsetting.Category instances with extra
+ methods and properties.
+
+ """
+ iconNameMap = {
+ 'wm' : 'kwin',
+ 'effects' : 'style',
+ 'misc' : 'package_toys',
+ 'settings' : 'configure',
+ 'imageformat' : 'icons',
+ 'devel' : 'source',
+ 'desktop' : 'desktop',
+ 'accessibility' : 'access',
+ }
+
def __init__(self, category):
self.category = category
def __cmp__(self, other):
+ """ x.__cmp__(y) <==> cmp(x, y)
+
+ """
return cmp(self.ShortDesc, other.ShortDesc)
def __getattr__(self, value):
+ """ x.__getattr__('name') <==> x.name
+
+ """
return getattr(self.category, value)
- def icon(self, size, loader):
- return loader.loadIcon('unknown', KIcon.NoGroup, size)
+ def icon(self, size):
+ """ icon for this category
+
+ @param size KIcon size
+ @return icon instance
+ """
+ name = self.iconNameMap.get(self.Name, self.Name)
+ return icon(name, KIcon.NoGroup, size)
def plugins(self):
+ """ sequence of plugin instances in this category
+
+ @return sequence of active plugin names
+ """
seq = [Plugin(p) for p in self.category.Plugins]
seq.sort()
return seq
@@ -128,6 +168,10 @@ class Category:
class Plugin:
+ """ Plugin -> wraps berylsetting.Plugin instances with extra
+ methods and properties.
+
+ """
generalName = '_'
iconCache = {}
@@ -135,6 +179,9 @@ class Plugin:
self.plugin = plugin
def __cmp__(self, other):
+ """ x.__cmp__(y) <==> cmp(x, y)
+
+ """
if other is None:
return -1
if not isinstance(other, Plugin):
@@ -146,19 +193,35 @@ class Plugin:
return cmp(self.plugin.ShortDesc, other.plugin.ShortDesc)
def __getattr__(self, value):
+ """ x.__getattr__('name') <==> x.name
+
+ """
return getattr(self.plugin, value)
def __repr__(self):
+ """ x.__repr__() <==> repr(x)
+
+ """
args = (self.__module__, self.__class__.__name__,
self.Name,
hex(abs(id(self))))
return "<%s.%s instance name='%s' at %s>" % args
-
+ __str__ = __repr__
+
def isGeneral(self):
+ """ true if this plugin is a general plugin
+
+ """
return self.plugin.Name == self.generalName
isGeneral = property(isGeneral)
def icon(self, size, loader):
+ """ icon for this plugin
+
+ @param size KIcon size
+ @param loader KIconLoader instance
+ @return icon instance
+ """
if App.debug:
return loader.loadIcon('empty', KIcon.NoGroup, size)
name = self.plugin.Name
@@ -174,45 +237,32 @@ class Plugin:
pix.convertFromImage(img.smoothScale(size, size, QImage.ScaleMin))
return pix
- def nativeSettingsGroups(self):
- settingsMap = {}
- for setting in self.plugin.Settings:
- seq = settingsMap.setdefault(setting.Type, [])
- seq.append(setting)
- return settingsMap
-
- def regroupSettings(self):
- mapping = self.nativeSettingsGroups()
- remap = {}
- for typ, values in mapping.items():
- other = self.alternateGroup(typ, values, mapping)
- seq = remap.setdefault(other, [])
- values.sort()
- seq.extend(values)
- return remap
-
- def alternateGroup(self, typ, val, mapping):
- if typ in ('Int', 'Float'):
- return 'Numeric Values'
- if typ in ('Bool', 'String'):
- return 'Choices'
- if typ in ('Binding', ):
- return 'Bindings'
- return typ
-
+ altType = {
+ 'Int' : 'Values',
+ 'Float' : 'Values',
+ 'Color' : 'Colors',
+ 'Bool' : 'Choices',
+ 'String' : 'Choices',
+ 'Binding' : 'Bindings',
+ 'List of String' : 'Items',
+ }
+
def settings(self):
- mapping = {}
- settings = [Setting(s) for s in self.plugin.Settings]
- for setting in settings:
- key = self.alternateGroup(setting.Type, None, None)
- seq = mapping.setdefault(key, [])
- seq.append(setting)
- for seq in mapping.values():
- seq.sort()
- return mapping
+ """ mapping of plugin settings
+
+ """
+ settingtype = {}
+ for setting in [Setting(s) for s in self.plugin.Settings]:
+ typ = setting.Type
+ key = self.altType.get(typ, typ)
+ settingtype.setdefault(key, []).append(setting)
+ return settingtype
settings = property(settings)
def groups(self):
+ """ sorted groups sequence
+
+ """
groups = [Group(g) for g in self.plugin.Groups]
groups.sort()
return groups
@@ -220,109 +270,110 @@ class Plugin:
class Group:
+ """ Group -> wraps berylsetting.Group instances with extra
+ methods and properties.
+
+ """
def __init__(self, group):
self.group = group
def __getattr__(self, value):
+ """ x.__getattr__('name') <==> x.name
+
+ """
return getattr(self.group, value)
def __cmp__(self, other):
+ """ x.__cmp__(y) <==> cmp(x, y)
+
+ """
if not isinstance(other, Group):
other = Group(other)
return cmp(self.label, other.label)
def label(self):
+ """ label for this group
+
+ """
return self.Name or self.Desc or 'Uncategorized'
label = property(label)
def settings(self, plugin):
- if not isinstance(plugin, Plugin):
- plugin = Plugin(plugin)
+ """ sequence of settings in this group for plugin
+
+ """
group = self.Name
- settings = [Setting(s) for s in plugin.Settings if s.Group==group]
- settings.sort()
- return settings
+ return [Setting(s) for s in plugin.Settings if s.Group==group]
class Setting:
- iconNameMap = {
- 'Binding' : 'mouse',
- 'Bool' : 'apply',
- 'Int' : 'configure',
- 'List of String' : 'view_text',
- 'String' : 'view_detailed',
- 'Back':'back',
- }
+ """ Setting -> wraps berylsetting.Setting instances with extra
+ methods and properties.
- labelMap = {
- 'Binding' : 'Keyboard/Mouse',
- 'Bool' : 'Choices',
- 'Int' : 'Values',
- 'List of String' : 'Files',
- 'String' : 'Values',
+ """
+ iconNameMap = {
+ 'Bindings' : 'mouse',
+ 'Choices': 'apply',
+ 'Colors' : 'colorize',
+ 'Items': 'edit',
+ 'Values' : 'exec',
+ 'Back' : 'back',
+ 'None' : 'back',
}
def __init__(self, setting):
self.setting = setting
- def __cmp__(self, other):
- try:
- a = int(self.ShortDesc.split()[-1])
- except:
- a = self.ShortDesc
- try:
- b = int(other.ShortDesc.split()[-1])
- except:
- b = getattr(other, 'ShortDesc', None)
- return cmp(a, b)
-
def __getattr__(self, value):
+ """ x.__getattr__('name') <==> x.name
+
+ """
return getattr(self.setting, value)
def __repr__(self):
+ """ x.__repr__() <==> repr(x)
+
+ """
args = (self.__module__, self.__class__.__name__,
self.Name,
hex(abs(id(self))))
return "<%s.%s instance name='%s' at %s>" % args
-
+ __str__ = __repr__
+
def set(self, value):
+ """ set the setting's value
+
+ @param value new value for setting
+ @return None
+ """
self.setting.Value = value
def icon(cls, value, size):
- name = cls.iconNameMap.get(str(value), cls.iconNameMap['Bool'])
+ """ icon for this plugin
+
+ @param value setting type name
+ @param size KIcon size
+ @return icon instance
+ """
+ name = cls.iconNameMap.get(str(value), cls.iconNameMap['Choices'])
return icon(name, size=size)
icon = classmethod(icon)
- def label(self):
- value = self.ShortDesc
- value = value.title()
- for pattern, repl in self.fixes:
- value = sub(pattern, repl, value)
- return value
- return settingLabelMap.get(value, value)
- label = property(label)
-
def getValue(self):
+ """ get value of setting, explicitly silencing errors
+
+ @return setting value
+ """
try:
return self.setting.Value
except (IndexError, ):
return ''
def setValue(self, value):
+ """ set value of setting
+
+ @param new value for setting
+ @return None
+ """
self.set(value)
Value = property(getValue, setValue)
-
-
- fixes = [
- (' A ', ' a '),
- (' And ', ' and '),
- (' For ', ' for '),
- (' In ', ' in '),
- (' The ', ' the '),
- (' To ', ' to '),
- (' Of ', ' of '),
- (' On ', ' on '),
- (' Fsp', ' FSP'),
- (' Svg', ' SVG'),
- (' Vblank', ' VBlank'),
- ]
diff --git a/kberylsettings/contentframe.py b/kberylsettings/contentframe.py
index c4085fe..6890fd5 100644
--- a/kberylsettings/contentframe.py
+++ b/kberylsettings/contentframe.py
@@ -196,7 +196,6 @@ class SettingPage:
"""
self.enableApplyReset(False, False)
-
def settingDefaults(self):
""" set each setting to its default value
@@ -308,7 +307,7 @@ class TabPage(Frame, SettingPage):
for group in plugin.groups:
page = MultiSettingFrame(tabs)
page.setPlugin(plugin, group.settings(plugin))
- tabs.addTab(page, group.label)
+ tabs.addTab(page, i18n(group.label))
self.connect(page.container, changed, self.onSomethingChanged)
tabs.setCurrentPage(0)
diff --git a/kberylsettings/lib.py b/kberylsettings/lib.py
index e8a033b..44dbbab 100644
--- a/kberylsettings/lib.py
+++ b/kberylsettings/lib.py
@@ -79,6 +79,7 @@ def iconLoader():
"""
return KGlobal.instance().iconLoader()
+
def icon(name, group=KIcon.NoGroup, size=KIcon.SizeSmall):
""" loads pixmap by name
@@ -177,4 +178,3 @@ def buildPart(parent, servicetype, constraint, writable=False):
if part:
break
return part
-
diff --git a/kberylsettings/main.py b/kberylsettings/main.py
index b1aedff..632aacb 100644
--- a/kberylsettings/main.py
+++ b/kberylsettings/main.py
@@ -333,7 +333,7 @@ class KBerylSettings(KMainWindow):
self.iconSizePopup.setItemEnabled(menuid, isIconMode)
for mode, menuid in self.modePopupIds.items():
self.modePopup.setItemChecked(menuid, mode==value)
-
+
def onImport(self):
""" shows dialog to select profile for import
diff --git a/kberylsettings/pluginframe.py b/kberylsettings/pluginframe.py
index 8d81f9e..f096de3 100644
--- a/kberylsettings/pluginframe.py
+++ b/kberylsettings/pluginframe.py
@@ -246,10 +246,10 @@ class IconView(BasicPluginView):
self.iconSize = size
for item in self:
plugin, setting = item.value
- if plugin:
- item.setPixmap(0, plugin.icon(size, self.loader))
+ if setting or not plugin:
+ item.setPixmap(0, Setting.icon(setting, size))
else:
- item.setPixmap(0, Setting.icon(setting, size))
+ item.setPixmap(0, plugin.icon(size, self.loader))
def onItemClick(self, item):
""" emit a signal if a plugin item is selected
@@ -337,7 +337,7 @@ class TreeView(BasicPluginView):
while child:
item.takeItem(child)
child = item.firstChild()
- for key in keys:
+ for key in keys[::-1]:
sub = ValueListViewItem(item, key, (plugin, key))
sub.setPixmap(0, Setting.icon(key, self.iconSize))
return item
@@ -413,7 +413,7 @@ class CategoryView(BasicPluginView):
item = self.findItem(desc, 0)
if not item:
item = CategoryListViewItem(self, desc, (None, None))
- item.setPixmap(0, category.icon(self.iconSize, self.loader))
+ item.setPixmap(0, category.icon(self.iconSize))
return item
def pluginItem(self, plugin, parent):
diff --git a/kberylsettings/settingwidget.py b/kberylsettings/settingwidget.py
index 0bfe81d..c1689dd 100644
--- a/kberylsettings/settingwidget.py
+++ b/kberylsettings/settingwidget.py
@@ -94,7 +94,7 @@ class SettingWidget(QFrame):
@return layoutType instance with QLabel added
"""
layout = layoutType(self)
- label = self.label = QLabel(setting.label, self)
+ label = self.label = QLabel(setting.ShortDesc, self)
layout.addWidget(label, stretch)
return layout
@@ -502,8 +502,8 @@ 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)
+ #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)