Le lun, 17 avr 2000, vous avez �crit :
> If you use gnome features in your glade file, you must import gnome.ui
> before creating the GladeXML object.  That should fix the problem.
> 
> James.
> 
> --

I have the same problem: even when importing gnome.ui before creating the
GladeXML object. The attached files are just taken from a gnome python tutorial.
What has to be made to have this example work?

Fr�d�ric
<?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>exit</handler>
                <last_modification_time>Fri, 11 Feb 2000 21:50:28 
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>change_greeting_cb</handler>
                <last_modification_time>Fri, 11 Feb 2000 20:18:45 
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>about_cb</handler>
                <last_modification_time>Fri, 11 Feb 2000 21:19:14 
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>hello_cb</handler>
        <last_modification_time>Fri, 11 Feb 2000 21:56:03 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>
        <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[1].get_text()
	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 "Instance self.wtree",self.wtree
        self.wtree.get_widget('app').connect("destroy", mainquit) 
        print "\n***Dictionary ot the instance were I can see self.wtree"
        print(self.__dict__)
        print "\nDictionary of the class were I can see on_about_cb"
        print(Application.__dict__)
	# You need to create this diccionary in order to get the 
        # the bound methods that you can autoconnect with.
	# And quoting James: 
        # "I know it is not perfect, but it should do what you want."
	dict = {}
	for key in dir(self.__class__):
	    dict[key] = getattr(self, key)
	self.wtree.signal_autoconnect(dict)

    def exit(self,*args):
	mainquit()

    def about_cb(self,*args):
        self.wtree.get_widget('about').show()

    def change_greeting_cb(self,*args):
	self.wtree.get_widget('entry').set_text(self.hello.greeting)
	
    	self.wtree.get_widget('ok-button').connect("clicked",
						   self.hello.change_greeting,
						   self.wtree.get_widget(
						       'entry'))
    	self.wtree.get_widget('ok-button').connect_after("clicked",
							 self.wtree.get_widget(
							     'dialog').hide)
    	self.wtree.get_widget('cancel-button').connect("clicked",
						       self.wtree.get_widget(
							   'dialog').hide)
    	self.wtree.get_widget('dialog').show()

    def hello_cb(self,*args):
	self.hello.print_greeting()

if __name__ == '__main__': # Here starts the dynamic part of the program 
    app = Application()    # Instancing of the GUI   
    mainloop()


Reply via email to