Skip navigation.

GTK+ fundamentals, Part 2: How to use GTK+

GTK
GTK

The second part of IBM published series is up.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

A little unpolished

I've always felt, that gtk was an extremely nice toolkit, when using the programs, but the way it works isn't that nice.

Really how much performance do you get, by not having all widgets taking events? And what about the call to gtk_main(), and all the .show() calls.

It just feels a little unpolished, maybe because I haven't been using it for so long, but maybe at least the other language bindings, should do a little to smarten it.

Maybe I was wrong

Okay, I take much of it back. I didn't know about the show_all function. I wrote this little comparision. Not that big, but showing some basis:

Swing: (Jython)
from javax.swing import JFrame, JLabel
f = JFrame()
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(JLabel("Hello world"))
f.setBounds(0,0,100,100)
f.setVisible(True)

Gtk: (Pygtk)
import pygtk
pygtk.require('2.0')
import gtk
window = gtk.Window ()
window.add(gtk.Label("Hello World"))
window.connect("delete-event", lambda a,b: gtk.main_quit())
window.show_all()
gtk.main()

wxWidgets

I made a wxWidgets edition also, using wxpython. Seams that it also has a forced main() function. I'd really like to know what it helps.
import wx
app = wx.App()
frame = wx.Frame(parent=None, title='Bare Frame')
wx.StaticText(frame, -1, "Hello")
frame.Show()
app.MainLoop()

not really

1) containers are free to override virtual function used for show_all(), so they can keep hidden parts hidden
2) most of the time, you know what the widget hierarchy is, so if something breaks, you can simply fallback to manual show() for the offending part
3) USE LIBGLADE, dammit

3) USE LIBGLADE,

3) USE LIBGLADE, dammit

WRONG!!! That should be:

1) USE LIBGLADE, dammit.

Because ...

... you need to give flow control to {GTK+, Wx, whatever} at some point. It doesn't happen by magic, y'know, GTK+ can't just come, say "gimme that" and grab the control from you. I don't know how it's possible to get away with it in Swing, it probably creates implicit thread, which suggests some (potentially significant) pain at later stage when you start doing non-trivial things.

Besides, I don't understand why gtk.main() freaks you out so much, it's 1 line after all.

Swing...

Yes, you are correct.

Any call to setVisible(true) or show() will hand a window or component over to the implicit Swing/Awt thread. (Starting the thread if there isn't one yet.) It is assumed that no other threads will touch these objects after that point.

http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html

Can be by Anonymous George

Libglade is fine, but glade

Libglade is fine, but glade and gazpacho is really not that ultimate. At least not compared to stuff like Netbeans Matisse: http://www.netbeans.org/kb/50/quickstart-gui.html
Glade hasn't even got gnome HIG stuff like Drag'n'Drop, and only got redo functions a moment ago.

Sure, glade is lacking a bit by Anonymous George