summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Niklaus <marex@compiz-fusion.org>2011-02-12 18:37:09 +0100
committerPatrick Niklaus <marex@compiz-fusion.org>2011-02-12 18:37:09 +0100
commit690bf9be1d70a4751eaf53216b2e785d529b1986 (patch)
tree35c1bdf9c419e9fdb9cfce03e8dc322d9eaa91b7
parent3400d3c836a88b7806eea79e4f6011bef3cff87b (diff)
downloadccsm-690bf9be1d70a4751eaf53216b2e785d529b1986.tar.gz
ccsm-690bf9be1d70a4751eaf53216b2e785d529b1986.tar.bz2
Python 3 syntax and minor cleanup
Removed functions that are deprecated in python 3.x, renamed variables to not overwrite buildin functions, removed libsexy code and some other minor cleanups.
-rw-r--r--ccm/Conflicts.py3
-rw-r--r--ccm/Pages.py76
-rw-r--r--ccm/Settings.py64
-rw-r--r--ccm/Utils.py12
-rw-r--r--ccm/Widgets.py28
-rwxr-xr-xccsm17
6 files changed, 94 insertions, 106 deletions
diff --git a/ccm/Conflicts.py b/ccm/Conflicts.py
index abe3a40..2b08ba8 100644
--- a/ccm/Conflicts.py
+++ b/ccm/Conflicts.py
@@ -85,7 +85,8 @@ class ActionConflict (Conflict):
# actions from the same plugin. If it is global, include all actions.
if not settings:
- for plugin in self.Setting.Plugin.Context.Plugins.values ():
+ for n in self.Setting.Plugin.Context.Plugins:
+ plugin = self.Setting.Plugin.Context.Plugins[n]
if plugin.Enabled:
pluginActions = GetSettings(plugin, types=self.ActionTypes)
diff --git a/ccm/Pages.py b/ccm/Pages.py
index 3689d7c..ff7ef54 100644
--- a/ccm/Pages.py
+++ b/ccm/Pages.py
@@ -76,11 +76,7 @@ class PluginPage(GenericPage):
filterLabel = Label()
filterLabel.set_markup(HeaderMarkup % (_("Filter")))
filterLabel.connect("style-set", self.HeaderStyleSet)
- if has_sexy:
- self.FilterEntry = sexy.IconEntry()
- self.FilterEntry.add_clear_button()
- else:
- self.FilterEntry = gtk.Entry()
+ self.FilterEntry = gtk.Entry()
self.FilterEntry.connect("changed", self.FilterChanged)
self.LeftWidget.pack_start(pluginImg, False, False)
@@ -259,16 +255,16 @@ class FilterPage(GenericPage):
self.LeftWidget.pack_start(filterImg, False, False)
self.LeftWidget.pack_start(filterLabel, False, False)
- # Entry
- if has_sexy:
- self.FilterEntry = sexy.IconEntry()
- self.FilterEntry.add_clear_button()
- keyboardImage = Image("input-keyboard", ImageThemed, 16)
- self.FilterEntry.set_icon(sexy.ICON_ENTRY_PRIMARY, keyboardImage)
- self.FilterEntry.set_icon_highlight(sexy.ICON_ENTRY_PRIMARY, True)
- self.FilterEntry.connect('icon-pressed', self.GrabKey)
- else:
- self.FilterEntry = gtk.Entry()
+ # Entry FIXME find a solution with std gtk
+ """
+ self.FilterEntry = sexy.IconEntry()
+ self.FilterEntry.add_clear_button()
+ keyboardImage = Image("input-keyboard", ImageThemed, 16)
+ self.FilterEntry.set_icon(sexy.ICON_ENTRY_PRIMARY, keyboardImage)
+ self.FilterEntry.set_icon_highlight(sexy.ICON_ENTRY_PRIMARY, True)
+ self.FilterEntry.connect('icon-pressed', self.GrabKey)
+ """
+ self.FilterEntry = gtk.Entry()
self.FilterEntry.set_tooltip_text(_("Enter a filter.\nClick the keyboard image to grab a key for which to search."))
self.FilterEntry.connect("changed", self.FilterChanged)
@@ -386,17 +382,17 @@ class FilterPage(GenericPage):
length = len(context.Plugins)
- for index, (plugin, Plugin) in enumerate(context.Plugins.items()):
-
+ for index, n in enumerate(context.Plugins):
+ plugin = context.Plugins[n]
bar.set_fraction((index+1)/float(length))
- label.set_markup("<i>%s</i>" %protect_pango_markup(Plugin.ShortDesc))
+ label.set_markup("<i>%s</i>" %protect_pango_markup(plugin.ShortDesc))
gtk_process_events()
groups = []
- sortedGroups = sorted(Plugin.Groups.items(), key=GroupIndexKeyFunc)
+ sortedGroups = sorted(plugin.Groups.items(), key=GroupIndexKeyFunc)
for (name, (groupIndex, group)) in sortedGroups:
groups.append((name, GroupPage(name or _('General'), group)))
- self.GroupPages[plugin] = groups
+ self.GroupPages[n] = groups
self.Level = FilterName | FilterLongDesc
@@ -420,7 +416,8 @@ class FilterPage(GenericPage):
def Filter(self, text, level=FilterAll):
text = text.lower()
- for plugin, groups in self.GroupPages.items():
+ for plugin in self.GroupPages:
+ groups = self.GroupPages[plugin]
results = dict((n, sg) for (n, sg) in groups if sg.Filter(text, level=level))
if results:
yield plugin, results
@@ -437,15 +434,16 @@ class FilterPage(GenericPage):
self.FilterValueCheck.set_active(True)
self.FilterEntry.set_text(new)
+ # FIXME find a way to reuse this function
+ """
def GrabKey(self, widget, pos, button):
- if not has_sexy or pos != sexy.ICON_ENTRY_PRIMARY:
- return
grabber = KeyGrabber(label = _("Grab key combination"))
self.LeftWidget.pack_start(grabber, False, False)
grabber.hide()
grabber.set_no_show_all(True)
grabber.connect('changed', self.GotKey)
grabber.begin_key_grab(None)
+ """
def ShowFilterError(self, text):
@@ -675,16 +673,15 @@ class ProfileBackendPage(object):
self.ProfileComboBox = gtk.combo_box_new_text()
self.ProfileComboBox.set_sensitive(self.Context.CurrentBackend.ProfileSupport)
self.ProfileComboBox.append_text(_("Default"))
- for profile in self.Context.Profiles.values():
+ active = -1
+ for i, name in enumerate(self.Context.Profiles):
+ profile = self.Context.Profiles[name]
self.ProfileComboBox.append_text(profile.Name)
+ if name == self.Context.CurrentProfile.Name:
+ active = i
self.ProfileHandler = self.ProfileComboBox.connect("changed",
self.ProfileChangedAddTimeout)
- name = self.Context.CurrentProfile.Name
- if name in self.Context.Profiles:
- index = self.Context.Profiles.values().index(self.Context.Profiles[name])
- self.ProfileComboBox.set_active(index+1)
- else:
- self.ProfileComboBox.set_active(0)
+ self.ProfileComboBox.set_active(active+1)
profileAdd.connect("clicked", self.AddProfile)
profileRemove.connect("clicked", self.RemoveProfile)
profileBox.pack_start(self.ProfileComboBox, True, True)
@@ -721,11 +718,13 @@ class ProfileBackendPage(object):
# Backends
backendBox = gtk.combo_box_new_text()
- for backend in self.Context.Backends.values():
+ active = 0
+ for i, name in enumerate(self.Context.Backends):
+ backend = self.Context.Backends[name]
backendBox.append_text(backend.ShortDesc)
- name = self.Context.CurrentBackend.Name
- index = self.Context.Backends.values().index(self.Context.Backends[name])
- backendBox.set_active(index)
+ if name == self.CurrentBackend.Name:
+ active = i
+ backendBox.set_active(active)
backendBox.connect("changed", self.BackendChangedAddTimeout)
backendLabel = Label()
backendLabel.set_markup(HeaderMarkup % (_("Backend")))
@@ -812,7 +811,6 @@ class ProfileBackendPage(object):
chooser.add_filter(filter)
def ResetProfile(self, widget):
-
for plugin in self.Context.Plugins.values():
settings = GetSettings(plugin)
for setting in settings:
@@ -924,7 +922,7 @@ class ProfileBackendPage(object):
self.Context.CurrentBackend = self.Context.Backends[name]
self.UpdateProfiles()
else:
- raise Exception, _("Backend not found.")
+ raise Exception(_("Backend not found."))
self.ProfileComboBox.set_sensitive(self.Context.CurrentBackend.ProfileSupport)
self.IntegrationButton.set_sensitive(self.Context.CurrentBackend.IntegrationSupport)
@@ -1193,11 +1191,7 @@ class MainPage(object):
filterLabel.set_markup(HeaderMarkup % (_("Filter")))
filterLabel.connect("style-set", self.HeaderStyleSet)
filterLabel.props.xalign = 0.1
- if has_sexy:
- filterEntry = sexy.IconEntry()
- filterEntry.add_clear_button()
- else:
- filterEntry = gtk.Entry()
+ filterEntry = gtk.Entry()
filterEntry.set_tooltip_text(_("Filter your Plugin list"))
filterEntry.connect("changed", self.FilterChanged)
self.filterEntry = filterEntry
diff --git a/ccm/Settings.py b/ccm/Settings.py
index 619b1f5..787461f 100644
--- a/ccm/Settings.py
+++ b/ccm/Settings.py
@@ -94,7 +94,7 @@ class Setting(object):
'class': self}
value = message % msg_dict
- raise PureVirtualError, value
+ raise PureVirtualError(value)
def _Init(self):
self.PureVirtual('_Init')
@@ -367,11 +367,11 @@ class RestrictedStringSetting(StockSetting):
# if current value is not provided by any restricted string extension,
# insert an N/A item at the beginning
- if not self.ItemsByValue.has_key(self.OriginalValue):
+ if self.OriginalValue not in self.ItemsByValue:
self.NAItemShift = 1
self.Combo.insert_text(0, NAItemText)
- if self.ItemsByValue.has_key(value):
+ if value in self.ItemsByValue:
self.Combo.set_active(self.ItemsByValue[self.Get()][1] + \
self.NAItemShift)
else:
@@ -621,15 +621,15 @@ class BaseListSetting(Setting):
self.Settings[0].Plugin.Context.Write()
def Delete(self, *args):
- model, iter = self.Select.get_selected()
- if iter is not None:
- path = model.get_path(iter)
+ model, it = self.Select.get_selected()
+ if it is not None:
+ path = model.get_path(it)
if path is not None:
row = path[0]
else:
return
- model.remove(iter)
+ model.remove(it)
self._Delete(row)
@@ -649,9 +649,9 @@ class BaseListSetting(Setting):
return dlg
def Edit(self, widget):
- model, iter = self.Select.get_selected()
- if iter:
- path = model.get_path(iter)
+ model, it = self.Select.get_selected()
+ if it:
+ path = model.get_path(it)
if path is not None:
row = path[0]
else:
@@ -681,9 +681,9 @@ class BaseListSetting(Setting):
self.Read()
def Move(self, widget, direction):
- model, iter = self.Select.get_selected()
- if iter is not None:
- path = model.get_path(iter)
+ model, it = self.Select.get_selected()
+ if it is not None:
+ path = model.get_path(it)
if path is not None:
row = path[0]
else:
@@ -697,7 +697,7 @@ class BaseListSetting(Setting):
self.Settings[0].Plugin.Context.Write()
- order = range(len(model))
+ order = list(range(len(model)))
order.insert(dest, order.pop(row))
model.reorder(order)
@@ -705,13 +705,13 @@ class BaseListSetting(Setting):
def SelectionChanged(self, selection):
- model, iter = selection.get_selected()
+ model, it = selection.get_selected()
for widget in (self.Buttons[gtk.STOCK_EDIT], self.Buttons[gtk.STOCK_DELETE],
self.PopupItems[gtk.STOCK_EDIT], self.PopupItems[gtk.STOCK_DELETE]):
- widget.set_sensitive(iter is not None)
+ widget.set_sensitive(it is not None)
- if iter is not None:
- path = model.get_path(iter)
+ if it is not None:
+ path = model.get_path(it)
if path is not None:
row = path[0]
self.Buttons[gtk.STOCK_GO_UP].set_sensitive(row > 0)
@@ -732,25 +732,25 @@ class BaseListSetting(Setting):
def KeyPressEvent(self, treeview, event):
if gtk.gdk.keyval_name(event.keyval) == "Delete":
- model, iter = treeview.get_selection().get_selected()
- if iter is not None:
- path = model.get_path(iter)
+ model, it = treeview.get_selection().get_selected()
+ if it is not None:
+ path = model.get_path(it)
if path is not None:
row = path[0]
- model.remove(iter)
+ model.remove(it)
self._Delete(row)
return True
def ListInfo(self):
types = []
cols = []
- for i, (setting, widget) in enumerate(zip(self.Settings, self.Widgets)):
- type, col = widget.GetColumn(i)
- types.append(type)
+ for i, widget in enumerate(self.Widgets):
+ t, col = widget.GetColumn(i)
+ types.append(t)
cols.append(col)
return types, cols
- def Activated(self, object, path, col):
+ def Activated(self, obj, path, col):
self._Edit(path[0])
def _Read(self):
@@ -867,7 +867,7 @@ class RestrictedStringFlagsSetting(Setting):
for key, box in self.Checks:
box.set_active(False)
for setVal in self.Setting.Value:
- if self.ItemsByValue.has_key(setVal):
+ if setVal in self.ItemsByValue:
self.Checks[self.ItemsByValue[setVal][1]][1].set_active(True)
def _Changed(self):
@@ -1136,7 +1136,7 @@ class ButtonSetting (EditableActionSetting):
def ReorderButtonString (self, old):
new = ""
- edges = map (lambda e: "%sEdge" % e, Edges)
+ edges = ["%sEdge" % e for e in Edges]
for s in edges + KeyModifier:
if "<%s>" % s in old:
new += "<%s>" % s
@@ -1332,7 +1332,7 @@ class EdgeSetting (EditableActionSetting):
label = self.current
if len (self.current):
edges = self.current.split ("|")
- edges = map (lambda s: _(s), edges)
+ edges = [_(s) for s in edges]
label = ", ".join (edges)
else:
label = _("None")
@@ -1447,11 +1447,11 @@ SettingTypeDict = {
def MakeSetting(setting, List=False):
if List:
- type = setting.Info[0]
+ t = setting.Info[0]
else:
- type = setting.Type
+ t = setting.Type
- stype = SettingTypeDict.get(type, None)
+ stype = SettingTypeDict.get(t, None)
if not stype:
return
diff --git a/ccm/Utils.py b/ccm/Utils.py
index cf62548..2a4f04e 100644
--- a/ccm/Utils.py
+++ b/ccm/Utils.py
@@ -62,7 +62,7 @@ def getDefaultScreen():
return display.get_default_screen().get_number()
def protect_markup_dict (dict_):
- return dict((k, protect_pango_markup (v)) for (k, v) in dict_.iteritems())
+ return dict((k, protect_pango_markup (v)) for (k, v) in dict_.items())
class Image (gtk.Image):
@@ -103,7 +103,7 @@ class Image (gtk.Image):
elif type == ImageStock:
self.set_from_stock (name, size)
- except gobject.GError, e:
+ except gobject.GError as e:
self.set_from_stock (gtk.STOCK_MISSING_IMAGE, gtk.ICON_SIZE_BUTTON)
class ActionImage (gtk.Alignment):
@@ -230,8 +230,8 @@ class IdleSettingsParser:
self.Main = main
self.PluginList = [p for p in self.Context.Plugins.items() if FilterPlugin(p[1])]
nCategories = len (main.MainPage.RightWidget._boxes)
- self.CategoryLoadIconsList = range (3, nCategories) # Skip the first 3
- print 'Loading icons...'
+ self.CategoryLoadIconsList = list(range(3, nCategories)) # Skip the first 3
+ print('Loading icons...')
gobject.timeout_add (150, self.Wait)
@@ -394,9 +394,9 @@ def GetSettings(group, types=None):
yield setting
if types:
- screen = TypeFilter(group.Screen.itervalues(), types)
+ screen = TypeFilter(iter(group.Screen.values()), types)
else:
- screen = group.Screen.itervalues()
+ screen = iter(group.Screen.values())
return screen
diff --git a/ccm/Widgets.py b/ccm/Widgets.py
index ff61628..67eff6f 100644
--- a/ccm/Widgets.py
+++ b/ccm/Widgets.py
@@ -421,7 +421,7 @@ class ModifierSelector (gtk.DrawingArea):
self.redraw (queue = True)
def get_current (self):
- return "|".join (filter (lambda s: len (s) > 0, self._current))
+ return "|".join ([s for s in self._current if len (s) > 0])
current = property (get_current, set_current)
def draw (self, cr, width, height):
@@ -761,7 +761,7 @@ class SingleEdgeSelector (EdgeSelector):
self.redraw (queue = True)
def get_current (self):
- return "|".join (filter (lambda s: len (s) > 0, self._current))
+ return "|".join ([s for s in self._current if len (s) > 0])
current = property (get_current, set_current)
def set_fill_color (self, cr, edge):
@@ -835,7 +835,7 @@ class GlobalEdgeSelector(EdgeSelector):
def filter_settings(plugin):
if plugin.Enabled:
settings = sorted (GetSettings(plugin), key=SettingKeyFunc)
- settings = filter (lambda s: s.Type == 'Edge', settings)
+ settings = [s for s in settings if s.Type == 'Edge']
return settings
return []
@@ -855,13 +855,13 @@ class GlobalEdgeSelector(EdgeSelector):
value = setting.Value.split ("|")
if edge in value:
value.remove(edge)
- value = "|".join (filter (lambda s: len (s) > 0, value))
+ value = "|".join ([s for s in value if len (s) > 0])
setting.Value = value
else:
value = setting.Value.split ("|")
if not edge in value:
value.append (edge)
- value = "|".join (filter (lambda s: len (s) > 0, value))
+ value = "|".join ([s for s in value if len (s) > 0])
conflict = EdgeConflict (setting, value, settings = self._settings, autoResolve = True)
if conflict.Resolve (GlobalUpdater):
@@ -1102,11 +1102,11 @@ class MatchButton(gtk.Button):
value_widget.set_text(value)
- def generate_match (self, type, value, relation, invert):
+ def generate_match (self, t, value, relation, invert):
match = ""
text = self.match
- prefix = self.prefix[type]
+ prefix = self.prefix[t]
symbol = self.symbols[relation]
# check if the current match needs some brackets
@@ -1151,8 +1151,8 @@ class MatchButton(gtk.Button):
# Type
label = Label (_("Type"))
type_chooser = gtk.combo_box_new_text ()
- for type in self.prefix.keys ():
- type_chooser.append_text (type)
+ for t in self.prefix:
+ type_chooser.append_text (t)
type_chooser.set_active (0)
rows.append ((label, type_chooser))
@@ -1171,7 +1171,7 @@ class MatchButton(gtk.Button):
# Relation
label = Label (_("Relation"))
relation_chooser = gtk.combo_box_new_text ()
- for relation in self.symbols.keys ():
+ for relation in self.symbols:
relation_chooser.append_text (relation)
relation_chooser.set_active (0)
rows.append ((label, relation_chooser))
@@ -1194,11 +1194,11 @@ class MatchButton(gtk.Button):
response = dlg.run ()
dlg.hide ()
if response == gtk.RESPONSE_OK:
- type = type_chooser.get_active_text ()
+ t = type_chooser.get_active_text ()
value = entry.get_text ()
relation = relation_chooser.get_active_text ()
invert = check.get_active ()
- self.generate_match (type, value, relation, invert)
+ self.generate_match (t, value, relation, invert)
dlg.destroy ()
@@ -1590,7 +1590,7 @@ class PluginWindow(gtk.ScrolledWindow):
self._categories = {}
self._boxes = []
self._context = context
- pool = plugins or self._context.Plugins.values()
+ pool = plugins or list(self._context.Plugins.values())
if len (categories):
for plugin in pool:
category = plugin.Category
@@ -1690,7 +1690,7 @@ class PluginWindow(gtk.ScrolledWindow):
last_box = box
def get_categories (self):
- return self._categories.keys ()
+ return list(self._categories)
def show_plugin_page (self, widget):
plugin = widget.get_plugin ()
diff --git a/ccsm b/ccsm
index f46be37..a112f2d 100755
--- a/ccsm
+++ b/ccsm
@@ -41,9 +41,9 @@ def try_register_dbus ():
except ImportError:
return
- # rely on a reasonably new dbus-python
- if dbus.version < (0, 80, 0):
- return
+ # rely on a reasonably new dbus-python
+ if dbus.version < (0, 80, 0):
+ return
class CCSMObject(dbus.service.Object):
main_window = None
@@ -78,7 +78,7 @@ def try_register_dbus ():
display = gtk.gdk.display_get_default()
startup_id = gtk.gdk.x11_display_get_startup_notification_id(display)
obj.present(startup_id or "")
- print 'Another CCSM instance already running'
+ print('Another CCSM instance already running')
sys.exit(0)
except dbus.DBusException:
# error on present call so pretend it doesn't exist and start up normally
@@ -86,13 +86,6 @@ def try_register_dbus ():
dbusObj = try_register_dbus()
-try:
- import sexy
- has_sexy = True
-except ImportError:
- print "Info: No sexy-python package found, don't worry it's optional."
- has_sexy = False
-
if gtk.pygtk_version < (2,12,0):
raise SystemExit("PyGtk 2.12.0 or later required")
@@ -115,7 +108,7 @@ parser.add_option("-v", "--version", dest = "version",
help = "Version")
(options, args) = parser.parse_args()
if options.version:
- print "CCSM %s" % Version
+ print("CCSM %s" % Version)
sys.exit(0)
if options.plugin:
plugin = options.plugin