summaryrefslogtreecommitdiff
path: root/kberylsettings/beryl.py
diff options
context:
space:
mode:
Diffstat (limited to 'kberylsettings/beryl.py')
-rw-r--r--kberylsettings/beryl.py93
1 files changed, 82 insertions, 11 deletions
diff --git a/kberylsettings/beryl.py b/kberylsettings/beryl.py
index 2594361..d07d89a 100644
--- a/kberylsettings/beryl.py
+++ b/kberylsettings/beryl.py
@@ -27,19 +27,24 @@ class Context(QObject):
context.Read()
self.context = context
+ def __repr__(self):
+ args = (self.__module__, self.__class__.__name__, hex(abs(id(self))))
+ return "<%s.%s instance at %s>" % args
+
def getCategories(self):
- return self.context.Categories
+ seq = [Category(c) for c in self.context.Categories]
+ seq.sort()
+ return seq
categories = property(getCategories)
-
def getPlugins(self):
""" sorted plugin sequence
@return sequence of Plugin wrapper instances
"""
seq = [Plugin(p) for p in self.context.Plugins]
- seq.sort(reverse=True)
- return iter(seq)
+ seq.sort()
+ return seq
plugins = property(getPlugins)
def plugin(self, value):
@@ -53,9 +58,9 @@ class Context(QObject):
except (TypeError, ):
for plugin in self.plugins:
if value == plugin.ShortDesc:
- return plugin
+ return Plugin(plugin)
if value == plugin.Name:
- return plugin
+ return Plugin(plugin)
else:
return list(self.plugins)[value]
@@ -102,6 +107,26 @@ class Context(QObject):
self.emit(Signals.statusMessage, ('Beryl settings reloaded.', ))
+class Category:
+ def __init__(self, category):
+ self.category = category
+
+ def __cmp__(self, other):
+ return cmp(self.ShortDesc, other.ShortDesc)
+
+ def __getattr__(self, value):
+ return getattr(self.category, value)
+
+ def icon(self, size, loader):
+ return loader.loadIcon('unknown', KIcon.NoGroup, size)
+
+ def plugins(self):
+ seq = [Plugin(p) for p in self.category.Plugins]
+ seq.sort()
+ return seq
+ plugins = property(plugins)
+
+
class Plugin:
generalName = '_'
iconCache = {}
@@ -109,16 +134,26 @@ class Plugin:
def __init__(self, plugin):
self.plugin = plugin
- def __getattr__(self, value):
- return getattr(self.plugin, value)
-
def __cmp__(self, other):
- if self.isGeneral:
+ if other is None:
return -1
if not isinstance(other, Plugin):
other = Plugin(other)
+ if self.isGeneral:
+ return -1
+ if other.isGeneral:
+ return 1
return cmp(self.plugin.ShortDesc, other.plugin.ShortDesc)
+ def __getattr__(self, value):
+ return getattr(self.plugin, value)
+
+ def __repr__(self):
+ args = (self.__module__, self.__class__.__name__,
+ self.Name,
+ hex(abs(id(self))))
+ return "<%s.%s instance name='%s' at %s>" % args
+
def isGeneral(self):
return self.plugin.Name == self.generalName
isGeneral = property(isGeneral)
@@ -175,9 +210,39 @@ class Plugin:
for seq in mapping.values():
seq.sort()
return mapping
-
settings = property(settings)
+ def groups(self):
+ groups = [Group(g) for g in self.plugin.Groups]
+ groups.sort()
+ return groups
+ groups = property(groups)
+
+
+class Group:
+ def __init__(self, group):
+ self.group = group
+
+ def __getattr__(self, value):
+ return getattr(self.group, value)
+
+ def __cmp__(self, other):
+ if not isinstance(other, Group):
+ other = Group(other)
+ return cmp(self.label, other.label)
+
+ def label(self):
+ return self.Name or self.Desc or 'Uncategorized'
+ label = property(label)
+
+ def settings(self, plugin):
+ if not isinstance(plugin, Plugin):
+ plugin = Plugin(plugin)
+ group = self.Name
+ settings = [Setting(s) for s in plugin.Settings if s.Group==group]
+ settings.sort()
+ return settings
+
class Setting:
iconNameMap = {
@@ -214,6 +279,12 @@ class Setting:
def __getattr__(self, value):
return getattr(self.setting, value)
+ def __repr__(self):
+ args = (self.__module__, self.__class__.__name__,
+ self.Name,
+ hex(abs(id(self))))
+ return "<%s.%s instance name='%s' at %s>" % args
+
def set(self, value):
self.setting.Value = value