> From: Jon Nelson <[EMAIL PROTECTED]>

> that a more general question (for a more general audience):
> could some of you explain how *you* use glade and/or gtk?
> Do you use classes? Do you do things programmatically? Personally,
> I use a wrapper that does (essentially) this:
> 
> import foo_handlers
> wtree = libglade.GladeXML(filename)
> try:
>   foo_handlers.wtree = wtree
>   foo_handlers.setup() # handles things like commandline, preps variables
>   foo_handlers.wtree.signal_autoconnect(foo_handlers.__dict__)
>   f = os.path.expanduser("~/.gtkrc-foo")
>   if os.path.exists(f):
>     gtk.rc_parse(f)
>   foo_handlers.go() # eventually calls gtk.mainloop()
> except:
>   foo_handlers.on_exit() # eventually calls gtk.mainquit()
>   raise
>   sys.exit(1)
> 
> and foo_handlers is little more than support functions and
> 
> def on_button_foo_clicked(widget):
>   blah blah blah
> 
> style.  No classes, etc...


I create a class for each window in the program.

The class has a method called load_glade()

that calls libglade.GladeXML

and contains a list of widgets I want to access:

e.g., widget_list = ('scrolledwindow', 'last')

that correspond to their Glade names

then I do:

      for w in widget_list:
         setattr(self, w, self.loader.get_widget(w))

So that the class member functions can access those widgets as:
self.scrolledwindow
and
self.last

I then have a signal handler dict like:

      signal_handlers = {
         'on_scores_select_row': self.on_scores_select_row,
         'on_update_clicked': self.on_update_clicked,
         'on_exit_clicked': self.on_exit_clicked,
         }
      self.loader.signal_autoconnect(signal_handlers)

so each callback is a member of the class.

I haven't run into any situations yet where this design strategy didn't
work well for me.

I have a student who is working on a junior/senior project that
involves parsing the glade XML file and create a class that does all
this (grabs the widget_list entries based on the names in the XML
file, sets up the signal_handlers dict, etc.) and makes empty signal
handlers. I know something exists to do this (gladepyc or something
like that), but it didn't seem to work very well when I tried it.

HTH,
Dave
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk

Reply via email to