From 99b44818d60794aae11dca5f67722ab32c98f137 Mon Sep 17 00:00:00 2001 From: natural Date: Sun, 17 Dec 2006 10:06:18 +0000 Subject: Implemented search -- search for plugin settings by keyword. Refactored views and content frames. Many docstrings. --- kberylsettings/contentframe.py | 158 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 kberylsettings/contentframe.py (limited to 'kberylsettings/contentframe.py') 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('%s%s' % (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) -- cgit v1.1