diff options
author | natural <natural> | 2006-12-30 01:13:17 +0000 |
---|---|---|
committer | natural <natural> | 2006-12-30 01:13:17 +0000 |
commit | d5c0b65e73186b30cdf2ab7e5ebf72cddc852a2a (patch) | |
tree | dc633f900d07b02ca6be8cb9dd6e7f8f8f303d74 /kberylsettings | |
parent | 7a42e6fc0a031c905b045564609ca5a4317cfe07 (diff) | |
download | kberylsettings-d5c0b65e73186b30cdf2ab7e5ebf72cddc852a2a.tar.gz kberylsettings-d5c0b65e73186b30cdf2ab7e5ebf72cddc852a2a.tar.bz2 |
Sync plugin lists on view mode change.
More docstrings.
Diffstat (limited to 'kberylsettings')
-rw-r--r-- | kberylsettings/lib.py | 1 | ||||
-rw-r--r-- | kberylsettings/pluginframe.py | 133 |
2 files changed, 125 insertions, 9 deletions
diff --git a/kberylsettings/lib.py b/kberylsettings/lib.py index 44dbbab..2251e51 100644 --- a/kberylsettings/lib.py +++ b/kberylsettings/lib.py @@ -52,6 +52,7 @@ class Signals: okClicked = SIGNAL('okClicked()') quitSelected = SIGNAL("quitSelected()") searchInput = PYSIGNAL('searchInput') + selectItem = PYSIGNAL('selectItem') selectPrevious = PYSIGNAL('selectPrevious') showAbout = PYSIGNAL('showAbout') showGroups = PYSIGNAL('showGroups') diff --git a/kberylsettings/pluginframe.py b/kberylsettings/pluginframe.py index 5ede875..5a0095d 100644 --- a/kberylsettings/pluginframe.py +++ b/kberylsettings/pluginframe.py @@ -29,6 +29,11 @@ class PluginFrame(WidgetStack): ## entry selectable by the user. (categoryPageId, '&Category View') ) + relatedModes = { + iconPageId : (treePageId, categoryPageId), + treePageId : (iconPageId, categoryPageId), + categoryPageId : (iconPageId, treePageId), + } def __init__(self, parent): WidgetStack.__init__(self, parent) @@ -40,6 +45,12 @@ class PluginFrame(WidgetStack): connect = self.connect root = self.topLevelWidget() connect(root, Signals.viewModeChanged, self.raiseWidget) + + for pageId, others in self.relatedModes.items(): + for otherId in others: + connect(pages[pageId], Signals.selectItem, + pages[otherId].otherSelected) + for page in pages: connect(page, Signals.berylSettingChanged, root.onContextChanged) connect(page, Signals.showAbout, root, Signals.showAbout) @@ -172,11 +183,17 @@ class BasicPluginView(BasicListView): self.connect(self, Signals.itemClicked, self.onItemClick) def selectPluginItem(self, plugin, setting): + """ locate and set current item given plugin and setting + + @param plugin beryl settings Plugin object + @param setting any object + @return None + """ match = (plugin, setting) for item in self: if item.value == match: - self.setCurrentItem(item) - return + self.setCurrentEnsureVisible(item) + break def addItems(self): """ adds list view items for every plugin in context @@ -227,6 +244,15 @@ class BasicPluginView(BasicListView): if p == plugin and s is None: item.setVisible(enable) + def setCurrentEnsureVisible(self, item): + """ set current item and ensure it's visible + + @param QListViewItem instance + @return None + """ + self.setCurrentItem(item) + self.ensureItemVisible(item) + class IconView(BasicPluginView): """ IconView -> icon list view of plugins @@ -269,8 +295,13 @@ class IconView(BasicPluginView): self.showPlugins() else: self.emit(Signals.showSettings, (plugin, setting)) + self.emit(Signals.selectItem, (item, )) def showPlugins(self): + """ sets all active plugin items visible + + @return None + """ active = self.context.active for item in self: plugin, setting = item.value @@ -280,6 +311,10 @@ class IconView(BasicPluginView): item.setVisible(False) def backItem(self): + """ locates or creates the 'Back' item + + @return ValueListViewItem instance + """ back = self.findItem(i18n('Back'), 0) if back is None: back = ValueListViewItem(self, i18n('Back'), (None, None)) @@ -287,12 +322,15 @@ class IconView(BasicPluginView): return back def showSettingItems(self, plugin): + """ displays setting icons for given plugin + + @param plugin beryl settings Plugin object + @return None + """ keys = plugin.settings.keys() keys.sort() - back = self.backItem() back.setVisible(True) - settings = [] for item in self: p, s = item.value @@ -305,13 +343,37 @@ class IconView(BasicPluginView): item.setVisible(False) elif p and not s: item.setVisible(False) - for key in keys[::-1]: if key not in settings: sub = ValueListViewItem(self, key, (plugin, key)) sub.setPixmap(0, Setting.icon(key, self.iconSize)) sub.moveItem(back) + def otherSelected(self, other): + """ set current item when other item is selected elsewhere + + @param other ValueListViewItem instance + @return None + """ + a, b = other.value + if a and b: + plugin = a + setting = b + self.showSettingItems(plugin) + for item in self: + p, s = item.value + if p == plugin and s == setting: + self.setCurrentEnsureVisible(item) + break + elif a is None and b: + plugin = b + self.showPlugins() + for item in self: + p, s = item.value + if p == plugin: + self.setCurrentEnsureVisible(item) + break + class TreeView(BasicPluginView): """ TreeView -> tree list view of plugins @@ -357,7 +419,42 @@ class TreeView(BasicPluginView): self.emit(Signals.showSettings, (plugin, setting)) else: self.emit(Signals.showAbout, (plugin, )) + self.emit(Signals.selectItem, (item, )) + def otherSelected(self, other): + """ set current item when other item is selected elsewhere + + @param other ValueListViewItem instance + @return None + """ + a, b = other.value + if a is None and b: + # category + plugin = b + for item in self: + p, s = item.value + if p == plugin and s is None: + self.setCurrentEnsureVisible(item) + break + elif a and b is None: + # plugin + plugin = a + for item in self: + p, s = item.value + if p == plugin and s is None: + self.setCurrentEnsureVisible(item) + break + elif a and b: + # plugin + setting + plugin = a + setting = b + for item in self: + p, s = item.value + if p == plugin and s == setting: + item.parent().setOpen(True) + self.setCurrentEnsureVisible(item) + break + class CategoryView(BasicPluginView): """ CategoryView -> tree list view of plugins by category @@ -396,27 +493,34 @@ class CategoryView(BasicPluginView): category, plugin = item.value if plugin: self.emit(Signals.showGroups, (plugin, )) + self.emit(Signals.selectItem, (item, )) def addItems(self): """ adds list view items for each category and plugin in context @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] if not category.Name: ## general plugin(s) for plugin in category.plugins: if plugin.Name in active: - self.pluginItem(plugin, self) + item = self.pluginItem(plugin, self) + seen.append(item) else: catitem = self.categoryItem(category) catitem.setVisible(bool(plugins)) + seen.append(catitem) for plugin in plugins: if plugin.Name in active: - self.pluginItem(plugin, catitem) + item = self.pluginItem(plugin, catitem) + seen.append(item) + for item in self: + if item.isVisible(): + item.setVisible(item in seen) self.setSorting(1) self.sort() self.setSorting(-1) @@ -453,6 +557,18 @@ class CategoryView(BasicPluginView): item.setPixmap(0, plugin.icon(self.iconSize, self.loader)) return item + def otherSelected(self, other): + """ set current item when other item is selected elsewhere + + @param other ValueListViewItem instance + @return None + """ + for item in self: + if item.value[1] == other.value[0] and item.parent(): + item.parent().setOpen(True) + self.setCurrentEnsureVisible(item) + break + class CategoryListViewItem(ValueListViewItem): """ Sortable items for the category list view @@ -471,4 +587,3 @@ class CategoryListViewItem(ValueListViewItem): if plugin and plugin.isGeneral: return val return cmp(self.text(0), other.text(0)) - |