summaryrefslogtreecommitdiff
path: root/kberylsettings/contentframe.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/contentframe.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/contentframe.py')
-rw-r--r--kberylsettings/contentframe.py158
1 files changed, 158 insertions, 0 deletions
diff --git a/kberylsettings/contentframe.py b/kberylsettings/contentframe.py
new file mode 100644
index 0000000..72155b3
--- /dev/null
+++ b/kberylsettings/contentframe.py
@@ -0,0 +1,158 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+""" kberylsettings.contentframe -> defines the right side about/setting views.
+
+"""
+from os.path import abspath
+
+from qt import Qt, QFrame, QLabel, QHBoxLayout, QScrollView, QVBoxLayout
+from kdecore import KIcon, KIconLoader
+from kdeui import KStdGuiItem, KPushButton
+
+from kberylsettings.lib import App, Signals, buildPart
+from kberylsettings.settingframe import SettingFrame
+from kberylsettings.widget import Frame, WidgetStack
+
+
+class ContentFrame(WidgetStack):
+ """ ContentFrame -> stack with About page, Settings Page.
+
+ """
+ aboutPageId = 0
+ settingsPageId = 1
+
+ def __init__(self, parent):
+ WidgetStack.__init__(self, parent)
+ self.loader = KIconLoader(self.__class__.__name__)
+ self.buildAboutPage()
+ self.buildSettingsPage()
+ self.buildConnections()
+
+ def buildAboutPage(self):
+ """ builds the About Plugin page
+
+ @return None
+ """
+ self.aboutPage = Frame(self, margin=6, spacing=10)
+ self.infoHtml = buildPart(self.aboutPage, 'text/html',
+ "Type == 'Service'", True)
+ self.addWidget(self.aboutPage, self.aboutPageId)
+
+ def buildSettingsPage(self):
+ """ builds page for displaying one or more settings
+
+ @return None
+ """
+ self.settingsPage = Frame(self, margin=6, spacing=10)
+ self.pluginHeader = QFrame(self.settingsPage)
+ self.pluginIconLabel = QLabel(self.pluginHeader)
+ self.pluginNameLabel = QLabel(self.pluginHeader)
+ layout = QHBoxLayout(self.pluginHeader)
+ layout.addWidget(self.pluginIconLabel)
+ layout.addWidget(self.pluginNameLabel, 100)
+
+ self.settingsMain = QFrame(self)
+ self.settingsMain.settingsWidgets = []
+ layout = QVBoxLayout(self.settingsMain)
+
+ self.settingsScroller = ContentScroll(self.settingsPage, self.settingsMain)
+ if not App.debug:
+ self.settingsScroller.setFrameShape(Frame.NoFrame)
+ self.settingsFooter = QFrame(self.settingsPage)
+ layout = QHBoxLayout(self.settingsFooter)
+
+ def contentButton(name):
+ gui = getattr(KStdGuiItem, name)()
+ button = KPushButton(gui.iconSet(), gui.text(), self.settingsFooter)
+ layout.addWidget(button)
+ return button
+
+ self.helpButton = contentButton('help')
+ self.defaultsButton = contentButton('defaults')
+ layout.addStretch(100)
+ self.applyButton = contentButton('apply')
+ self.resetButton = contentButton('reset')
+ self.addWidget(self.settingsPage, self.settingsPageId)
+
+ def buildConnections(self):
+ """ build the connections for this instance
+
+ @return None
+ """
+ self.connect(self.helpButton, Signals.clicked, self.settingHelp)
+ self.connect(self.defaultsButton, Signals.clicked, self.settingDefaults)
+ self.connect(self.applyButton, Signals.clicked, self.settingApply)
+
+ def showAbout(self, plugin):
+ """ displays the About Plugin page with information from the plugin
+
+ @param plugin berylsettings Plugin instance
+ @return None
+ """
+ logofile = 'file://%s' % (abspath(App.basedir + '/html/beryl-manager.png'), )
+ htmlsrc = open(abspath(App.basedir + '/html/plugin.html')).read()
+ if plugin is None:
+ pluginname = 'Beryl Settings'
+ plugindesc = 'Beryl Settings - Get Your Effects On!'
+ else:
+ pluginname = plugin.ShortDesc
+ plugindesc = plugin.LongDesc
+ self.infoHtml.begin()
+ self.infoHtml.write(htmlsrc % locals())
+ self.infoHtml.end()
+ self.raiseWidget(self.aboutPageId)
+
+ def showSettings(self, plugin, arg):
+ """ displays the settings page with individual setting frames
+
+ @param plugin berylsettings Plugin instance
+ @param arg setting name or setting section name
+ @return None
+ """
+ self.settingsMain.hide()
+ for widget in self.settingsMain.settingsWidgets:
+ widget.close()
+ layout = self.settingsMain.layout()
+ layout.deleteAllItems()
+ if arg in plugin.settings:
+ settings = plugin.settings[arg]
+ extra = ' - %s' % (arg, )
+ else:
+ settings = [arg, ]
+ extra = ''
+ ico = plugin.icon(KIcon.SizeLarge, self.loader)
+ self.pluginIconLabel.setPixmap(ico)
+ self.pluginNameLabel.setText('<b>%s%s</b>' % (plugin.ShortDesc, extra))
+ for setting in settings:
+ frame = SettingFrame(self.settingsMain, setting)
+ self.settingsMain.settingsWidgets.append(frame)
+ layout.addWidget(frame, 0, Qt.AlignTop)
+ frame.show()
+ layout.addStretch(100)
+ self.settingsMain.show()
+ self.raiseWidget(self.settingsPageId)
+
+ def settingHelp(self):
+ """ not implemented
+
+ """
+
+ def settingDefaults(self):
+ """ not implemented
+
+ """
+
+ def settingApply(self):
+ """ not implemented
+
+ """
+
+
+class ContentScroll(QScrollView):
+ """ ContentScroll -> a scroll view fitted to a single child
+
+ """
+ def __init__(self, parent, child):
+ QScrollView.__init__(self, parent)
+ self.addChild(child)
+ self.setResizePolicy(QScrollView.AutoOneFit)