P e t e S a v a g e

Building GUI applications with Python, GTK and Glade R o a ma p

● Why use python? ● The Concepts ● The Tools ● Example ● Advanced ● Resources ● Questions - Gulp!! Wh y u s e P y t h o n ?

● Easy to learn ● Promotes clean, readable code ● Cross platform Linux/Windows ● Good RAD (Rapid Application Development) ● Great Documentation T h e o n c e p t s

Signal Handler “clicked”

Action to be performed T h e T o o l s

● Python – Ties everything together, handlers etc ● Glade – Designs the GUI – Sets up signals with references ● PyGTK – Interfaces between python and GTK ● GTK – for drawing and handling graphical elements Gl a d e

● Easy to create complex GUI ● Can handle linking of signals to handlers via a “dictionary” ● Can produce large-ish files Gl a d e D e s i g n e r

Toolbox

Properties

Project

GUI Preview C r e a t e a n e x a mp l e

● An application that counts each time a button is clicked ● Presents a box when the total button is clicked Wh a t h a v e w e d o n e ?

● Created example.glade file ● Created main window ● Set up initial widgets ● Tied widget signals to references P y t h o n p r o g r a m

● Import glade ● Create GUI class ● Assign signal references to handler functions ● Write handler functions E x t e n d i n g t h e p r o g r a m

● Event handlers – act as an interrupt – e.g. “Are you sure you want to quit?” T h e “ d e l e t e _ e v e n t ” s i g n a l

Further User clicks False handlers/methods the X button allowed to run program quits Any further Handler returns True handlers/methods True/False are ignored as event Class tries to dialog box effectively deleted delete widget “Do you want to quit?” program continues

“delete_event” signal Signal invokes is emitted handler

on_delete_event A d v a n c e d T o p i c s

● Creating your own widgets ● Using Drag and Drop methods ● Using treestores and liststores R e s o u r c e s

● Python website – http://www.python.org ● PyGTK website – http://www.pygtk.org ● Gnome website – http://www.gnome.org T o p i c s C o v e r e d

● Why use python? ● The Concepts ● The Tools ● Example ● Advanced ● Resources ● Questions - Gulp!! Q u e s t i o n s ?

● Questions?