François Pinard <[EMAIL PROTECTED]> writes:
>I suppose I should put in a message stating that the pyglade
>module is deprecated. It is probably better to use the libglade
>module, which uses libglade rather than being pure python. It
>handles the default_width and default_height attributes
>correctly.
>
> However, I do not run Gnome, and would prefer to not ought to change
> window managers as well. A new language and a new design spirit is
> a lot already for the poor little me, I do not feel like embracing a
> new religion as well! I tried both KDE and Gnome for a while, and
> returned to my previous habits, probably because I merely failed to
> quickly see the promised wonders. :-)
>
> However, I repeatedly read on the `pygtk' mailing list archives that
> PyGnome (whatever it is :-) is the way to go, yet the same lists
> report a lot of build and unstability problems (but maybe I
> misinterpreted them?).
François, please note that pygtk does not require PyGnome to be used.
PyGnome is merely a superset of pygtk, providing wrappers for
Gnome-specific stuff, such as communication with panel, and the
additional Gtk widgets provided by Gnome. (Also note that you needn't
switch window managers to run Gnome, but that's a different issue.)
I believe the glade bindings can be useful. Gtk programming is
basically fun -- you explain to the engine the layout you want your
widgets to have, you connect their actions to callbacks, and watch
things happen. With Python's lexical-scoping-like bound methods, it's
really not hard to get reasonable results.
The most tedious part of it all is configuring actual widget packing.
Take, for instance, a simple class that tries to configure a text
entry field along with "OK" and "Cancel". It's totally trivial, and
should look like this:
class OpenDialog(gtk.GtkWindow):
def __init__(self, dispatchfun):
gtk.GtkWindow.__init__(self)
# ... setup the widgets ...
gtk_entry.connect("activate", self.open, entry, dispatchfun)
gtk_entry.connect("changed", self.change_hook)
button1.connect("clicked", self.open, dispatchfun)
button2.connect("clicked", self.destroy)
self.show_all()
def change_hook(self, widget):
if widget.get_text() == '':
self.ok_button.set_sensitive(gtk.FALSE)
else:
self.ok_button.set_sensitive(gtk.TRUE)
def open(self, widget, entry, dispatchfun):
text = entry.gtk_entry().get_text()
if text != '':
dispatchfun(text)
self.destroy()
Nice and simple, isn't it? In reality, because I didn't bother to
learn to use libglade properly, it looks as below, a spaghetti of
getting the Gtk widgets to look nice. *All* the additional code could
have been done within libglade, based on an XML file that the users
can edit. My code would simply get the objects and work on them. The
real code follows:
class OpenDialog(gtk.GtkWindow):
def __init__(self, dispatchfun):
gtk.GtkWindow.__init__(self)
self.set_border_width(5)
self.set_policy(gtk.TRUE, gtk.TRUE, gtk.FALSE)
gtk.quit_add_destroy(1, self)
vbox = gtk.GtkVBox()
self.add(vbox)
label = gtk.GtkLabel("Enter a URL to download it with Wget.")
label.set_alignment(0, 0.5) # No centering
label.set_padding(0, 5)
vbox.pack_start(label, expand = gtk.FALSE, fill = gtk.FALSE)
hbox = gtk.GtkHBox(spacing = 10)
vbox.pack_start(hbox, expand = gtk.FALSE, padding = 3)
hbox.pack_start(gtk.GtkLabel("Open:"), expand = gtk.FALSE, fill = gtk.FALSE)
entry = gnome.ui.GnomeEntry("OpenDialog")
gtk_entry = entry.gtk_entry()
gtk_entry.connect("activate", self.open, entry, dispatchfun)
gtk_entry.connect("changed", self.change_hook)
#gtk_entry.set_flags(gtk.HAS_DEFAULT | gtk.CAN_DEFAULT)
#gtk_entry.grab_default()
hbox.pack_start(entry)
vbox.pack_start(gtk.GtkHSeparator(), expand = gtk.FALSE, padding = 10)
alignment = gtk.GtkAlignment(0.5, 0.5, 1, 1)
vbox.pack_start(alignment, expand = gtk.FALSE)
bbox = gtk.GtkHButtonBox()
bbox.set_layout(gtk.BUTTONBOX_SPREAD)
alignment.add(bbox)
button = gnome.ui.GnomeStockButton(gnome.ui.STOCK_BUTTON_OK)
button.connect("clicked", self.open, dispatchfun)
button.set_flags(gtk.HAS_DEFAULT | gtk.CAN_DEFAULT)
#button.grab_default()
button.set_sensitive(gtk.FALSE)
bbox.pack_start(button)
self.ok_button = button
button = gnome.ui.GnomeStockButton(gnome.ui.STOCK_BUTTON_CANCEL)
button.connect("clicked", self.destroy)
bbox.pack_start(button)
def change_hook(self, widget):
if widget.get_text() == '':
self.ok_button.set_sensitive(gtk.FALSE)
else:
self.ok_button.set_sensitive(gtk.TRUE)
def open(self, widget, entr