You are on page 1of 10

GUI apps in Python Simple, Effective and Robust

Vishal Sapre vsapre80@gmail.com June 10th 2011

Agenda

Introduce the user to a simple way of creating effective and robust GUI apps in Python. Presentation proceeds as:

Briefing about self. The usual GUI creation paradigm The Traits GUI creation paradigm The libraries used Walk through of an example Q&A

The usual GUI creation paradigm


Create layout using a designer


Write code for handlers and data model. Bind/Expose the GUI controls and handlers to each other. What if data model changes with time...

Scientific Computing...
Changing Visualization layouts is HARD !!!

What if customer requirement change often... What if same data model needs to be shown differently to different audiences... Fork apps ??

Introduction to Traits

TraitsUI based demo app


Traits:
A Python component library from Enthought Inc www.enthought.com Available as part of Enthought Tool Suite or Enthought Python Distribution A 'trait' is a type definition that can be used for normal Python object attributes, giving the attributes some additional characteristics:
Initialization, Validation, Deferral, Notification, Visualization

TraitsUI
Handles UI creation and back-end rendering

Traits and related stuff is under a permissible license.

Introduction to TraitsUI

TraitsUI follows the 'MVC' pattern closely:


M = Model
Represents the data elements and their behavior of some aspect of your solution. Does not have any inherent visualization criteria

V = View
The visual aspect of your solution Needs to be 'connected' with the data that it 'shows'

C = Controller
The executive component that connects & controls information flow between Model & View(s) Sometimes part of the Model, but recommended to be different.

The 'Traits' GUI creation paradigm

Focus on the data model


An object with any 'traits' defined, is a model !!!

Create UI's separately


Specify UI using 'View'objects

Use Traits and TraitsUI infrastructure to stitch the above. For a traits based app, the view comes almost for free !! React quickly to changing requirements. Geared towards Scientific Computing community. More focus on productivity than nicety of look-&-feel.

10000 feet view of a 'Traits' based App


Application
from enthought.traits.api import * from enthought.traits.ui.api import *

Traits

TraitsUI

WxWidgets

Qt

Walkthrough of the demo app

Focus on the class definitions that contain all the data Focus on how they are nested

Focus on how the final view is created.

Resources

http://python.mirocommunity.org/video/1788/pyohio-2010-gui-tools

Q&A

You might also like