In examples/neil/TAppli.py it creates an item factory thus:

    itemf = gtk.GtkItemFactory(gtk.GtkMenuBar, "<main>", ag)

This call fails under pygtk2, complaining that the first arg is supposed to
be an integer.  After a little muddling around I found the __gtype__
attribute of GObjects.  On more-or-less of a whim I tried modifying the
above to

    itemf = gtk.GtkItemFactory(gtk.GtkMenuBar.__gtype__, "<main>", ag)

After making a couple other unrelated changes, this script seems to work
(changes appended).  I worry about referencing the __gtype__ attribute
directly, but didn't see any sort of "get_type" method.  Am I missing
something?

On an unrelated note, I think standard practice should be to use "import
gtk", not "from gtk import *", if for no other reason than that the gtk
module defines the names TRUE and FALSE, which are fairly easy to clash
with.

Thanks,

-- 
Skip Montanaro ([EMAIL PROTECTED])
(847)971-7098


*** TAppli.py.~1~       Mon Jan 11 07:30:34 1999
--- TAppli.py   Wed Apr 18 03:24:05 2001
***************
*** 6,19 ****
  
  import sys
  import time
! from gtk import *
  
  class Application:            
        def __init__(self, argv):
!               self.w_window=GtkWindow()
                self.w_window.set_title("Test application")
                self.w_window.set_border_width(10)
!               self.w_vbox=GtkVBox()
                
                self.init_menu()
                self.init_list()
--- 6,19 ----
  
  import sys
  import time
! import gtk
  
  class Application:            
        def __init__(self, argv):
!               self.w_window=gtk.GtkWindow()
                self.w_window.set_title("Test application")
                self.w_window.set_border_width(10)
!               self.w_vbox=gtk.GtkVBox()
                
                self.init_menu()
                self.init_list()
***************
*** 24,49 ****
                self.w_window.show()            
                
                self.idlecount=0
!               idle_add(self.idle)
  
        def mainloop(self):
!               mainloop()
  
        def quit(self, mi):
!               mainquit()
                                
        def doit(self, button):
                z=[]
                for x in range(10,20):
!                       item=GtkListItem(label="line %d" % x)
                        item.show()
                        z.append(item)
                self.w_listbox.append_items(z)
        
  
        def init_menu(self):
!               ag = GtkAccelGroup()
!               itemf = GtkItemFactory(GtkMenuBar, "<main>", ag)
                self.w_window.add_accel_group(ag)
                file_cb = self.process_file
                edit_cb = self.process_edit
--- 24,50 ----
                self.w_window.show()            
                
                self.idlecount=0
!               gtk.idle_add(self.idle)
  
        def mainloop(self):
!               gtk.mainloop()
  
        def quit(self, mi):
!               gtk.mainquit()
                                
        def doit(self, button):
                z=[]
                for x in range(10,20):
!                       item=gtk.GtkListItem(label="line %d" % x)
                        item.show()
                        z.append(item)
                self.w_listbox.append_items(z)
        
  
        def init_menu(self):
!               ag = gtk.GtkAccelGroup()
!               itemf = gtk.GtkItemFactory(gtk.GtkMenuBar.__gtype__,
!                                          "<main>", ag)
                self.w_window.add_accel_group(ag)
                file_cb = self.process_file
                edit_cb = self.process_edit
***************
*** 62,95 ****
                        ('/_Edit/_Paste',   '<control>V', edit_cb, 3, '')
                ])
                self.w_menubar = itemf.get_widget('<main>')
!               self.w_vbox.pack_start(self.w_menubar, expand=FALSE)
                self.w_menubar.show()
  
        def init_list(self):            
!               c=GtkScrolledWindow()   
                c.set_usize(250,200)
!               self.w_listbox=GtkList()
!               self.w_listbox.set_selection_mode(SELECTION_MULTIPLE)
                c.add_with_viewport(self.w_listbox)
                self.w_vbox.pack_start(c)
                
                for x in range(0,10):
!                       item=GtkListItem(label="line %d" % x)
                        item.show()
                        self.w_listbox.add(item)
                self.w_listbox.show()
                c.show()
                
        def init_button(self):
!               t = GtkTable(rows=1, cols=2, homogeneous=TRUE)
!               b1 = GtkButton('Do it!')
                b1.connect('clicked', self.doit)
!               b2 = GtkButton('Quit')
                b2.connect('clicked', self.quit)
                t.attach(b1, 0, 1, 0, 1, yoptions=0, xpadding=2, ypadding=2)
                t.attach(b2, 1, 2, 0, 1, yoptions=0, xpadding=2, ypadding=2)
                
!               self.w_vbox.pack_end(t, expand=FALSE)
                                
                b1.show()
                b2.show()
--- 63,96 ----
                        ('/_Edit/_Paste',   '<control>V', edit_cb, 3, '')
                ])
                self.w_menubar = itemf.get_widget('<main>')
!               self.w_vbox.pack_start(self.w_menubar, expand=gtk.FALSE)
                self.w_menubar.show()
  
        def init_list(self):            
!               c=gtk.GtkScrolledWindow()       
                c.set_usize(250,200)
!               self.w_listbox=gtk.GtkList()
!               self.w_listbox.set_selection_mode(gtk.SELECTION_MULTIPLE)
                c.add_with_viewport(self.w_listbox)
                self.w_vbox.pack_start(c)
                
                for x in range(0,10):
!                       item=gtk.GtkListItem(label="line %d" % x)
                        item.show()
                        self.w_listbox.add(item)
                self.w_listbox.show()
                c.show()
                
        def init_button(self):
!               t = gtk.GtkTable(rows=1, columns=2, homogeneous=gtk.TRUE)
!               b1 = gtk.GtkButton('Do it!')
                b1.connect('clicked', self.doit)
!               b2 = gtk.GtkButton('Quit')
                b2.connect('clicked', self.quit)
                t.attach(b1, 0, 1, 0, 1, yoptions=0, xpadding=2, ypadding=2)
                t.attach(b2, 1, 2, 0, 1, yoptions=0, xpadding=2, ypadding=2)
                
!               self.w_vbox.pack_end(t, expand=gtk.FALSE)
                                
                b1.show()
                b2.show()
***************
*** 104,110 ****
                elif action == 5: print "File:Close"
                elif action == 6:
                        print "File:Exit"
!                       mainquit()
        def process_edit(self, action, widget):
                if action == 0: print "Edit:<unknown>"
                elif action == 1: print "Edit:Cut"
--- 105,111 ----
                elif action == 5: print "File:Close"
                elif action == 6:
                        print "File:Exit"
!                       gtk.mainquit()
        def process_edit(self, action, widget):
                if action == 0: print "Edit:<unknown>"
                elif action == 1: print "Edit:Cut"
***************
*** 117,123 ****
                        print "Idle:", self.idlecount
                        # if measuring time
                        ##self.quit()
!               return TRUE
  
                        
  if(__name__=="__main__"):
--- 118,124 ----
                        print "Idle:", self.idlecount
                        # if measuring time
                        ##self.quit()
!               return gtk.TRUE
  
                        
  if(__name__=="__main__"):
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk

Reply via email to