diff options
author | natural <natural> | 2006-12-23 23:03:53 +0000 |
---|---|---|
committer | natural <natural> | 2006-12-23 23:03:53 +0000 |
commit | 5dbd7720a4e446d8f12c1456584e354a3facdd7c (patch) | |
tree | 87219a0b522de31d9dcbcd110459ceebed481be2 /kberylsettings/contentframe.py | |
parent | 218899acc534b1d8d8896ecf5cbbda8c676732be (diff) | |
download | kberylsettings-5dbd7720a4e446d8f12c1456584e354a3facdd7c.tar.gz kberylsettings-5dbd7720a4e446d8f12c1456584e354a3facdd7c.tar.bz2 |
Added popup balloons for setting.LongDesc.
Initial add of (gimped) kberylsettings.png.
Fixed no-save-settings-on-quit-action bug.
Tweaks to contentframe.py.
Diffstat (limited to 'kberylsettings/contentframe.py')
-rw-r--r-- | kberylsettings/contentframe.py | 126 |
1 files changed, 82 insertions, 44 deletions
diff --git a/kberylsettings/contentframe.py b/kberylsettings/contentframe.py index e0f53d8..bcea158 100644 --- a/kberylsettings/contentframe.py +++ b/kberylsettings/contentframe.py @@ -3,15 +3,15 @@ """ kberylsettings.contentframe -> defines the right side about/setting views. """ -from os.path import abspath - -from qt import Qt, QFrame, QLabel, QHBoxLayout, QScrollView, QVBoxLayout, QStringList, QSizePolicy, QSize from kdecore import KIcon -from kdeui import KStdGuiItem, KPushButton, KMessageBox, KSeparator +from kdeui import KMessageBox, KPassivePopup, KPushButton, \ + KSeparator, KStdGuiItem +from qt import Qt, QFrame, QHBoxLayout, QLabel, QScrollView, QSize, \ + QSizePolicy, QStringList, QVBoxLayout -from kberylsettings.lib import App, Signals, buildPart, iconLoader -from kberylsettings.settingframe import SettingFrame -from kberylsettings.widget import Frame, WidgetStack +from kberylsettings.lib import App, Signals, buildPart, icon, iconLoader, iconSet +from kberylsettings.widget import Frame, SmallPushButton, WidgetStack +from kberylsettings.settingwidget import settingWidget class ContentFrame(WidgetStack): @@ -44,7 +44,6 @@ class ContentFrame(WidgetStack): @return None """ - self.settingsPage = page = Frame(self, 6, 10) self.addWidget(page, self.settingsPageId) @@ -56,28 +55,27 @@ class ContentFrame(WidgetStack): headerLayout.addWidget(self.pluginIconLabel, 1) headerLayout.addWidget(self.pluginNameLabel, 10) - self.settingsMain = main = SettingsMainFrame(page) - ## ugly hack that took me 6 hours (!!) to find - self.any = Frame(page) - self.settingsScroller = scroller = ContentScroll(self.any, main) + self.settingsMain = main = SettingsContainer(page) + self.scrollerWrap = wrap = Frame(page) + self.settingsScroller = scroller = ContentScroll(wrap, main) - sep = KSeparator(KSeparator.Horizontal, page) + KSeparator(KSeparator.Horizontal, page) self.settingsFooter = footer = QFrame(page) footerLayout = QHBoxLayout(footer) def contentButton(name): gui = getattr(KStdGuiItem, name)() - button = KPushButton(gui.iconSet(), gui.text(), self.settingsFooter) + button = KPushButton(gui.iconSet(), gui.text(), footer) footerLayout.addWidget(button) return button self.helpButton = contentButton('help') self.defaultsButton = contentButton('defaults') - footerLayout.addStretch(100) - self.applyButton = contentButton('apply') - self.applyButton.setEnabled(False) - self.resetButton = contentButton('reset') - self.resetButton.setEnabled(False) + footerLayout.addStretch(2) + self.applyButton = applyButton = contentButton('apply') + applyButton.setEnabled(False) + self.resetButton = resetButton = contentButton('reset') + resetButton.setEnabled(False) def buildConnections(self): """ build the connections for this instance @@ -105,13 +103,13 @@ class ContentFrame(WidgetStack): @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() + logofile = 'file://%s' % App.basedir + '/html/beryl-manager.png' + htmlsrc = open(App.basedir + '/html/plugin.html').read() if plugin is None: pluginname = 'Beryl Settings' plugindesc = 'Beryl Settings - Get Your Effects On!' else: - #logofile = 'file://%s' % (abspath(App.basedir + '/pixmaps/beryl-settings-section-%s.png' % plugin.Name), ) + #logofile = 'file://%s' % App.basedir + '/pixmaps/beryl-settings-section-%s.png' % plugin.Name pluginname = plugin.ShortDesc plugindesc = plugin.LongDesc self.infoHtml.begin() @@ -164,39 +162,35 @@ class ContentFrame(WidgetStack): self.resetButton.setEnabled(False) def settingApply(self): - """ not implemented + """ not final """ - frame = self.settingsPage - widgets = frame.queryList('SettingWidgetBase') - exceptions = [] - for widget in widgets: + excs = [] + for w in self.settingsPage.queryList('SettingWidgetBase'): try: - value = widget.value() - widget.setting.set(value) - widget.initial = value - print '****', widget.setting.ShortDesc, widget.setting.Value + v = w.value() + w.setting.set(v) + w.initial = v except (Exception, ), exc: - exceptions.append((widget.plugin.Name, widget.setting.Name, exc)) - if exceptions: - exclist = QStringList() - for exc in exceptions: - exclist.append('Plugin:%s Setting:%s Exception:%s' % exc) - ## KMessageBox.errorList isn't available! - KMessageBox.informationList(None, 'Exceptions Saving Settings', - exclist) + excs.append((w.plugin.Name, w.setting.Name, exc)) + if excs: + excstrs = QStringList() + for exc in excs: + excstrs.append('Plugin:%s Setting:%s Exception:%s' % exc) + KMessageBox.errorList(None, 'Exceptions Saving Settings', + excstrs) self.applyButton.setEnabled(False) self.resetButton.setEnabled(False) self.emit(Signals.statusMessage, ('Saving settings...', )) self.emit(Signals.berylSettingChanged, ()) -class SettingsMainFrame(QFrame): +class SettingsContainer(QFrame): def __init__(self, parent): QFrame.__init__(self, parent) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.settingFrames = [] - layout = QVBoxLayout(self, 20) + layout = QVBoxLayout(self, 5) def addSettings(self, plugin, settings): self.clearFrames() @@ -207,7 +201,7 @@ class SettingsMainFrame(QFrame): self.settingFrames.append(frame) layout.addWidget(frame, 0, Qt.AlignTop) self.connect(frame, changed, self, changed) - layout.addStretch(100) + layout.addStretch(5) for frame in self.settingFrames: frame.show() self.updateGeometry() @@ -219,7 +213,52 @@ class SettingsMainFrame(QFrame): self.settingFrames = [] - +class SettingFrame(QFrame): + """ SettingFrame -> displays editing widgets for a single Setting instance. + + """ + def __init__(self, parent, plugin, setting): + QFrame.__init__(self, parent) + mainLayout = QVBoxLayout(self) + innerLayout = QHBoxLayout(mainLayout, 3) + self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) + self.infoCaption = setting.ShortDesc + self.infoText = setting.LongDesc + self.infoButton = info = SmallPushButton(iconSet('help'), '', self) + self.resetButton = reset = SmallPushButton(iconSet('reload'), '', self) + self.settingWidget = widget = settingWidget(self, plugin, setting) + if isinstance(widget.layout(), QHBoxLayout): + align = Qt.AlignLeft | Qt.AlignVCenter + else: + align = Qt.AlignLeft | Qt.AlignTop + innerLayout.addWidget(info, 0, align) + innerLayout.addWidget(reset, 0, align) + innerLayout.addWidget(widget, 10) + mainLayout.addSpacing(10) + + connect = self.connect + connect(info, Signals.clicked, self.showInfo) + connect(widget, Signals.somethingChanged, + self, Signals.somethingChanged) + + def showInfo(self): + """ show a balloon tip with the setting description + + @return None + """ + parent = self.resetButton + ico = icon('help', size=KIcon.SizeLarge) + txt = self.infoText + cap = self.infoCaption + msg = KPassivePopup.message + pop = msg(KPassivePopup.Balloon, cap, txt, ico, parent) + pos = pop.pos() + pos.setY(pos.y() + (parent.height() / 2)) + pos.setX(pos.x() + (parent.width() * 2)) + pop.show() + pop.move(pos) + + class ContentScroll(QScrollView): """ ContentScroll -> a scroll view fitted to a single child @@ -227,6 +266,5 @@ class ContentScroll(QScrollView): def __init__(self, parent, child): QScrollView.__init__(self, parent) self.setResizePolicy(QScrollView.AutoOneFit) - #self.setVScrollBarMode(self.AlwaysOn) self.setFrameShape(self.Box) self.addChild(child) |