summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornatural <natural>2007-01-07 06:00:34 +0000
committernatural <natural>2007-01-07 06:00:34 +0000
commite89937e2cf235c1560bdb3a7add8b3701bd4bfd4 (patch)
tree5b8c46e976b0296719b6134361664791e34ed476
parent3348c3e49865c5e6a32073e85a6d7a1574cac244 (diff)
downloadkberylsettings-e89937e2cf235c1560bdb3a7add8b3701bd4bfd4.tar.gz
kberylsettings-e89937e2cf235c1560bdb3a7add8b3701bd4bfd4.tar.bz2
Accounted for changes to berylsettings python extension in r2434.
-rw-r--r--kberylsettings/aboutpage.py3
-rw-r--r--kberylsettings/beryl.py43
-rw-r--r--kberylsettings/lib.py9
-rw-r--r--kberylsettings/main.py100
-rw-r--r--kberylsettings/plugindialog.py13
-rw-r--r--kberylsettings/pluginframe.py28
-rw-r--r--kberylsettings/settingwidget.py19
7 files changed, 125 insertions, 90 deletions
diff --git a/kberylsettings/aboutpage.py b/kberylsettings/aboutpage.py
index 1b3e585..f7db1ec 100644
--- a/kberylsettings/aboutpage.py
+++ b/kberylsettings/aboutpage.py
@@ -78,8 +78,7 @@ class AboutPage(Frame):
('<br />', '<br />'),
('Active Plugins:', '')
]
- active = context.active
- for plugin in [p for p in context.plugins if p.Name in active]:
+ for plugin in [p for p in context.plugins if p.Enabled]:
row = (self.contentImg % plugin.iconPath() + '&nbsp;' + \
self.pluginHREF % (plugin.Name, plugin.ShortDesc),
plugin.LongDesc)
diff --git a/kberylsettings/beryl.py b/kberylsettings/beryl.py
index 7268887..828465c 100644
--- a/kberylsettings/beryl.py
+++ b/kberylsettings/beryl.py
@@ -16,7 +16,6 @@ class Context(QObject):
This class inherits QObject so that instances can emit Qt signals.
"""
- activePluginsSettingName = 'active_plugins'
def __init__(self, context=None):
QObject.__init__(self)
@@ -38,7 +37,7 @@ class Context(QObject):
args = (self.__module__, self.__class__.__name__, hex(abs(id(self))))
return "<%s.%s instance at %s>" % args
__str__ = __repr__
-
+
def getCategories(self):
""" sorted categories sequence
@@ -76,23 +75,6 @@ class Context(QObject):
else:
return list(self.plugins)[value]
- def getActive(self):
- """ sequence of active plugin names
-
- @return sequence of active plugin names
- """
- act = self.general.Setting(self.activePluginsSettingName).Value
- return act
-
- def setActive(self, active):
- """ sets active plugins
-
- @param active sequence of plugin names to set as active
- @return None
- """
- self.general.Setting(self.activePluginsSettingName).Value = active
- active = property(getActive, setActive)
-
def getGeneral(self):
""" general plugin instance
@@ -119,7 +101,7 @@ class Context(QObject):
self.emit(Signals.statusMessage, ('Beryl settings reloaded.', ))
-class Category:
+class Category(object):
""" Category -> wraps berylsetting.Category instances with extra
methods and properties.
@@ -162,7 +144,7 @@ class Category:
def plugins(self):
""" sequence of plugin instances in this category
- @return sequence of active plugin names
+ @return sequence of Plugin instances
"""
seq = [Plugin(p) for p in self.category.Plugins]
seq.sort()
@@ -170,7 +152,7 @@ class Category:
plugins = property(plugins)
-class Plugin:
+class Plugin(object):
""" Plugin -> wraps berylsetting.Plugin instances with extra
methods and properties.
@@ -210,6 +192,19 @@ class Plugin:
hex(abs(id(self))))
return "<%s.%s instance name='%s' at %s>" % args
__str__ = __repr__
+
+ def getEnabled(self):
+ """ true if this plugin is enabled
+
+ """
+ return self.plugin.Enabled
+
+ def setEnabled(self, value):
+ """ set the enabled flag for this plugin
+
+ """
+ self.plugin.Enabled = value
+ enabled = property(getEnabled, setEnabled)
def isGeneral(self):
""" true if this plugin is a general plugin
@@ -294,7 +289,7 @@ class Plugin:
groups = property(groups)
-class Group:
+class Group(object):
""" Group -> wraps berylsetting.Group instances with extra
methods and properties.
@@ -331,7 +326,7 @@ class Group:
return [Setting(s) for s in plugin.Settings if s.Group==group]
-class Setting:
+class Setting(object):
""" Setting -> wraps berylsetting.Setting instances with extra
methods and properties.
diff --git a/kberylsettings/lib.py b/kberylsettings/lib.py
index 13b50f3..995917a 100644
--- a/kberylsettings/lib.py
+++ b/kberylsettings/lib.py
@@ -30,6 +30,8 @@ class Signals:
clickedId = SIGNAL('clicked(int)')
colorChanged = SIGNAL('changed(const QColor &)')
doubleValueChanged = SIGNAL('valueChanged(double)')
+ fileChanged = SIGNAL('dirty(const QString&)')
+ fileCreated = SIGNAL('created(const QString&)')
iconSizeChanged = PYSIGNAL('iconSizeChanged')
intValueChanged = SIGNAL('valueChanged(int)')
itemClicked = SIGNAL('clicked(QListViewItem *)')
@@ -119,8 +121,11 @@ def action(text, iconset, cut, slot, collection, name,
cut = KShortcut()
else:
cut = KShortcut(cut)
- iconset = iconSet(iconset)
- action = KAction(text, iconset, cut, slot, collection, name)
+ if iconset:
+ iconset = iconSet(iconset)
+ action = KAction(text, iconset, cut, slot, collection, name)
+ else:
+ action = KAction(text, cut, slot, collection, name)
if tooltip:
action.setToolTip(tooltip)
if pluggable:
diff --git a/kberylsettings/main.py b/kberylsettings/main.py
index b43e2e7..f28efe4 100644
--- a/kberylsettings/main.py
+++ b/kberylsettings/main.py
@@ -4,12 +4,13 @@
"""
from os import listdir
-from os.path import abspath, dirname, expanduser
+from os.path import abspath, dirname, exists, expanduser
from sys import argv
from kdecore import KApplication, KCmdLineArgs, KIcon, KGlobal, KWin, i18n, locate
from kdeui import KMainWindow, KStdGuiItem, KLineEdit, KSystemTray, KTipDialog, \
KKeyDialog
+from kio import KDirWatch
from kfile import KFileDialog
from qt import Qt, QWidget, QHBoxLayout, QLabel, QImage
@@ -29,7 +30,8 @@ class KBerylSettings(KMainWindow):
viewMode = PluginFrame.categoryPageId
iconSize = KIcon.SizeMedium
startDir = '::kberylsettings'
-
+ berylDir = expanduser('~/.beryl/')
+
def __init__(self):
KMainWindow.__init__(self)
self.buildWidgets()
@@ -140,7 +142,7 @@ class KBerylSettings(KMainWindow):
## done after initial emit to prevent spurious context update
connect(self, Signals.berylContextChanged, self.onContextChanged)
self.tipDialog(force=False)
-
+
def config(self, group=None):
""" loads the general configuration object
@@ -198,18 +200,34 @@ class KBerylSettings(KMainWindow):
profileMap = self.profileMap
except (AttributeError, ):
profileMap = self.profileMap = {}
-
+ try:
+ watcher = self.watcher
+ except (AttributeError, ):
+ watcher = self.watcher = KDirWatch(self)
+ self.connect(watcher, Signals.fileChanged, self.updatedFile)
+ self.connect(watcher, Signals.fileCreated, self.newFile)
+
+ berylDir = self.berylDir
+ profFormat = 'settings%s.Profile'
+ maybeProfiles = [profFormat % i for i in range(1, 6)]
+
pop = Popup(self)
- names = [n for n in listdir(expanduser('~/.beryl'))
- if n.endswith('.Profile')]
- names.sort()
- for name in names:
+ for name in maybeProfiles:
popid = pop.insertItem(name)
- index = hash(name)
- profileMap[index] = name
+ path = berylDir + name
+ index = hash(path)
+ profileMap[index] = path
pop.setItemParameter(popid, index)
+ pop.setItemEnabled(popid, exists(path))
pop.connectItem(popid, self.onProfileSelect)
+ watcher.addFile(path)
return pop
+
+ def updatedFile(self, path):
+ print '### updated file path:', path
+
+ def newFile(self, path):
+ print '### new file path:', path
def viewMenu(self):
""" creates a new View menu
@@ -228,16 +246,31 @@ class KBerylSettings(KMainWindow):
"""
actions = self.actionCollection()
pop = Popup(self)
- self.keysAction = stdAction('keyBindings', self.onConfigKeys,
- actions, 'keyBindings', pop)
self.pluginsAction = action('Select Plugins...', 'configure', 'Ctrl+P',
self.onSelectPlugins,
actions,
'select_plugins',
'Select Beryl plugins.',
pop)
+ pop.insertSeparator()
+ self.toggleMenuBarAction = action('Hide menubar',
+ 'showmenu', 'Ctrl+M',
+ self.onMenuBar,
+ actions,
+ 'toggle_menubar',
+ 'Hide menubar.',
+ pop)
+ self.toggleStatusBarAction = action('Hide statusbar',
+ '', '',
+ self.onStatusBar,
+ actions,
+ 'toggle_statusbar',
+ 'Hide statusbar.',
+ pop)
+ self.keysAction = stdAction('keyBindings', self.onConfigKeys,
+ actions, 'keyBindings', pop)
return pop
-
+
def modeMenu(self):
""" creates a new View Mode menu
@@ -333,16 +366,21 @@ class KBerylSettings(KMainWindow):
self.emit(Signals.showAbout, (self.context, None))
def onPluginDialogOk(self):
- """ sets current context active plugins
+ """ enables and disables plugins when plugin dialog accepted
@return None
"""
- items = self.pluginDialogItems.items()
- active = [name for name, enabled in items if enabled]
+ items = self.pluginDialogItems
context = self.context
for p in context.plugins:
- self.emit(Signals.berylPluginEnabled, (p, p.Name in active))
- context.active = active
+ enable = items.get(p.Name, None)
+ if enable is None:
+ continue
+ ## wtf? the extension raises and exception when we blindly
+ ## set the enabled property.
+ if (enable and not p.Enabled) or (not enable and p.Enabled):
+ p.enabled = enable
+ self.emit(Signals.berylPluginEnabled, (p, p.Enabled))
self.emit(Signals.berylContextChanged, (context, ))
def onProfileSelect(self, itemId):
@@ -355,7 +393,7 @@ class KBerylSettings(KMainWindow):
self.emit(Signals.berylContextChanged, (self.context, ))
def onSelectPlugins(self):
- """ shows dialog to select/deselect active plugins
+ """ shows dialog to enable/disable plugins
@return None
"""
@@ -400,6 +438,30 @@ class KBerylSettings(KMainWindow):
'Select File to Export Profile')
if filename:
print 'exporting file...', filename
+
+ def onMenuBar(self):
+ """ toggle the visibility of the menu bar and the related menu text
+
+ """
+ menuBar = self.menuBar()
+ if menuBar.isVisible():
+ menuBar.hide()
+ self.toggleMenuBarAction.setText('Show menubar')
+ else:
+ menuBar.show()
+ self.toggleMenuBarAction.setText('Hide menubar')
+
+ def onStatusBar(self):
+ """ toggle the visibility of the menu bar and the related menu text
+
+ """
+ statusBar = self.statusBar()
+ if statusBar.isVisible():
+ statusBar.hide()
+ self.toggleStatusBarAction.setText('Show statusbar')
+ else:
+ statusBar.show()
+ self.toggleStatusBarAction.setText('Hide statusbar')
def showMessage(self, text):
""" show a message in the status bar
diff --git a/kberylsettings/plugindialog.py b/kberylsettings/plugindialog.py
index 9a35164..0dd5a6b 100644
--- a/kberylsettings/plugindialog.py
+++ b/kberylsettings/plugindialog.py
@@ -29,7 +29,6 @@ class PluginList(ListView):
@param context berylsetting Context instance
@return mapping of plugin names and their enabled state
"""
- active = context.active
count = textlen = 0
loader = iconLoader()
cats = context.categories
@@ -41,11 +40,11 @@ class PluginList(ListView):
item.setText(1, cnames)
item.setText(2, p.LongDesc)
item.setPixmap(0, p.icon(KIcon.SizeSmall, loader))
- if p.Name in active:
- stateMap[p.Name] = 1
+ if p.Enabled:
+ stateMap[p.Name] = True
item.setState(QCheckListItem.On)
else:
- stateMap[p.Name] = 0
+ stateMap[p.Name] = False
count += 1
textlen = max(textlen, len(p.ShortDesc + p.LongDesc))
@@ -90,7 +89,7 @@ class PluginDialog(KDialogBase):
plugin = self.context.plugin(item.text(0))
state = item.state()
if state == item.On:
- self.pluginMap[plugin.Name] = 1
+ self.pluginMap[plugin.Name] = True
self.satisfy(plugin)
elif state == item.Off:
remaining = self.needs(plugin)
@@ -101,7 +100,7 @@ class PluginDialog(KDialogBase):
text %= (plugin.ShortDesc, str.join(', ', need))
KMessageBox.sorry(self, text)
else:
- self.pluginMap[plugin.Name] = 0
+ self.pluginMap[plugin.Name] = False
def satisfy(self, plugin):
""" enable requirement for plugin if necessary
@@ -113,7 +112,7 @@ class PluginDialog(KDialogBase):
for p in self.context.plugins:
if requirement in p.Provides:
if not self.pluginMap[p.Name]:
- self.pluginMap[p.Name] = 1
+ self.pluginMap[p.Name] = True
item = self.listView.findItem(p.ShortDesc, 0)
if item:
item.setState(item.On)
diff --git a/kberylsettings/pluginframe.py b/kberylsettings/pluginframe.py
index eb64c54..a93fc4f 100644
--- a/kberylsettings/pluginframe.py
+++ b/kberylsettings/pluginframe.py
@@ -130,11 +130,10 @@ class SearchView(Frame):
index = self.index
parent = self.keywordsList
parent.clear()
- active = self.context.active
for keyword in self.index:
if searchtext in keyword.lower():
plugin, setting = index[keyword][0]
- if plugin.Name in active:
+ if plugin.Enabled:
item = ValueListViewItem(parent, keyword, index[keyword])
def showResults(self, item):
@@ -205,15 +204,13 @@ class BasicPluginView(BasicListView):
@return None
"""
- active = self.context.active
for plugin in self.context.plugins[::-1]:
- self.listItem(plugin, active)
+ self.listItem(plugin)
- def listItem(self, plugin, active):
+ def listItem(self, plugin):
""" create a list view item for a plugin
@param plugin beryl settings Plugin object
- @param active sequence of active plugin names
@return QListViewItem instance
"""
item = None
@@ -224,7 +221,7 @@ class BasicPluginView(BasicListView):
if not item:
item = ViewItem(self, plugin.ShortDesc)
item.plugin = plugin
- item.setVisible(plugin.Name in active)
+ item.setVisible(plugin.Enabled)
item.setPixmap(0, plugin.icon(self.iconSize, self.loader))
return item
@@ -300,13 +297,12 @@ class IconView(BasicPluginView):
self.emit(Signals.selectItem, (item, ))
def showPlugins(self):
- """ sets all active plugin items visible
+ """ sets all enabled plugin items visible
@return None
"""
- active = self.context.active
for item in self:
- if item.plugin and item.plugin.Name in active and not item.setting:
+ if item.plugin and item.plugin.Enabled and not item.setting:
item.setVisible(True)
else:
item.setVisible(False)
@@ -382,15 +378,14 @@ class TreeView(BasicPluginView):
BasicPluginView.__init__(self, parent)
self.setRootIsDecorated(True)
- def listItem(self, plugin, active):
+ def listItem(self, plugin):
""" create an item for the plugin and sub items for its settings
@param plugin beryl settings Plugin object
- @param active sequence of active plugin names
@param size icon size
@return QListViewItem instance with children
"""
- item = BasicPluginView.listItem(self, plugin, active)
+ item = BasicPluginView.listItem(self, plugin)
groups = plugin.settings
keys = groups.keys()
keys.sort()
@@ -484,14 +479,13 @@ class CategoryView(BasicPluginView):
@return None
"""
- active = self.context.active
seen = []
for category in self.context.categories[::-1]:
- plugins = [p for p in category.plugins[::-1] if p.Name in active]
+ plugins = [p for p in category.plugins[::-1] if p.Enabled]
if not category.Name:
## general plugin(s)
for plugin in category.plugins:
- if plugin.Name in active:
+ if plugin.Enabled:
item = self.pluginItem(plugin, self)
seen.append(item)
else:
@@ -499,7 +493,7 @@ class CategoryView(BasicPluginView):
catitem.setVisible(bool(plugins))
seen.append(catitem)
for plugin in plugins:
- if plugin.Name in active:
+ if plugin.Enabled:
item = self.pluginItem(plugin, catitem)
seen.append(item)
for item in self:
diff --git a/kberylsettings/settingwidget.py b/kberylsettings/settingwidget.py
index be641ea..bb114e2 100644
--- a/kberylsettings/settingwidget.py
+++ b/kberylsettings/settingwidget.py
@@ -340,26 +340,7 @@ class SpecificNames(SettingWidget):
return (self.combo, Signals.activatedIndex,
self.comboIndex, self.comboIndexReset)
- noActiveText = ('Active Plugins should not be edited directly.\n'
- 'Use the Plugin dialog from the Settings menu instead.')
-
- def _active_plugins(self, parent, plugin, setting):
- """ creates a non-editable widget for the Active Plugin setting
- @param parent parent object of this widget
- @param plugin berylsettings Plugin instance
- @param setting better be a icon_corner setting instance
- @return four-item tuple of (widget, signal, valuemethod, resetmethod)
- """
- layout = QVBoxLayout(self)
- self.groupBox = GroupBox(1, Qt.Vertical, setting.ShortDesc, self, 10, 10)
- self.groupBox.setFlat(False)
- layout.addWidget(self.groupBox)
- self.noActiveLabel = QLabel(self.noActiveText, self.groupBox)
- self.setFromValue = self.setDefault = self.noOp
- return (None, None, self.noOp, self.noOp)
-
-
class MatchNames(SettingWidget):
""" Setting widget for settings with matching names.