summaryrefslogtreecommitdiff
path: root/kberylsettings/lib.py
diff options
context:
space:
mode:
authorracarr <racarr>2006-12-15 19:45:12 +0000
committerracarr <racarr>2006-12-15 19:45:12 +0000
commite9c4bd69ccee487f8d32e8d2e2072dc46fb36f09 (patch)
tree22e638e15060218ba4d180d007cf3e3d60a52df1 /kberylsettings/lib.py
downloadkberylsettings-e9c4bd69ccee487f8d32e8d2e2072dc46fb36f09.tar.gz
kberylsettings-e9c4bd69ccee487f8d32e8d2e2072dc46fb36f09.tar.bz2
racarr: Add Troy Mellhase's kberylsettings manager to branches
Diffstat (limited to 'kberylsettings/lib.py')
-rw-r--r--kberylsettings/lib.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/kberylsettings/lib.py b/kberylsettings/lib.py
new file mode 100644
index 0000000..69843bd
--- /dev/null
+++ b/kberylsettings/lib.py
@@ -0,0 +1,83 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+from os import environ
+from os.path import abspath, dirname
+
+from qt import SIGNAL, PYSIGNAL, QPixmap, QImage
+from qt import QSizePolicy
+
+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 kparts import createReadOnlyPart, createReadWritePart
+
+
+appDebug = environ.get('DEBUG', False)
+appBase = abspath(dirname(__file__))
+iconCache = {}
+
+
+class Signals:
+ viewModeChanged = PYSIGNAL('viewModeChanged')
+ iconSizeChanged = PYSIGNAL('iconSizeChanged')
+ berylContextChanged = PYSIGNAL('berylContextChanged')
+ berylSettingChanged = PYSIGNAL('berylSettingChanged')
+ berylPluginEnabled = PYSIGNAL('berylPluginEnabled')
+ pluginAbout = PYSIGNAL('pluginAbout')
+ showSettings = PYSIGNAL('showSettings')
+ statusMessage = PYSIGNAL('statusMessage')
+ clicked = SIGNAL('clicked()')
+ itemClicked = SIGNAL('clicked(QListViewItem *)')
+ itemSelected = SIGNAL('selectionChanged(QListViewItem *)')
+ contextMenuRequest = \
+ SIGNAL('contextMenuRequested(QListViewItem*,const QPoint&,int)')
+
+
+def minSizePolicy():
+ return QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
+
+
+def icon(name, group=KIcon.NoGroup, size=KIcon.SizeSmall):
+ ico = KGlobal.instance().iconLoader().loadIcon(name, group)
+ img = ico.convertToImage()
+ pix = iconCache[(name, size)] = QPixmap()
+ pix.convertFromImage(img.smoothScale(size, size, QImage.ScaleMin))
+ return pix
+
+
+def iconSet(name, group=KIcon.NoGroup, size=KIcon.SizeSmall):
+ return KGlobal.instance().iconLoader().loadIconSet(name, group, size)
+
+
+def action(name, label, icon, accel, tip, collection, pluggable):
+ obj = KAction(collection, name)
+ obj.setShortcut(KShortcut(accel))
+ obj.setIconSet(iconSet(icon))
+ obj.setIcon(icon)
+ obj.setText(i18n(label))
+ obj.setToolTip(i18n(tip))
+ collection.insert(obj)
+ collection.connectHighlight(pluggable, obj)
+ obj.plug(pluggable)
+ return obj
+
+
+def stdAction(parent, name, slot, collection, pluggable):
+ 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)
+ for ptr in offers:
+ if writable:
+ builder = createReadWritePart
+ else:
+ builder = createReadOnlyPart
+ part = builder(ptr.library(), parent, ptr.name())
+ if part:
+ break
+ return part