summaryrefslogtreecommitdiff
path: root/kberylsettings/beryl.py
diff options
context:
space:
mode:
authornatural <natural>2006-12-17 10:06:18 +0000
committernatural <natural>2006-12-17 10:06:18 +0000
commit99b44818d60794aae11dca5f67722ab32c98f137 (patch)
tree8e54863077d35d0cbb88925c3fd012827d328a80 /kberylsettings/beryl.py
parentfcfa23f8e1b16bc68329c9e9aa3cb31d906ee572 (diff)
downloadkberylsettings-99b44818d60794aae11dca5f67722ab32c98f137.tar.gz
kberylsettings-99b44818d60794aae11dca5f67722ab32c98f137.tar.bz2
Implemented search -- search for plugin settings by keyword.
Refactored views and content frames. Many docstrings.
Diffstat (limited to 'kberylsettings/beryl.py')
-rw-r--r--kberylsettings/beryl.py75
1 files changed, 50 insertions, 25 deletions
diff --git a/kberylsettings/beryl.py b/kberylsettings/beryl.py
index ed0f5ae..ba8a791 100644
--- a/kberylsettings/beryl.py
+++ b/kberylsettings/beryl.py
@@ -1,16 +1,25 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+""" kberylsettings.beryl -> wrappers around berylsettings objects.
+
+"""
import berylsettings
-import re
+
from os.path import abspath, exists
+from re import sub
+
from qt import QImage, QPixmap, QObject
from kdecore import KIcon
-from kberylsettings.lib import appDebug, appBase, iconCache, icon, Signals
+from kberylsettings.lib import App, Signals, icon
class Context(QObject):
+ """ Context -> wraps berylsetting.Context instances with extra
+ methods and properties.
+
+ """
activePluginsSettingName = 'active_plugins'
-
+
def __init__(self, context=None):
QObject.__init__(self)
if context is None:
@@ -18,43 +27,67 @@ class Context(QObject):
context.read()
self.context = context
+ def getPlugins(self):
+ """ sorted plugin sequence
- def plugins(self):
+ @return sequence of Plugin wrapper instances
+ """
seq = [Plugin(p) for p in self.context.Plugins]
seq.sort(reverse=True)
return iter(seq)
- plugins = property(plugins)
-
+ plugins = property(getPlugins)
def plugin(self, value):
+ """ locates plugin by name, description, or index
+
+ @param value plugin name, short description, or index
+ @return Plugin wrapper instance
+ """
try:
value + 0
except (TypeError, ):
for plugin in self.plugins:
if value == plugin.ShortDesc:
return plugin
+ if value == plugin.Name:
+ return plugin
else:
return list(self.plugins)[value]
-
def getActive(self):
+ """ sequence of active plugin names
+
+ @return sequence of active plugin names
+ """
act = self.general.Setting(self.activePluginsSettingName).Value
return act + [Plugin.generalName, ]
def setActive(self, active):
+ """ sets active plugins
+
+ @param active sequence of plugin names to set as active
+ @return None
+ """
self.general.Setting(self.activePluginsSettingName).Value = active
active = property(getActive, setActive)
+ def getGeneral(self):
+ """ general plugin instance
- def general(self):
- return self.context.Plugin(Plugin.generalName)
-
- general = property(general)
+ @return Plugin wrapper instance
+ """
+ return Plugin(self.context.Plugin(Plugin.generalName))
+ general = property(getGeneral)
def write(self):
+ """ saves the beryl context and messages the extension to
+ reload the new settings.
+
+ @return None
+ """
self.emit(Signals.statusMessage, ('Saving Beryl settings....', ))
self.context.write()
berylsettings.send_reload()
@@ -63,44 +96,40 @@ class Context(QObject):
class Plugin:
generalName = '_'
+ iconCache = {}
def __init__(self, plugin):
self.plugin = plugin
-
def __getattr__(self, value):
return getattr(self.plugin, value)
-
def __cmp__(self, other):
if self.isGeneral:
return -1
return cmp(self.plugin.ShortDesc,
getattr(other.plugin, 'ShortDesc', None))
-
def isGeneral(self):
return self.plugin.Name == self.generalName
isGeneral = property(isGeneral)
-
def icon(self, size, loader):
- if appDebug:
+ if App.debug:
return loader.loadIcon('empty', KIcon.NoGroup, size)
name = self.plugin.Name
try:
- pix = iconCache[(name, size)]
+ pix = self.iconCache[(name, size)]
except (KeyError, ):
- path = abspath(appBase + '/pixmaps/beryl-settings-section-%s.svg' % name)
+ path = abspath(App.basedir + '/pixmaps/beryl-settings-section-%s.svg' % name)
if not exists(path):
path = 'unknown'
ico = loader.loadIcon(path, KIcon.NoGroup)
img = ico.convertToImage()
- pix = iconCache[(name, size)] = QPixmap()
+ pix = self.iconCache[(name, size)] = QPixmap()
pix.convertFromImage(img.smoothScale(size, size, QImage.ScaleMin))
return pix
-
def nativeSettingsGroups(self):
settingsMap = {}
for setting in self.plugin.Settings:
@@ -108,7 +137,6 @@ class Plugin:
seq.append(setting)
return settingsMap
-
def regroupSettings(self):
mapping = self.nativeSettingsGroups()
remap = {}
@@ -119,7 +147,6 @@ class Plugin:
seq.extend(values)
return remap
-
def alternateGroup(self, typ, val, mapping):
if typ in ('Int', 'Float'):
return 'Numeric Values'
@@ -187,7 +214,7 @@ class Setting:
value = self.ShortDesc
value = value.title()
for pattern, repl in self.fixes:
- value = re.sub(pattern, repl, value)
+ value = sub(pattern, repl, value)
return value
return settingLabelMap.get(value, value)
label = property(label)
@@ -205,5 +232,3 @@ class Setting:
(' Svg', ' SVG'),
(' Vblank', ' VBlank'),
]
-
-