[meld] ui.gnomeglade: Clean up the docs and sundry
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] ui.gnomeglade: Clean up the docs and sundry
- Date: Fri, 27 Sep 2013 22:06:57 +0000 (UTC)
commit 661a5c395bab696016778b88124b0601749e3800
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sat Sep 7 17:46:21 2013 +1000
ui.gnomeglade: Clean up the docs and sundry
meld/ui/gnomeglade.py | 44 +++++++++++++++++++-------------------------
1 files changed, 19 insertions(+), 25 deletions(-)
---
diff --git a/meld/ui/gnomeglade.py b/meld/ui/gnomeglade.py
index 1b51e69..4be95ac 100644
--- a/meld/ui/gnomeglade.py
+++ b/meld/ui/gnomeglade.py
@@ -1,5 +1,5 @@
### Copyright (C) 2002-2008 Stephen Kennedy <stevek gnome org>
-### Copyright (C) 2010 Kai Willadsen <kai willadsen gmail com>
+### Copyright (C) 2010, 2013 Kai Willadsen <kai willadsen gmail com>
### This program is free software; you can redistribute it and/or modify
### it under the terms of the GNU General Public License as published by
@@ -18,28 +18,26 @@
import gtk
+# Import support module to get all builder-constructed widgets in the namespace
+from meld.ui import gladesupport
# FIXME: duplicate defn in bin/meld
locale_domain = "meld"
class Component(object):
- """Base class for all glade objects.
+ """Base class for all gtk.Builder created objects
- This class handles loading the xml glade file and autoconnects
- all signals in the glade file.
+ This class loads the UI file, autoconnects signals, and makes
+ widgets available as attributes. The toplevel widget is stored as
+ 'self.widget'.
- The handle to the xml file is stored in 'self.xml'. The
- toplevel widget is stored in 'self.widget'.
-
- In addition it calls widget.set_data("pyobject", self) - this
- allows us to get the python object given only the 'raw' gtk+
- object, which is sadly sometimes necessary.
+ The python object can be accessed from the widget itself via
+ widget.get_data("pygobject"), which is sadly sometimes necessary.
"""
def __init__(self, filename, root, extra=None):
- """Load the widgets from the node 'root' in file 'filename'.
- """
+ """Load the widgets from the node 'root' in file 'filename'"""
self.builder = gtk.Builder()
self.builder.set_translation_domain(locale_domain)
objects = [root] + extra if extra else [root]
@@ -49,32 +47,28 @@ class Component(object):
self.widget.set_data("pyobject", self)
def __getattr__(self, key):
- """Allow glade widgets to be accessed as self.widgetname.
- """
+ """Allow UI builder widgets to be accessed as self.widgetname"""
widget = self.builder.get_object(key)
- if widget: # cache lookups
+ if widget:
setattr(self, key, widget)
return widget
raise AttributeError(key)
def map_widgets_into_lists(self, widgetnames):
"""Put sequentially numbered widgets into lists.
-
- e.g. If an object had widgets self.button0, self.button1, ...,
- then after a call to object._map_widgets_into_lists(["button"])
- object has an attribute self.button == [self.button0, self.button1, ...]."
+
+ Given an object with widgets self.button0, self.button1, ...,
+ after a call to object.map_widgets_into_lists(["button"])
+ object.button == [self.button0, self.button1, ...]
"""
for item in widgetnames:
- setattr(self,item, [])
- lst = getattr(self,item)
- i = 0
+ i, lst = 0, []
while 1:
- key = "%s%i"%(item,i)
+ key = "%s%i" % (item, i)
try:
val = getattr(self, key)
except AttributeError:
break
lst.append(val)
i += 1
-
-from . import gladesupport
+ setattr(self, item, lst)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]