summaryrefslogtreecommitdiff
path: root/kberylsettings/lib.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/lib.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/lib.py')
-rw-r--r--kberylsettings/lib.py90
1 files changed, 79 insertions, 11 deletions
diff --git a/kberylsettings/lib.py b/kberylsettings/lib.py
index 5f2e484..8a2d795 100644
--- a/kberylsettings/lib.py
+++ b/kberylsettings/lib.py
@@ -1,24 +1,37 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+""" kberylsettings.lib -> library classes, functions, and attributes.
+
+"""
from os import environ
from os.path import abspath, dirname
-from qt import SIGNAL, PYSIGNAL, QPixmap, QImage
-from qt import QSizePolicy
+from qt import PYSIGNAL, SIGNAL, SLOT, QPixmap, QImage
from kdecore import KGlobal, KIcon, KShortcut, i18n
from kdeui import KAction, KStdAction
from kio import KTrader
-from khtml import KHTMLPart # without this, the part isn't created correctly. :(
+from khtml import KHTMLPart # without this, the KHTMLParts aren't created.
from kparts import createReadOnlyPart, createReadWritePart
-appDebug = environ.get('DEBUG', False)
-appBase = abspath(dirname(__file__))
+##
+# a cache for already-created icons
iconCache = {}
+class App:
+ """ class for application-wide settings
+
+ """
+ debug = environ.get('DEBUG')
+ basedir = abspath(dirname(__file__))
+
+
class Signals:
+ """ class with SIGNAL and PYSIGNAL attributes
+
+ """
viewModeChanged = PYSIGNAL('viewModeChanged')
iconSizeChanged = PYSIGNAL('iconSizeChanged')
berylContextChanged = PYSIGNAL('berylContextChanged')
@@ -32,15 +45,34 @@ class Signals:
itemSelected = SIGNAL('selectionChanged(QListViewItem *)')
okClicked = SIGNAL('okClicked()')
activated = SIGNAL('activated()')
+ textChanged = SIGNAL('textChanged(const QString&)')
contextMenuRequest = \
SIGNAL('contextMenuRequested(QListViewItem*,const QPoint&,int)')
-def minSizePolicy():
- return QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
+class Slots:
+ """ class with SLOT attributes
+
+ """
+ close = SLOT('close()')
def icon(name, group=KIcon.NoGroup, size=KIcon.SizeSmall):
+ """ loads pixmap by name
+
+ This function could return the icon directly from the loadIcon
+ call, but that method (for some reason) doesn't apply any icon
+ effects.
+
+ @param name icon name
+ @param group KIcon group
+ @param size KIcon size
+ @return icon as QPixmap instance
+ """
+ try:
+ return iconCache[(name, size)]
+ except (KeyError, ):
+ pass
ico = KGlobal.instance().iconLoader().loadIcon(name, group)
img = ico.convertToImage()
pix = iconCache[(name, size)] = QPixmap()
@@ -49,11 +81,29 @@ def icon(name, group=KIcon.NoGroup, size=KIcon.SizeSmall):
def iconSet(name, group=KIcon.NoGroup, size=KIcon.SizeSmall):
+ """ load icon set by name
+
+ @param name icon set name
+ @param group KIcon group
+ @param size KIcon size
+ @return icon as QIconSet instance
+ """
return KGlobal.instance().iconLoader().loadIconSet(name, group, size)
-def action(name, label, icon, accel, tip, collection, pluggable):
- obj = KAction(collection, name)
+def action(text, label, icon, accel, tip, collection, pluggable):
+ """ creates and configures a KAction instance
+
+ @param text display value for action
+ @param label value associated with action
+ @param icon pixmap for action
+ @param accel constructor parameter for KAccel
+ @param tip tooltip text for actin
+ @param collection KActionCollection instance
+ @param pluggable any object with plug method
+ @return KAction instance
+ """
+ obj = KAction(text)
obj.setShortcut(KShortcut(accel))
obj.setIconSet(iconSet(icon))
obj.setIcon(icon)
@@ -66,14 +116,32 @@ def action(name, label, icon, accel, tip, collection, pluggable):
def stdAction(parent, name, slot, collection, pluggable):
+ """ creates a named KStdAction instance
+
+ @param parent receiver of action
+ @param name attribute of KStdAction class
+ @param slot slot for KStdAction instance
+ @param collection KActionCollection instance
+ @param pluggable any object with plug method
+ @return KStdAction instance
+ """
typ = getattr(KStdAction, name)
obj = typ(parent, slot, collection)
obj.plug(pluggable)
return obj
-def buildPart(parent, query, constraint, writable=False):
- offers = KTrader.self().query(query, constraint)
+def buildPart(parent, servicetype, constraint, writable=False):
+ """ build a KDE part
+
+ @param parent parent object of created part
+ @param servicetype mime type as string, or other service name
+ @param constraint value to limit KTrader query
+ @keyparam writable=False if True, creates read-write part
+ @return KParts.ReadOnlyPart or KParts.ReadWritePart instance
+ """
+ offers = KTrader.self().query(servicetype, constraint)
+ part = None
for ptr in offers:
if writable:
builder = createReadWritePart