Difference between revisions of "PyGTK"

From Projects Wiki
Jump to: navigation, search
(Control and Display)
 
Line 1: Line 1:
 
PyGTK is loads better than TKinter.  There are far more events to work with which let you make a more responsive, convenient, and concise interface.<br>
 
PyGTK is loads better than TKinter.  There are far more events to work with which let you make a more responsive, convenient, and concise interface.<br>
 
I am using Glade to create the gui. pygtk is well documented; glade is not.<br>
 
I am using Glade to create the gui. pygtk is well documented; glade is not.<br>
For starters, supposedly you should use the GtkBuilder file format over Libglade. Many instructions on the web are for Libglade.
+
For starters, supposedly you should use the GtkBuilder file format over Libglade. Many instructions on the web are for Libglade.<br>
 +
holy crap, there's gtk 3, it's buried beneath a lot of gtk 2 documentation on the internet. But it's so much better.
 +
<br>But... it seems to require python 3, which I'd like to use but there are some issues with that.<br>
 +
Fortunately, the only thing I know of that doesn't work are comboboxtext widgets, which are convenient but don't add anything new.<br>
 +
Also, apparently, gtk 3 is not so widespread, particularly on Windows, which will be the main platform for the program I'm making.
 
==Loading a glade file, hooking up event handlers, and displaying a window==
 
==Loading a glade file, hooking up event handlers, and displaying a window==
 
<source lang="python">#Load the file
 
<source lang="python">#Load the file
Line 58: Line 62:
 
***Set the Text property to the column you want displayed from the ListStore
 
***Set the Text property to the column you want displayed from the ListStore
 
| <source lang="python">cb = builder.get_object('comboboxname')
 
| <source lang="python">cb = builder.get_object('comboboxname')
activeiter = cb.get_active_iter()</source>
+
cb.get_active_text()</source>
 
|-
 
|-
 
| Treeview
 
| Treeview

Latest revision as of 03:12, 15 June 2013

PyGTK is loads better than TKinter. There are far more events to work with which let you make a more responsive, convenient, and concise interface.
I am using Glade to create the gui. pygtk is well documented; glade is not.
For starters, supposedly you should use the GtkBuilder file format over Libglade. Many instructions on the web are for Libglade.
holy crap, there's gtk 3, it's buried beneath a lot of gtk 2 documentation on the internet. But it's so much better.
But... it seems to require python 3, which I'd like to use but there are some issues with that.
Fortunately, the only thing I know of that doesn't work are comboboxtext widgets, which are convenient but don't add anything new.
Also, apparently, gtk 3 is not so widespread, particularly on Windows, which will be the main platform for the program I'm making.

Loading a glade file, hooking up event handlers, and displaying a window

#Load the file
import gtk
gladefile = 'app.glade'
builder = gtk.Builder()
builder.add_from_file(gladefile)

#Connect callback handlers
handlers = {}
handlers['button_clicked_cb'] = buttonclickedfunction
builder.connect_signals(handlers)

#Display the window
window = builder.get_object('mainwindow')
window.show_all()

But first you have to create the glade file. Create a window and divide it with boxes and then put widgets in each panel and widgets within those widgets as needed.

Actions

What are actions for? Do they let me configure a button to launch a file dialog?

Toplevels

widget glade python
Window Make an empty window
window = builder.get_object('windowname')
window.show_all()
FileChooserDialog
  • Click and create it
  • Add cancel and ok buttons
  • Add a combobox for filtering files or an entry box for entering a filename, or both or neither
  • You can set Response ID for the buttons to know which was clicked
  • How do you get the file selection back?
 ???

Control and Display

widget glade python
ComboBox
  • Create a ListStore for the model
    • Add a column to the ListStore on the General tab. gchararray for strings
  • Create a ComboBox
    • Set the model to the ListStore
    • Right click the ComboBox in the widget tree and click Edit
      • On the Hierarchy tab, click add to insert a Cell Renderer. Name it whatever.
      • Set the Text property to the column you want displayed from the ListStore
cb = builder.get_object('comboboxname')
cb.get_active_text()
Treeview

(ListStore)

  • Place inside a viewport to give it a nice-looking border
  • Set TreeView Model to a ListStore or TreeStore. Add at least one column to the Store
  • Right-click>edit the TreeView and add at least one column on the Hierarchy tab
    • Right-click each column in the Hierarch list and "Add child text", for text at least
      • Set the Text property of the child text to the