Python / glade fundamentals

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Doug

    #1

    Python / glade fundamentals

    Hi all,
    Can someone tell me why I do not get a connection between the events and
    the functions in the sample below. GUI window appears OK, just no
    connections seem to be made.
    I am new to this so may be missing something fundamental.
    Thanks,
    Doug



    file pgtest.glade
    =============== ==

    <?xml version="1.0" standalone="no" ?> <!--*- mode: xml -*-->
    <!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">

    <glade-interface>

    <widget class="GtkWindo w" id="page">
    <property name="visible"> True</property>
    <property name="events">G DK_KEY_PRESS_MA SK</property>
    <property name="title" translatable="y es">PGtestWindo w</property>
    <property name="type">GTK _WINDOW_TOPLEVE L</property>
    <property name="window_po sition">GTK_WIN _POS_NONE</property>
    <property name="modal">Fa lse</property>
    <property name="default_w idth">640</property>
    <property name="default_h eight">480</property>
    <property name="resizable ">True</property>
    <property name="destroy_w ith_parent">Tru e</property>
    <property name="decorated ">True</property>
    <property name="skip_task bar_hint">False </property>
    <property name="skip_page r_hint">False</property>
    <property name="type_hint ">GDK_WINDOW_TY PE_HINT_NORMAL</property>
    <property name="gravity"> GDK_GRAVITY_NOR TH_WEST</property>
    <signal name="destroy_e vent" handler="on_pag e_destroy_event " last_modificati on_time="Thu, 16 Mar 2006 12:57:33 GMT"/>

    <child>
    <widget class="GtkDrawi ngArea" id="drawingarea 1">
    <property name="visible"> True</property>
    <property name="events">G DK_KEY_PRESS_MA SK</property>
    <property name="extension _events">GDK_EX TENSION_EVENTS_ ALL</property>
    <signal name="key_press _event" handler="on_dra wingarea1_key_p ress_event" last_modificati on_time="Thu, 16 Mar 2006 10:09:36 GMT"/>
    <signal name="destroy_e vent" handler="on_dra wingarea1_destr oy_event" last_modificati on_time="Thu, 16 Mar 2006 13:01:31 GMT"/>
    </widget>
    </child>
    </widget>

    </glade-interface>

    file pgtest.py
    ==============
    import gtk
    import gtk.glade

    def on_drawingarea1 _key_press(widg et):
    print "keypress"

    xml = gtk.glade.XML(' pgtest.glade')
    widget = xml.get_widget( 'drawingarea1')
    #print type(xml)

    xml.signal_auto connect({
    "on_drawingarea 1_key_press_eve nt": on_drawingarea1 _key_press,
    "on_page_destro y_event":gtk.ma inquit
    })

    gtk.main()


  • Dave Cook

    #2
    Re: Python / glade fundamentals

    On 2006-03-16, Doug <doug@localhost .localdomain> wrote:
    [color=blue]
    > Can someone tell me why I do not get a connection between the events and
    > the functions in the sample below. GUI window appears OK, just no
    > connections seem to be made.
    > I am new to this so may be missing something fundamental.[/color]

    This might be relevant:



    Dave Cook

    Comment

    • Doug

      #3
      Re: Python / glade fundamentals

      OK, I have solved the problem. The reference was a help. The clue is that
      the events may not get passed through the parent. For reference here is
      the code that worked.
      It's good to finally get the basics working.
      Doug

      import gtk
      import gtk.glade

      def key_press(widge t,event):
      print "keypress"

      xml = gtk.glade.XML(' pgtest.glade')
      widget = xml.get_widget( 'drawingarea1')

      xml.signal_auto connect({
      "on_page_key_pr ess_event": key_press,
      "on_page_destro y_event": gtk.main_quit
      })

      gtk.main()


      =======file: pgtest.glade=== ====

      <?xml version="1.0" standalone="no" ?> <!--*- mode: xml -*-->
      <!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">

      <glade-interface>

      <widget class="GtkWindo w" id="page">
      <property name="visible"> True</property>
      <property name="title" translatable="y es">PGtestWindo w</property>
      <property name="type">GTK _WINDOW_TOPLEVE L</property>
      <property name="window_po sition">GTK_WIN _POS_NONE</property>
      <property name="modal">Fa lse</property>
      <property name="default_w idth">640</property>
      <property name="default_h eight">480</property>
      <property name="resizable ">True</property>
      <property name="destroy_w ith_parent">Tru e</property>
      <property name="decorated ">True</property>
      <property name="skip_task bar_hint">False </property>
      <property name="skip_page r_hint">False</property>
      <property name="type_hint ">GDK_WINDOW_TY PE_HINT_NORMAL</property>
      <property name="gravity"> GDK_GRAVITY_NOR TH_WEST</property>
      <signal name="destroy" handler="on_pag e_destroy_event " last_modificati on_time="Fri, 17 Mar
      2006 12:42:42 GMT"/>
      <signal name="key_press _event" handler="on_pag e_key_press_eve nt" after="yes" last_modificat
      ion_time="Fri, 17 Mar 2006 12:56:29 GMT"/>

      <child>
      <widget class="GtkDrawi ngArea" id="drawingarea 1">
      <property name="visible"> True</property>
      <signal name="key_press _event" handler="on_dra wingarea1_key_p ress_event" after="yes" la
      st_modification _time="Thu, 16 Mar 2006 10:09:36 GMT"/>
      <signal name="destroy" handler="on_dra wingarea1_destr oy_event" last_modificati on_time="
      Fri, 17 Mar 2006 12:36:08 GMT"/>
      </widget>
      </child>
      </widget>

      </glade-interface>


      Comment

      • Ido Yehieli

        #4
        Re: Python / glade fundamentals

        Hi Doug,
        mabe you will find it easyer to use GladeGen to generate the
        skeleton of your application rather then coding it yourself. Take a
        look here: http://www.linuxjournal.com/article/7421

        Cheers,
        Ido Yehieli

        Comment

        • Ido Yehieli

          #5
          Re: Python / glade fundamentals

          Hi Doug,
          maybe you will find it easyer to use GladeGen to generate the
          skeleton of your application rather then coding it yourself. Take a
          look here: http://www.linuxjournal.com/article/7421

          Cheers,
          Ido Yehieli

          Comment

          • Franck Pommereau

            #6
            Re: Python / glade fundamentals

            > maybe you will find it easyer to use GladeGen to generate the[color=blue]
            > skeleton of your application rather then coding it yourself. Take a
            > look here: http://www.linuxjournal.com/article/7421[/color]

            You may also use my PyGG module: http://freshmeat.net/projects/pygg

            Cheers,
            Franck

            Comment

            • Ido Yehieli

              #7
              Re: Python / glade fundamentals

              Franck:
              PyGG seems pretty cool, thanks for the link!

              Comment

              Working...