summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornatural <natural>2006-12-31 10:53:36 +0000
committernatural <natural>2006-12-31 10:53:36 +0000
commitdd5381035a8a341b87d3836ea3e454eb999e9223 (patch)
treed627fc6604e93a85e9c4fd3d5542c0b25fbc3a21
parente7ae2a8a5f3bcf1669e1a7514540c451cafbc9b6 (diff)
downloadkberylsettings-dd5381035a8a341b87d3836ea3e454eb999e9223.tar.gz
kberylsettings-dd5381035a8a341b87d3836ea3e454eb999e9223.tar.bz2
Cleaned up attributed list view items.
-rw-r--r--kberylsettings/pluginframe.py185
1 files changed, 84 insertions, 101 deletions
diff --git a/kberylsettings/pluginframe.py b/kberylsettings/pluginframe.py
index 5772cca..fbfe3c7 100644
--- a/kberylsettings/pluginframe.py
+++ b/kberylsettings/pluginframe.py
@@ -6,7 +6,7 @@ and search view.
"""
from re import sub
-from qt import QLabel
+from qt import QLabel, QListViewItem
from kdecore import KIcon, i18n
from kberylsettings.beryl import Setting
@@ -189,17 +189,12 @@ class BasicPluginView(BasicListView):
@param setting any object
@return None
"""
- def match(a, b):
- try:
- return a.value[0].Name == b[0].Name and a.value[1] == b[1]
- except:
- try:
- return a.value[1].Name == b[0].Name and a.value[0] == b[1]
- except:
- pass
- other = (plugin, setting)
+ def match(a):
+ return a.plugin and \
+ a.plugin.Name == plugin.Name and \
+ a.setting == setting
for item in self:
- if match(item, other):
+ if match(item):
self.setCurrentEnsureVisible(item)
if activate:
self.onItemClick(item)
@@ -223,13 +218,12 @@ class BasicPluginView(BasicListView):
"""
item = None
for i in self:
- p, s = i.value
- if p and p.Name == plugin.Name and s is None:
+ if i.plugin and i.plugin.Name == plugin.Name and not i.setting:
item = i
break
if not item:
- item = ValueListViewItem(self, plugin.ShortDesc, (None, None))
- item.value = (plugin, None)
+ item = ViewItem(self, plugin.ShortDesc)
+ item.plugin = plugin
item.setVisible(plugin.Name in active)
item.setPixmap(0, plugin.icon(self.iconSize, self.loader))
return item
@@ -250,8 +244,7 @@ class BasicPluginView(BasicListView):
@return None
"""
for item in self:
- p, s = item.value
- if p == plugin and s is None:
+ if item.plugin == plugin and not item.setting:
item.setVisible(enable)
def setCurrentEnsureVisible(self, item):
@@ -283,11 +276,10 @@ class IconView(BasicPluginView):
"""
self.iconSize = size
for item in self:
- plugin, setting = item.value
- if setting or not plugin:
- item.setPixmap(0, Setting.icon(setting, size))
+ if item.setting or not item.plugin:
+ item.setPixmap(0, Setting.icon(item.setting, size))
else:
- item.setPixmap(0, plugin.icon(size, self.loader))
+ item.setPixmap(0, item.plugin.icon(size, self.loader))
def onItemClick(self, item):
""" emit a signal if a plugin item is selected
@@ -297,14 +289,13 @@ class IconView(BasicPluginView):
"""
if not item:
return
- plugin, setting = item.value
- if plugin and not setting:
- self.showSettingItems(plugin)
- self.emit(Signals.showAbout, (self.context, plugin, ))
+ if item.plugin and not item.setting:
+ self.showSettingItems(item.plugin)
+ self.emit(Signals.showAbout, (self.context, item.plugin, ))
elif item == self.firstChild():
self.showPlugins()
else:
- self.emit(Signals.showSettings, (plugin, setting))
+ self.emit(Signals.showSettings, (item.plugin, item.setting))
self.emit(Signals.selectItem, (item, ))
def showPlugins(self):
@@ -314,8 +305,7 @@ class IconView(BasicPluginView):
"""
active = self.context.active
for item in self:
- plugin, setting = item.value
- if plugin and plugin.Name in active and not setting:
+ if item.plugin and item.plugin.Name in active and not item.setting:
item.setVisible(True)
else:
item.setVisible(False)
@@ -323,11 +313,11 @@ class IconView(BasicPluginView):
def backItem(self):
""" locates or creates the 'Back' item
- @return ValueListViewItem instance
+ @return ViewItem instance
"""
back = self.findItem(i18n('Back'), 0)
if back is None:
- back = ValueListViewItem(self, i18n('Back'), (None, None))
+ back = ViewItem(self, i18n('Back'))
back.setPixmap(0, icon('back', size=self.iconSize))
return back
@@ -343,11 +333,12 @@ class IconView(BasicPluginView):
back.setVisible(True)
settings = []
for item in self:
- p, s = item.value
+ p, s = item.plugin, item.setting
if p and s:
if s in keys:
item.setVisible(True)
- item.value = (plugin, s)
+ item.plugin = plugin
+ item.setting = s
settings.append(s)
else:
item.setVisible(False)
@@ -355,34 +346,29 @@ class IconView(BasicPluginView):
item.setVisible(False)
for key in keys[::-1]:
if key not in settings:
- sub = ValueListViewItem(self, key, (plugin, key))
+ sub = ViewItem(self, key, plugin=plugin, setting=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
+ @param other ViewItem 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
+ if other.plugin and other.setting:
+ self.showSettingItems(other.plugin)
+ for i in self:
+ if i.plugin and \
+ i.plugin.Name == other.plugin.Name and \
+ i.setting == other.setting:
+ self.setCurrentEnsureVisible(i)
+ break
+ elif other.plugin:
self.showPlugins()
- for item in self:
- p, s = item.value
- if p == plugin:
- self.setCurrentEnsureVisible(item)
- break
+ for i in self:
+ if i.plugin and i.plugin.Name == other.plugin.Name:
+ self.setCurrentEnsureVisible(i)
class TreeView(BasicPluginView):
@@ -412,7 +398,7 @@ class TreeView(BasicPluginView):
item.takeItem(child)
child = item.firstChild()
for key in keys[::-1]:
- sub = ValueListViewItem(item, key, (plugin, key))
+ sub = ViewItem(item, key, plugin=plugin, setting=key)
sub.setPixmap(0, Setting.icon(key, self.iconSize))
return item
@@ -424,7 +410,7 @@ class TreeView(BasicPluginView):
"""
if not item:
return
- plugin, setting = item.value
+ plugin, setting = item.plugin, item.setting
if plugin and setting:
self.emit(Signals.showSettings, (plugin, setting))
else:
@@ -434,35 +420,24 @@ class TreeView(BasicPluginView):
def otherSelected(self, other):
""" set current item when other item is selected elsewhere
- @param other ValueListViewItem instance
+ @param other ViewItem 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)
+ if other.category:
+ for i in self:
+ if i.plugin == other.plugin and not i.setting:
+ self.setCurrentEnsureVisible(i)
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)
+ elif other.plugin and not other.setting:
+ for i in self:
+ if i.plugin == other.plugin and not i.setting:
+ self.setCurrentEnsureVisible(i)
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)
+ elif other.plugin and other.setting:
+ for i in self:
+ if i.plugin == other.plugin and i.setting == other.setting:
+ i.parent().setOpen(True)
+ self.setCurrentEnsureVisible(i)
break
@@ -485,12 +460,11 @@ class CategoryView(BasicPluginView):
@return None
"""
self.iconSize = size
- for item in self:
- category, plugin = item.value
- if category:
- item.setPixmap(0, category.icon(size))
- elif plugin:
- item.setPixmap(0, plugin.icon(size, self.loader))
+ for i in self:
+ if i.category:
+ i.setPixmap(0, i.category.icon(size))
+ elif i.plugin:
+ i.setPixmap(0, i.plugin.icon(size, self.loader))
def onItemClick(self, item):
""" emit appropriate signal when plugin or category selected
@@ -500,9 +474,8 @@ class CategoryView(BasicPluginView):
"""
if not item:
return
- category, plugin = item.value
- if plugin:
- self.emit(Signals.showGroups, (plugin, ))
+ if item.plugin:
+ self.emit(Signals.showGroups, (item.plugin, ))
self.emit(Signals.selectItem, (item, ))
def addItems(self):
@@ -544,7 +517,7 @@ class CategoryView(BasicPluginView):
desc = category.ShortDesc
item = self.findItem(desc, 0)
if not item:
- item = CategoryListViewItem(self, desc, (category, None))
+ item = CategoryViewItem(self, desc, category=category)
item.setPixmap(0, category.icon(self.iconSize))
return item
@@ -555,32 +528,43 @@ class CategoryView(BasicPluginView):
@return QListViewItem instance
"""
for item in [i for i in self if i.parent() in (parent, 0)]:
- if item.value[1].Name == plugin.Name:
- item.value = (None, plugin)
+ if item.plugin.Name == plugin.Name:
+ item.plugin = plugin
return item
if parent is self:
item = self.findItem(plugin.ShortDesc, 0)
if item:
- item.value = (None, plugin)
+ item.plugin = plugin
return item
- item = CategoryListViewItem(parent, plugin.ShortDesc, (None, plugin))
+ item = CategoryViewItem(parent, plugin.ShortDesc, plugin=plugin)
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
+ @param other ViewItem instance
@return None
"""
- for item in self:
- if item.value[1] == other.value[0] and item.parent():
- item.parent().setOpen(True)
- self.setCurrentEnsureVisible(item)
+ for i in self:
+ if i.plugin and i.plugin == other.plugin and i.parent():
+ i.parent().setOpen(True)
+ self.setCurrentEnsureVisible(i)
break
-
-class CategoryListViewItem(ValueListViewItem):
+
+class ViewItem(QListViewItem):
+ """ ViewItem -> QListViewItem with attributes common to local view classes
+
+ """
+ def __init__(self, parent, text, category=None, plugin=None, setting=None):
+ QListViewItem.__init__(self, parent, text)
+ self.category = category
+ self.plugin = plugin
+ self.setting = setting
+
+
+class CategoryViewItem(ViewItem):
""" Sortable items for the category list view
"""
@@ -593,7 +577,6 @@ class CategoryListViewItem(ValueListViewItem):
@return -1 if this item is less than other, 1 if greater, 0 if equal
"""
for (obj, val) in ((self, -1), (other, 1)):
- plugin = obj.value[1]
- if plugin and plugin.isGeneral:
+ if obj.plugin and obj.plugin.isGeneral:
return val
return cmp(self.text(0), other.text(0))