| FAQ Index - Search - Recent Changes - Everything - Add entry |
2.3. Is there a checklist of changes to migrate an application from PyGTK-0 to PyGTK-2?
Well, the start of one, thanks to LordVan ([www.lordvan.com] )
- Because PyGTK now support multiple versions being installed in parallel, you need to signal which one you want to use. ie:
import pygtk
pygtk.require('2.0')
import gtk
- If you used from gtk import *:
* use import gtk instead * from gtk import * * s/mainloop/gtk.mainloop/g # and other functions calls like 'mainquit' * s/Gtk/gtk./g
- If you used import gtk:
* s/Gtk//g
- Window doesn't accept a title keyword parameter to the constructor, use set_title():
- win = GtkWindow(title="Foo bar baz")
+ win = gtk.Window()
+ win.set_title("Foo bar baz")
- Label doesn't accept a label keyword parameter to the constructor: it now requires a string as an argument:
- label = GtkLabel(label="Foobar")
+ label = gtk.Label("Foobar")
- GtkText should be changed to a combination of GtkTextBuffer and GtkTextView:
- self.text = GtkText() + self.textbuffer = gtk.TextBuffer(None) + self.text = gtk.TextView() + self.text.set_buffer(self.textbuffer)
- TextBuffer offers insert_at_cursor, use it instead of GtkText.insert_defaults:
- self.text.insert_defaults( use_var ) + self.textbuffer.insert_at_cursor( use_var,len(use_var) )
- If you use GtkPixmap, it should be converted to gtk.Image, and use Image.set_from_pixmap() in place of GtkPixmap.set().
- Fonts can not be changed by altering the font attribute of the GdkStyle object (if you do style.font = foo it will silently be ignored). Instead, you must use something like:
entry = gtk.Entry()
font_desc = pango.FontDescription('monospace')
entry.modify_font(font_desc)
- To get a GdkWindow use the "window" instance attribute (Note that the widget needs to be realized before the GdkWindow is set):
entry = gtk.Entry() entry.realize() win = entry.window
- The GtkDrawingArea no longer offers proxy methods to its GdkDrawable's methods. In other words, you need to replace calls that looked like drawingarea.draw_point() with:
drawingarea.window.draw_point()
- clip_rectangle(), a method associated to GdkGC, requires a tuple to be passed in (it complains about a GdkRectangle) which is converted internally by PyGTK to a GdkRectangle:
gc.set_clip_rectangle((x, y, width, height))
- If you use a wheel mouse, listen to the new "scroll_event" signal. The old button 4/5 events are not generated anymore (jamesh says: The fact that the scroll wheel on your mouse generates button 4 and 5 events in X is an implementation detail, and was a bit of a pain for other GDK backends to implement.)
- OptionMenu wants get_children() instead of children()
option_menu=tree.get_widget("optionmenu1")
sometext=option_menu.get_children()[0].get()
- Function set_usize() is deprecated and should be replaced by set_size_request()
- Function GtkWindow.set_uposition() is deprecated and GtkWindow.move() should be used in its place.
