Python / glade fundamentals

Discussion in 'Python' started by Doug, Mar 16, 2006.

  1. Doug

    Doug Guest

    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="GtkWindow" id="page">
    <property name="visible">True</property>
    <property name="events">GDK_KEY_PRESS_MASK</property>
    <property name="title" translatable="yes">PGtestWindow</property>
    <property name="type">GTK_WINDOW_TOPLEVEL</property>
    <property name="window_position">GTK_WIN_POS_NONE</property>
    <property name="modal">False</property>
    <property name="default_width">640</property>
    <property name="default_height">480</property>
    <property name="resizable">True</property>
    <property name="destroy_with_parent">True</property>
    <property name="decorated">True</property>
    <property name="skip_taskbar_hint">False</property>
    <property name="skip_pager_hint">False</property>
    <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
    <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
    <signal name="destroy_event" handler="on_page_destroy_event" last_modification_time="Thu, 16 Mar 2006 12:57:33 GMT"/>

    <child>
    <widget class="GtkDrawingArea" id="drawingarea1">
    <property name="visible">True</property>
    <property name="events">GDK_KEY_PRESS_MASK</property>
    <property name="extension_events">GDK_EXTENSION_EVENTS_ALL</property>
    <signal name="key_press_event" handler="on_drawingarea1_key_press_event" last_modification_time="Thu, 16 Mar 2006 10:09:36 GMT"/>
    <signal name="destroy_event" handler="on_drawingarea1_destroy_event" last_modification_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(widget):
    print "keypress"

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

    xml.signal_autoconnect({
    "on_drawingarea1_key_press_event": on_drawingarea1_key_press,
    "on_page_destroy_event":gtk.mainquit
    })

    gtk.main()
     
    Doug, Mar 16, 2006
    #1
    1. Advertising

  2. Doug

    Dave Cook Guest

    On 2006-03-16, Doug <> wrote:

    > 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.


    This might be relevant:

    http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq03.003.htp

    Dave Cook
     
    Dave Cook, Mar 17, 2006
    #2
    1. Advertising

  3. Doug

    Doug Guest

    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(widget,event):
    print "keypress"

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

    xml.signal_autoconnect({
    "on_page_key_press_event": key_press,
    "on_page_destroy_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="GtkWindow" id="page">
    <property name="visible">True</property>
    <property name="title" translatable="yes">PGtestWindow</property>
    <property name="type">GTK_WINDOW_TOPLEVEL</property>
    <property name="window_position">GTK_WIN_POS_NONE</property>
    <property name="modal">False</property>
    <property name="default_width">640</property>
    <property name="default_height">480</property>
    <property name="resizable">True</property>
    <property name="destroy_with_parent">True</property>
    <property name="decorated">True</property>
    <property name="skip_taskbar_hint">False</property>
    <property name="skip_pager_hint">False</property>
    <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
    <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
    <signal name="destroy" handler="on_page_destroy_event" last_modification_time="Fri, 17 Mar
    2006 12:42:42 GMT"/>
    <signal name="key_press_event" handler="on_page_key_press_event" after="yes" last_modificat
    ion_time="Fri, 17 Mar 2006 12:56:29 GMT"/>

    <child>
    <widget class="GtkDrawingArea" id="drawingarea1">
    <property name="visible">True</property>
    <signal name="key_press_event" handler="on_drawingarea1_key_press_event" after="yes" la
    st_modification_time="Thu, 16 Mar 2006 10:09:36 GMT"/>
    <signal name="destroy" handler="on_drawingarea1_destroy_event" last_modification_time="
    Fri, 17 Mar 2006 12:36:08 GMT"/>
    </widget>
    </child>
    </widget>

    </glade-interface>
     
    Doug, Mar 17, 2006
    #3
  4. Doug

    Ido Yehieli Guest

    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
     
    Ido Yehieli, Mar 17, 2006
    #4
  5. Doug

    Ido Yehieli Guest

    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
     
    Ido Yehieli, Mar 17, 2006
    #5
  6. Franck Pommereau, Mar 20, 2006
    #6
  7. Doug

    Ido Yehieli Guest

    Franck:
    PyGG seems pretty cool, thanks for the link!
     
    Ido Yehieli, Mar 20, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?Gregory_Pi=F1ero?=

    Passing arguments to function - (The fundamentals are confusing me)

    =?ISO-8859-1?Q?Gregory_Pi=F1ero?=, Aug 9, 2005, in forum: Python
    Replies:
    20
    Views:
    697
    Dennis Lee Bieber
    Aug 10, 2005
  2. bart
    Replies:
    0
    Views:
    478
  3. gdv
    Replies:
    4
    Views:
    651
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Oct 14, 2007
  4. XyZed
    Replies:
    21
    Views:
    810
    dorayme
    Jan 17, 2008
  5. bart
    Replies:
    0
    Views:
    502
Loading...

Share This Page