[pygtk] Couple of easy questions (edit)

Micah Carrick email at micahcarrick.com
Thu Dec 27 12:23:56 WST 2007


Slight modification on the first question... I'm assuming I simply use a 
local variable for builder instead of self.builder and that will be 
taken care of just fine. So what I would have looks something more like:

def __init__(self):
   
        builder = gtk.Builder()
        builder.add_from_file("ui.xml")
       
        self.window = builder.get_object("window")
        self.window.set_default_size(200, 200)
       
        dic = { "on_window_destroy" : self.on_window_destroy,
                    "on_quit_menu_item_activate" : 
self.on_quit_menu_item_activate }
               
        builder.connect_signals(dic)

- Micah Carrick

  Developer - http://www.micahcarrick.com
  GTK+ Forums - http://www.gtkforums.com



Micah Carrick wrote:
> I'm an experienced GTK+ developer using C, however, I'm dinking around 
> with Python for a new tutorial I'm writing. Took me all of 2 minutes 
> to figure out how to get my glade file up and properly terminating. :)
>
> Couple of questions...
>
> 1. When using gtk.Builder (or glade), in C we use g_object_unref() on 
> the builder object to free memory when we've moved references to the 
> widgets we need into variables (don't need the XML sitting around). 
> Obviously python will handle memory for me, however, do I need to set 
> the variable to None or something so it knows I'm done with it?
>
> Example:
>
> self.builder = gtk.Builder()
> self.builder.add_from_file("ui.xml")
> self.window = self.builder.get_object("window")
> dic = { "on_window_destroy" : gtk.main_quit }     
> self.builder.connect_signals(dic)
> # I'm done with the builder... is it cleaned up automatically?
>
> 2. What's the difference between importing pygtk and just gtk? Is that 
> a distribution difference? Just 'import gtk' works for me... but I 
> need this code to be nice and universal.
>
> 3. I was looking at some PyGTK projects and noticed some have 
> everything all in one .py file. Is it common convention to put 
> everything into a single file, put each class into it's own file, or 
> does it vary from programmer to programmer?
>


More information about the pygtk mailing list