[pygtk] Can somebody explain the libglade OO paradigm?
Hi I'm making a gnome-hello example for my pygtutorial http://laguna.fmedic.unam.mx/~daniel/pygtutorial/ and I'm stuck with the libglade example. I'm trying to do a gnome-hello like the one in my tutorial but with glade. My problem is the following: When I autoconect a handler, the handle is called ONLY with the callback argument and the instance reference isn't passed at all. PLEASE run the unfinished example I attached to see what I mean. Select the menu "help" and clik in "about". The example just instances a GnomeApp with a buton and menus. My problem comes when I want to show a GnomeAbout I made with glade. I try to do this selecting "about" in the "help" menu. Even if I am in the SAME class the "on_about_cb" method can't reference the self.wtree which I need to show the GnomeAbout widget. This is because the "on_about_cb" method only recieves the argument callback but not the instance reference. --- partial code -- class Application: def __init__(self): self.hello = Hello() self.wtree = libglade.GladeXML('gnome-hello.glade') print "I instance self.wtree",self.wtree self.wtree.get_widget('app').connect("destroy", mainquit) print "***Here is the dictionary ot the instance were I can see\ self.wtree" print(self.__dict__) print "Here is the dictionary of the class were I can see\ on_about_cb" print(Application.__dict__) self.wtree.signal_autoconnect(Application.__dict__) def on_about_cb(self,*args): print "This should contain the instance directory like in\ ***",self print "This should contain the widget",args #self.wtree.get_widget('about_cb').show() -- The following code prints when I activate the "about..." menu: -- I instance self.wtree libglade.GladeXML instance at 81cfb40 ***Here is the dictionary ot the instance were I can see self.wtree {'wtree': libglade.GladeXML instance at 81cfb40, 'hello': __main__.Hello instance at 8209a50} Here is the dictionary of the class were I can see on_about_cb {'__init__': function __init__ at 81f20e0, '__doc__': None, 'on_about_cb': function on_about_cb at 8209a88, '__module__': '__main__'} This should contain the instance directory like in *** gtk.GtkBin instance at 8263f98 This should contain the pixmap () --- What I'm I doing wrong? Note: I'm not following the SkelImpl.py example because I don't understand his Object Oriented paradigm. Methods should be with the class they belong to, not all together in one "GladeHandlers" class. Thanks ?xml version="1.0"? GTK-Interface project namegnome-hello/name program_namegnome-hello/program_name directory/directory source_directorysrc/source_directory pixmaps_directorypixmaps/pixmaps_directory languageC/language gnome_supportTrue/gnome_support gettext_supportTrue/gettext_support use_widget_namesFalse/use_widget_names output_main_fileTrue/output_main_file output_support_filesTrue/output_support_files output_build_filesTrue/output_build_files backup_source_filesTrue/backup_source_files main_source_fileinterface.c/main_source_file main_header_fileinterface.h/main_header_file handler_source_filecallbacks.c/handler_source_file handler_header_filecallbacks.h/handler_header_file support_source_filesupport.c/support_source_file support_header_filesupport.h/support_header_file translatable_strings_file/translatable_strings_file /project widget classGnomeApp/class nameapp/name signal namedestroy/name handleron_app_destroy_cb/handler last_modification_timeFri, 11 Feb 2000 06:15:24 GMT/last_modification_time /signal titlegnome-hello/title typeGTK_WINDOW_TOPLEVEL/type positionGTK_WIN_POS_NONE/position modalFalse/modal allow_shrinkFalse/allow_shrink allow_growTrue/allow_grow auto_shrinkFalse/auto_shrink enable_layout_configTrue/enable_layout_config widget classGnomeDock/class child_nameGnomeApp:dock/child_name namedock/name allow_floatingTrue/allow_floating child padding0/padding expandTrue/expand fillTrue/fill /child widget classGnomeDockItem/class namedockitem/name border_width2/border_width placementGNOME_DOCK_TOP/placement band0/band position0/position offset0/offset lockedFalse/locked exclusiveTrue/exclusive never_floatingFalse/never_floating never_verticalTrue/never_vertical never_horizontalFalse/never_horizontal shadow_typeGTK_SHADOW_OUT/shadow_type widget classGtkMenuBar/class namemenubar1/name
Re: [pygtk] Can somebody explain the libglade OO paradigm?
What you want is a dictionary of the method objects. The class dictionary will not do (as that contains unbound methods, where the self parameter must be explicitely passed. The instance dictionary also will not do, as it does not contain the methods either. You would want to use some code something like: dict = {} for key in dir(self.__class__): dict[key] = getattr(self, key) This will give the bound methods that you can autoconnect with. I know it is not perfect, but it should do what you want. James. -- Email: [EMAIL PROTECTED] WWW: http://www.daa.com.au/~james/ On Thu, 10 Feb 2000, Daniel Kornhauser wrote: Hi I'm making a gnome-hello example for my pygtutorial http://laguna.fmedic.unam.mx/~daniel/pygtutorial/ and I'm stuck with the libglade example. I'm trying to do a gnome-hello like the one in my tutorial but with glade. My problem is the following: When I autoconect a handler, the handle is called ONLY with the callback argument and the instance reference isn't passed at all. PLEASE run the unfinished example I attached to see what I mean. Select the menu "help" and clik in "about". The example just instances a GnomeApp with a buton and menus. My problem comes when I want to show a GnomeAbout I made with glade. I try to do this selecting "about" in the "help" menu. Even if I am in the SAME class the "on_about_cb" method can't reference the self.wtree which I need to show the GnomeAbout widget. This is because the "on_about_cb" method only recieves the argument callback but not the instance reference. --- partial code -- class Application: def __init__(self): self.hello = Hello() self.wtree = libglade.GladeXML('gnome-hello.glade') print "I instance self.wtree",self.wtree self.wtree.get_widget('app').connect("destroy", mainquit) print "***Here is the dictionary ot the instance were I can see\ self.wtree" print(self.__dict__) print "Here is the dictionary of the class were I can see\ on_about_cb" print(Application.__dict__) self.wtree.signal_autoconnect(Application.__dict__) def on_about_cb(self,*args): print "This should contain the instance directory like in\ ***",self print "This should contain the widget",args #self.wtree.get_widget('about_cb').show() -- The following code prints when I activate the "about..." menu: -- I instance self.wtree libglade.GladeXML instance at 81cfb40 ***Here is the dictionary ot the instance were I can see self.wtree {'wtree': libglade.GladeXML instance at 81cfb40, 'hello': __main__.Hello instance at 8209a50} Here is the dictionary of the class were I can see on_about_cb {'__init__': function __init__ at 81f20e0, '__doc__': None, 'on_about_cb': function on_about_cb at 8209a88, '__module__': '__main__'} This should contain the instance directory like in *** gtk.GtkBin instance at 8263f98 This should contain the pixmap () --- What I'm I doing wrong? Note: I'm not following the SkelImpl.py example because I don't understand his Object Oriented paradigm. Methods should be with the class they belong to, not all together in one "GladeHandlers" class. Thanks To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]
Re: [pygtk] Width of a widget?
In gtk.py, there is a get_window() method for GtkWidget class. Then you should be able to use all gdkwindow attributes described in description.py in pygtk package. Now, you can do a widget.size_request() Does this help? Original Message On 2/11/00, 6:09:47 PM, "Stephan R.A. Deibel" [EMAIL PROTECTED] wrote regarding [pygtk] Width of a widget?: OK, this is pretty basic, but if I have an instance of gtk.GtkVBox I can't say x.width... it says Attribute Error. Shouldn't this be defined for all GtkWidgets? Is there some other way to get at this info? Thanks, - Stephan To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED] To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]
Re: [pygtk] Width of a widget?
What do you want? The widget's prefered minimum size? If so, use: width, height = widget.size_request() To get the actual allocated size of the widget, use: x, y, width, height = widget.get_allocation() James. -- Email: [EMAIL PROTECTED] WWW: http://www.daa.com.au/~james/ On Fri, 11 Feb 2000, Stephan R.A. Deibel wrote: OK, this is pretty basic, but if I have an instance of gtk.GtkVBox I can't say x.width... it says Attribute Error. Shouldn't this be defined for all GtkWidgets? Is there some other way to get at this info? Thanks, - Stephan To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED] To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]