Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python / glade fundamentals

Reply
Thread Tools

Python / glade fundamentals

 
 
Doug
Guest
Posts: n/a
 
      03-16-2006
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()


 
Reply With Quote
 
 
 
 
Dave Cook
Guest
Posts: n/a
 
      03-17-2006
On 2006-03-16, Doug <(E-Mail Removed)> 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/in...=faq03.003.htp

Dave Cook
 
Reply With Quote
 
 
 
 
Doug
Guest
Posts: n/a
 
      03-17-2006
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>


 
Reply With Quote
 
Ido Yehieli
Guest
Posts: n/a
 
      03-17-2006
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

 
Reply With Quote
 
Ido Yehieli
Guest
Posts: n/a
 
      03-17-2006
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

 
Reply With Quote
 
Franck Pommereau
Guest
Posts: n/a
 
      03-20-2006
> 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


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

Cheers,
Franck
 
Reply With Quote
 
Ido Yehieli
Guest
Posts: n/a
 
      03-20-2006
Franck:
PyGG seems pretty cool, thanks for the link!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
web services fundamentals gdv Java 4 10-14-2007 06:17 PM
ANNC: FPGA Noise Fundamentals Webcast bart VHDL 0 08-27-2007 06:00 PM
TCP/IP Fundamentals for Microsoft Windows Wayne MCSE 3 05-24-2006 06:29 PM
Passing arguments to function - (The fundamentals are confusing me) =?ISO-8859-1?Q?Gregory_Pi=F1ero?= Python 20 08-10-2005 06:08 AM
Fundamentals of Networking Frames to Packets Bharani Cisco 0 07-29-2004 12:04 PM



Advertisments