Difference between revisions of "PyGTK"

From Projects Wiki
Jump to: navigation, search
(Toplevels)
(Control and Display)
Line 57: Line 57:
 
***On the Hierarchy tab, click add to insert a Cell Renderer. Name it whatever.
 
***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
 
***Set the Text property to the column you want displayed from the ListStore
| <source lang="python">builder.get_object('comboboxname')</source>
+
| <source lang="python">cb = builder.get_object('comboboxname')
 +
activeiter = cb.get_active_iter()</source>
 +
|-
 +
| 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
 
|}
 
|}

Revision as of 04:04, 14 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.

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')
activeiter = cb.get_active_iter()
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