summaryrefslogtreecommitdiff
path: root/kberylsettings/aboutpage.py
diff options
context:
space:
mode:
authornatural <natural>2006-12-31 06:16:43 +0000
committernatural <natural>2006-12-31 06:16:43 +0000
commit0aa170e67595b83e49e72d78f41c27a48d3059ad (patch)
treec53db324e8a6b068846d55bdc163afbb634bd1df /kberylsettings/aboutpage.py
parentb3bd6e4163a79f03edf2c2c6935b530d2af21e14 (diff)
downloadkberylsettings-0aa170e67595b83e49e72d78f41c27a48d3059ad.tar.gz
kberylsettings-0aa170e67595b83e49e72d78f41c27a48d3059ad.tar.bz2
Support for a nifty "about beryl" and "about plugin" page. Again,
kcontrol is the example. Adding png versions of each svg; KHTML won't display svg icons. Also including a script to convert from svg to png.
Diffstat (limited to 'kberylsettings/aboutpage.py')
-rw-r--r--kberylsettings/aboutpage.py145
1 files changed, 145 insertions, 0 deletions
diff --git a/kberylsettings/aboutpage.py b/kberylsettings/aboutpage.py
new file mode 100644
index 0000000..648700e
--- /dev/null
+++ b/kberylsettings/aboutpage.py
@@ -0,0 +1,145 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+""" kberylsettings.contentframe -> defines the right side about/setting views.
+
+"""
+from os import popen
+
+from kdecore import KIcon, i18n, locate
+from khtml import KHTMLPart
+from pykdeconfig import _pkg_config
+
+from kberylsettings.beryl import Setting
+from kberylsettings.lib import App, Signals, iconLoader
+from kberylsettings.widget import Frame
+
+
+class AboutPage(Frame):
+ """ AboutPage -> displays info about Beryl, environment, and plugins.
+
+ """
+ berylProto = 'beryl:/'
+ pluginHREF = '<a href="' + berylProto + '%s">%s</a>'
+ settingHREF = '<a href="' + berylProto + '%s@%s">%s</a>'
+ contentContainer = '<table class="kc_table">%s</table>%s'
+ contentRow = '<tr>%s</tr>'
+ contentCell = '''
+ <td class="kc_leftcol">%s</td><td "kc_rightcol"><b>%s</b></td>
+ '''
+ contentImg = '''
+ <img src="file://%s"
+ ''' + ('width="%s" height="%s" />' % (KIcon.SizeSmall, KIcon.SizeSmall, ))
+ contextExtra = '''
+ Use the "Search" field if you are unsure where to look for a
+ particular configuration option.
+ '''
+
+ def __init__(self, parent):
+ Frame.__init__(self, parent)
+ self.infoHtml = HTMLPart(self)
+ self.loader = iconLoader()
+ self.connect(self.infoHtml, Signals.partURL, self.onURL)
+
+ def pluginContent(self, plugin):
+ """ constructs html content for a berylsettings Plugin
+
+ @param plugin berylsettings Plugin instance
+ @return markup string
+ """
+ rows = []
+ keys = plugin.settings.keys()
+ keys.sort()
+ for key in keys:
+ row = (self.contentImg % Setting.iconPath(key) + '&nbsp;' + \
+ self.settingHREF % (plugin.Name, key, key),
+ i18n(plugin.settingTypeDesc(key)))
+ rows.append(row)
+ rows = [self.contentCell % row for row in rows]
+ rows = [self.contentRow % row for row in rows]
+ return self.contentContainer % (str.join('', rows), '')
+
+ def contextContent(self, context):
+ """ constructs html content for a berylsettings Context
+
+ @param context berylsettings Context instance
+ @return markup string
+ """
+ def cmd(line):
+ return popen(line).read().strip()
+ rows = [
+ ('Beryl Version', cmd('beryl --version')),
+ ('KDE Version', _pkg_config['kde_version_str']),
+ ('PyKDE Version', _pkg_config['pykde_version_str']),
+ ('User', cmd('whoami')),
+ ('Hostname', cmd('uname -n')),
+ ('System', cmd('uname -s')),
+ ('Release', cmd('uname -r')),
+ ('Machine', cmd('uname -m')),
+ ('<br />', '<br />'),
+ ('Active Plugins:', '')
+ ]
+ active = context.active
+ for plugin in [p for p in context.plugins if p.Name in active]:
+ row = (self.contentImg % plugin.iconPath() + '&nbsp;' + \
+ self.pluginHREF % (plugin.Name, plugin.ShortDesc),
+ plugin.LongDesc)
+ rows.append(row)
+ rows = [self.contentCell % (i18n(a), b) for a, b in rows]
+ rows = [self.contentRow % row for row in rows]
+ extra = '<div>%s</div>' % i18n(self.contextExtra)
+ return self.contentContainer % (str.join('', rows), extra)
+
+ def showAbout(self, context, plugin):
+ """ displays the About Plugin page with information from the plugin
+
+ @param plugin berylsettings Plugin instance
+ @return None
+ """
+ self.context = context
+ htmlsrc = open(App.basedir + '/html/main.html').read()
+ extracssurl = locate('data', 'kdeui/about/kde_infopage.css')
+ extracssurl = 'file://%s' % extracssurl
+ kcontrolcssurl = locate('data', 'kcontrol/about/kcontrol.css')
+ kcontrolcssurl = 'file://%s' % kcontrolcssurl
+ logourl = 'file://%s' % App.basedir + '/html/beryl-manager.png'
+ if plugin is None:
+ title = i18n('KDE Beryl Settings')
+ shortdesc = i18n('Configure Your Beryl Settings')
+ longdesc = i18n('Beryl Settings - Get Your Effects On!')
+ content = self.contextContent(context)
+ else:
+ title = plugin.ShortDesc
+ shortdesc = plugin.ShortDesc
+ longdesc = plugin.LongDesc
+ content = self.pluginContent(plugin)
+ self.infoHtml.begin()
+ self.infoHtml.write(htmlsrc % locals())
+ self.infoHtml.end()
+
+ def onURL(self, url):
+ """ emits a signal to show the plugin and setting on a URL click
+
+ @param url string
+ @return None
+ """
+ protocol, path = url.split(self.berylProto)
+ path = path.split('@')
+ try:
+ pluginname, settingkey = path
+ except (ValueError, ):
+ pluginname = path[0]
+ settingkey = None
+ plugin = self.context.Plugin(pluginname)
+ self.emit(Signals.selectPrevious, (plugin, settingkey, True))
+
+
+class HTMLPart(KHTMLPart):
+ """ HTMLPart -> simple subclass that emits urls as they're selected.
+
+ """
+ def urlSelected(self, url, button, state, target, args):
+ """ emit a url when selected
+
+ @return None
+ """
+ self.emit(Signals.partURL, (str(url), ))