Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 13 May 2007 23:05:27 GMT
From:      Ivan Voras <ivoras@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 119803 for review
Message-ID:  <200705132305.l4DN5R6m097449@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=119803

Change 119803 by ivoras@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()



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200705132305.l4DN5R6m097449>