Difference between revisions of "PyGTK"

From Projects Wiki
Jump to: navigation, search
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>
Supposedly you should use the GtkBuilder file format over Libglade. With that in mind...<br>
+
I am using Glade to create the gui. pygtk is well documented; glade is not.<br>
{| class="wikitable"
+
For starters, supposedly you should use the GtkBuilder file format over Libglade. Many instructions on the web are for Libglade.
! scope="col" | Loading a glade file into a python program
+
==Loading a glade file, hooking up event handlers, and displaying a window==
|-
+
<source lang="python">#Load the file
|<pre>import gtk
+
import gtk
 
gladefile = 'app.glade'
 
gladefile = 'app.glade'
 
builder = gtk.Builder()
 
builder = gtk.Builder()
builder.add_from_file(gladefile)</pre>
+
builder.add_from_file(gladefile)
|}
 
  
 +
#Connect callback handlers
 +
handlers = {}
 +
handlers['button_clicked_cb'] = buttonclickedfunction
 +
builder.connect_signals(handlers)
  
But first you have to create the glade file. Create a window and divide it with boxes<br>
+
#Display the window
 +
window = builder.get_object('mainwindow')
 +
window.show_all()</source>
  
==ComboBox==
+
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.<br>
 +
==Actions==
 +
What are actions for? Do they let me configure a button to launch a file dialog?
 +
==Toplevels==
 +
{| class="wikitable"
 +
! scope="col" | widget
 +
! scope="col" | glade
 +
! scope="col" | python
 +
|-
 +
| Window
 +
| Make an empty window
 +
| <source lang="python">window = builder.get_object('windowname')
 +
window.show_all()</source>
 +
| 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==
 
{| class="wikitable"
 
{| class="wikitable"
! scope="col" | glade side
+
! scope="col" | widget
! scope="col" | adding items, pygtk side
+
! scope="col" | glade
 +
! scope="col" | python
 
|-
 
|-
 +
| ComboBox
 
|
 
|
 
*Create a ListStore for the model
 
*Create a ListStore for the model
Line 24: Line 53:
 
**Set the model to the ListStore
 
**Set the model to the ListStore
 
**Right click the ComboBox in the widget tree and click Edit
 
**Right click the ComboBox in the widget tree and click Edit
***On the Hierarchy tab, click add. 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
| <pre>
+
| <source lang="python">builder.get_object('comboboxname')</source>
 
|}
 
|}

Revision as of 03:38, 11 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
builder.get_object('comboboxname')