On Wed, May 26, 1999 at 05:32:26PM -0700, David M. Cook wrote:
> I'll see if I can bang together some of my notes into something presentable.
Here are parts of the notes from a talk I gave on pygtk:
* translating from C-Gtk to pygtk example
Example of object instantiation:
GtkWidget *window;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
==> window = GtkWindow(WINDOW_TOPLEVEL) #or just
window = GtkWindow()
in general:
instance_ptr = gtk_classname_new();
==> instance = GtkClassName()
Example of method call:
gtk_container_remove(widget, child);
==> widget.remove(child)
in general:
gtk_classname_methodname(instance, ...)
==> instance.mothodname(...)
exceptions: signal_connect is shortened to connect:
gtk_signal_connect(button, "clicked", button_cb)
==> button.connect("clicked", button_cb)
* hello world
Here's the ubiquitous "Hello, World!" program. In it we:
o import the gtk namespace. This also initializes the Gtk runtime.
o create a callback function that will be called when a button is clicked
o create a window to place our widgets in
o connect the window's "delete-event signal to the mainquit() function
ensuring the program exits when we delete the window
o create a button widget and add it the the window
o connect the hello_cb() function to the buttons "clicked" signal
o show the window and all its child widgets
o enter the Gtk mainloop to wait for events (signals)
from gtk import * #this imports and initializes gtk
def hello_cb(*args): #callback function; called when
print "Hello World!" #our buttons "clicked" signal is sent
window = GtkWindow() #a toplevel window by default
window.connect("delete-event", mainquit) #we want to quit the application
#when we close this window
button = GtkButton("Hello, World!") #button with a label
button.connect("clicked", hello_cb) #connect the hello_cb to the buttons
#"clicked" event
window.add(button) #add the button to the window
window.show_all() #show the window and all its children
mainloop() #enter gtk's event loop
This is the general structure of an event driven GUI app: we first
create the objects to show on the screen, add them to a toplevel
window, show them, and then enter the event loop. Everything else is
done through callbacks that are triggered by either user or system
events such as mouse clicks, the drawing of a window on the screen, or
a preset timer signal.
Notes: *args in the parameter list of hello_cb "captures" everything passed
to hello_cb in a tuple. In this particular case the button
instance is passed when the "clicked" signal occurs. We
ignore it here.
If in doubt about the parameters passed to a callback, try
using the *args parameter and printing the args tuple.
If we don't quit when the windows "delete-event" signal is emitted,
the mainloop will continue to run after the window is deleted.
The only way to stop it is to kill the process.
GtkWindow and GtkButton inherit the connect() method from GtkObject,
the root of the Gtk class tree.
GtkWindow inherits the add() method from its ancestor GtkContainer.
It inherits the show_all() method from its ancestor GtkWidget.
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]