PERFORCE change 119803 for review

Ivan Voras ivoras at FreeBSD.org
Sun May 13 23:05:28 UTC 2007


http://perforce.freebsd.org/chv.cgi?CH=119803

Change 119803 by ivoras at ivoras_finstall on 2007/05/13 23:04:27

	Generalize signal binding

Affected files ...

.. //depot/projects/soc2007/ivoras_finstall/installer/finstall.py#2 edit

Differences ...

==== //depot/projects/soc2007/ivoras_finstall/installer/finstall.py#2 (text+ko) ====

@@ -1,21 +1,41 @@
+from types import MethodType
 import gtk, gtk.gdk, gtk.glade
 
+
 class MainWin:
 	def __init__(self):
 		self.xml = gtk.glade.XML("glade/mainwin.glade")
 		self.window = self.xml.get_widget("mainwin")
-		#self.xml.signal_autoconnect({"on_button_next_clicked" : self.on_button_next_clicked })
-		self.xml.signal_autoconnect(self)
+		self.xml.signal_autoconnect(self._get_event_handlers())
 		self["img_logo"].set_from_file("img/logo.jpg")
-		self._center_window(self.window)
+		# img_logo stretches the window vertically, so calling window.set_position() has no affect
+		self._center_window(self.window) 
+
 
 	def __getitem__(self,key):
+		"""Make convenient shortcut to window widgets."""
 		return self.xml.get_widget(key)
 
+
 	def _center_window(self, window):
+		"""Centers window on screen """
 		ws = window.get_size()
 		window.move((gtk.gdk.screen_width() - ws[0]) / 2, (gtk.gdk.screen_height() - ws[1]) / 2)
 
+
+	def _get_event_handlers(self):
+		"""Returns a dictionary of form {'on_method' : self.on_method} for all
+		methods of self begining with "on_". This is useful for binding signal
+		handlers."""
+		dict = {}
+		for name in dir(self):
+			if not name.startswith("on_"):
+				continue
+			attr = getattr(self, name)
+			if isinstance(attr, MethodType):
+				dict[name] = attr
+		return dict
+
 	def on_button_next_clicked(self, obj):
 		print "clicked!", obj
 		gtk.main_quit()


More information about the p4-projects mailing list