From owner-p4-projects@FreeBSD.ORG Sun May 13 23:05:28 2007 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 4B77016A40A; Sun, 13 May 2007 23:05:28 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 050EB16A408 for ; Sun, 13 May 2007 23:05:28 +0000 (UTC) (envelope-from ivoras@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id E97F913C455 for ; Sun, 13 May 2007 23:05:27 +0000 (UTC) (envelope-from ivoras@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.8/8.13.8) with ESMTP id l4DN5Rgj097452 for ; Sun, 13 May 2007 23:05:27 GMT (envelope-from ivoras@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.8/8.13.8/Submit) id l4DN5R6m097449 for perforce@freebsd.org; Sun, 13 May 2007 23:05:27 GMT (envelope-from ivoras@FreeBSD.org) Date: Sun, 13 May 2007 23:05:27 GMT Message-Id: <200705132305.l4DN5R6m097449@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to ivoras@FreeBSD.org using -f From: Ivan Voras To: Perforce Change Reviews Cc: Subject: PERFORCE change 119803 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 May 2007 23:05:28 -0000 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()