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>
<name>gnome-hello</name>
<program_name>gnome-hello</program_name>
<directory></directory>
<source_directory>src</source_directory>
<pixmaps_directory>pixmaps</pixmaps_directory>
<language>C</language>
<gnome_support>True</gnome_support>
<gettext_support>True</gettext_support>
<use_widget_names>False</use_widget_names>
<output_main_file>True</output_main_file>
<output_support_files>True</output_support_files>
<output_build_files>True</output_build_files>
<backup_source_files>True</backup_source_files>
<main_source_file>interface.c</main_source_file>
<main_header_file>interface.h</main_header_file>
<handler_source_file>callbacks.c</handler_source_file>
<handler_header_file>callbacks.h</handler_header_file>
<support_source_file>support.c</support_source_file>
<support_header_file>support.h</support_header_file>
<translatable_strings_file></translatable_strings_file>
</project>
<widget>
<class>GnomeApp</class>
<name>app</name>
<signal>
<name>destroy</name>
<handler>on_app_destroy_cb</handler>
<last_modification_time>Fri, 11 Feb 2000 06:15:24 GMT</last_modification_time>
</signal>
<title>gnome-hello</title>
<type>GTK_WINDOW_TOPLEVEL</type>
<position>GTK_WIN_POS_NONE</position>
<modal>False</modal>
<allow_shrink>False</allow_shrink>
<allow_grow>True</allow_grow>
<auto_shrink>False</auto_shrink>
<enable_layout_config>True</enable_layout_config>
<widget>
<class>GnomeDock</class>
<child_name>GnomeApp:dock</child_name>
<name>dock</name>
<allow_floating>True</allow_floating>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GnomeDockItem</class>
<name>dockitem</name>
<border_width>2</border_width>
<placement>GNOME_DOCK_TOP</placement>
<band>0</band>
<position>0</position>
<offset>0</offset>
<locked>False</locked>
<exclusive>True</exclusive>
<never_floating>False</never_floating>
<never_vertical>True</never_vertical>
<never_horizontal>False</never_horizontal>
<shadow_type>GTK_SHADOW_OUT</shadow_type>
<widget>
<class>GtkMenuBar</class>
<name>menubar1</name>
<shadow_type>GTK_SHADOW_NONE</shadow_type>
<widget>
<class>GtkMenuItem</class>
<name>file</name>
<stock_item>GNOMEUIINFO_MENU_FILE_TREE</stock_item>
<widget>
<class>GtkMenu</class>
<name>file_menu</name>
<widget>
<class>GtkPixmapMenuItem</class>
<name>exit</name>
<signal>
<name>activate</name>
<handler>on_exit_menu_activate</handler>
<last_modification_time>Fri, 11 Feb 2000 06:30:00
GMT</last_modification_time>
</signal>
<stock_item>GNOMEUIINFO_MENU_EXIT_ITEM</stock_item>
</widget>
</widget>
</widget>
<widget>
<class>GtkMenuItem</class>
<name>settings</name>
<stock_item>GNOMEUIINFO_MENU_SETTINGS_TREE</stock_item>
<widget>
<class>GtkMenu</class>
<name>settings_menu</name>
<widget>
<class>GtkPixmapMenuItem</class>
<name>preferences</name>
<signal>
<name>activate</name>
<handler>on_preferences_activate</handler>
<last_modification_time>Fri, 11 Feb 2000 01:17:47
GMT</last_modification_time>
</signal>
<stock_item>GNOMEUIINFO_MENU_PREFERENCES_ITEM</stock_item>
</widget>
</widget>
</widget>
<widget>
<class>GtkMenuItem</class>
<name>help</name>
<stock_item>GNOMEUIINFO_MENU_HELP_TREE</stock_item>
<widget>
<class>GtkMenu</class>
<name>help_menu</name>
<widget>
<class>GtkPixmapMenuItem</class>
<name>about</name>
<signal>
<name>activate</name>
<handler>on_about_cb</handler>
<last_modification_time>Fri, 11 Feb 2000 08:48:35
GMT</last_modification_time>
</signal>
<stock_item>GNOMEUIINFO_MENU_ABOUT_ITEM</stock_item>
</widget>
</widget>
</widget>
</widget>
</widget>
<widget>
<class>GtkButton</class>
<child_name>GnomeDock:contents</child_name>
<name>gretting-buton</name>
<can_focus>True</can_focus>
<signal>
<name>clicked</name>
<handler>on_button4_clicked</handler>
<last_modification_time>Fri, 11 Feb 2000 01:13:32 GMT</last_modification_time>
</signal>
<label>Press for a gretting</label>
</widget>
</widget>
<widget>
<class>GnomeAppBar</class>
<child_name>GnomeApp:appbar</child_name>
<name>appbar</name>
<has_progress>True</has_progress>
<has_status>True</has_status>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
</widget>
</widget>
<widget>
<class>GnomeDialog</class>
<name>dialog</name>
<visible>False</visible>
<type>GTK_WINDOW_DIALOG</type>
<position>GTK_WIN_POS_NONE</position>
<modal>False</modal>
<allow_shrink>False</allow_shrink>
<allow_grow>False</allow_grow>
<auto_shrink>False</auto_shrink>
<auto_close>False</auto_close>
<hide_on_close>False</hide_on_close>
<widget>
<class>GtkVBox</class>
<child_name>GnomeDialog:vbox</child_name>
<name>vbox1</name>
<homogeneous>False</homogeneous>
<spacing>8</spacing>
<child>
<padding>4</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkVBox</class>
<name>vbox2</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkHBox</class>
<name>hbox1</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkLabel</class>
<name>gretting-question</name>
<label>What is thee new greeting ?</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
</widget>
<widget>
<class>GtkEntry</class>
<name>entry</name>
<can_focus>True</can_focus>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text></text>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
</widget>
<widget>
<class>GtkHButtonBox</class>
<child_name>GnomeDialog:action_area</child_name>
<name>dialog-action_area1</name>
<layout_style>GTK_BUTTONBOX_END</layout_style>
<spacing>8</spacing>
<child_min_width>85</child_min_width>
<child_min_height>27</child_min_height>
<child_ipad_x>7</child_ipad_x>
<child_ipad_y>0</child_ipad_y>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>True</fill>
<pack>GTK_PACK_END</pack>
</child>
<widget>
<class>GtkButton</class>
<name>ok-button</name>
<can_default>True</can_default>
<can_focus>True</can_focus>
<signal>
<name>clicked</name>
<handler>on_ok-button_clicked</handler>
<last_modification_time>Fri, 11 Feb 2000 04:29:29
GMT</last_modification_time>
</signal>
<stock_button>GNOME_STOCK_BUTTON_OK</stock_button>
</widget>
<widget>
<class>GtkButton</class>
<name>cancel-button</name>
<can_default>True</can_default>
<can_focus>True</can_focus>
<stock_button>GNOME_STOCK_BUTTON_CANCEL</stock_button>
</widget>
</widget>
</widget>
</widget>
<widget>
<class>GnomeAbout</class>
<name>about</name>
<visible>False</visible>
<modal>True</modal>
<copyright>�1999-2000:May be distributed under the terms of the GPL</copyright>
<authors>Daniel Kornhauser [EMAIL PROTECTED]
</authors>
<comments>A simple gnome-hello example generated by galde</comments>
</widget>
</GTK-Interface>
#!/usr/bin/env python
from gtk import *
from gnome.ui import *
from gnome.config import *
import libglade
class Hello:
def __init__(self):
self.greeting = get_string('pygnome-hello-world/greeting/string')
if (self.greeting == None): self.greeting = "Hello World"
def print_greeting(self):
print self.greeting
def change_greeting(self,*args):
self.greeting = args[0]
set_string('pygnome_hello/greeting/string',self.greeting)
sync()
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 "\n***Here is the dictionary ot the instance were I can see self.wtree"
print(self.__dict__)
print "\nHere 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 "\nself should contain the instance directory like in ***",self
print "\narg should contain the widget",args
#self.wtree.get_widget('about_cb').show()
if __name__ == '__main__': # Here starts the dynamic part of the program
app = Application() # Instancing of the GUI
mainloop()