No Huddle Offense

"Individual commitment to a group effort-that is what makes a team work, a company work, a society work, a civilization work."

Generating Tkinter GUIs from XML

April 20th, 2011 • 1 Comment

Update: Please also see this post!

Sometimes I just need to develop some GUIs for testing and demos. For 80% cases I hack those kind of codes in Python so Tkinter is the best choice there. Pretty old school – I know 🙂

I would recommend Qt (using PySide or PyQT) for bigger GUI projects but for interoperability (Tkinter is part of the python download and runs everywhere :-)) issues and development speed I still choose Tkinter most of the time 🙂

What bugged me was the amount of code needed to create a simple GUI. Especially defining the GUI itself in a programming language is a pain – so why no split those things? Defining the GUI in an XML file and just use python to bind some operations behind it…An old blog post here describes this using Tkinter. So a peace of cake (esp. with Tkinter). I made some slight modifications (Support for frames in frames in frames etc.; grid geometry manager instead of pack manager; minor improvements on the XML side etc.) and now you can write a simple XML file like this:

<?xml version="1.0" encoding="UTF-8"?>
    <LabelFrame text='Hello World' borderwidth='2' relief='groove' column='0' row='0' columnspan='2'>
        <Label text='Entry:' column='0' row='0'/>
        <Checkbutton name='check' text='checkbutton' column='1' row='0'/>
        <Entry name='entry' bg='gold' width='30' column='0' row='1' columnspan='2'/>
    <Button name='ok' text='OK' column='0' row='1'/>
    <Button name='cancel' text='Cancel' column='1' row='1'/>

Write some simple python code so the GUI actually does something:

xml_ui = TkFromXML()
root = xml_ui.initialize('ui.xml', title = 'Some test gui...')

# config vars for checkboxes etc.
c = xml_ui.checkbox('check')
def ok():
    print xml_ui.entry('entry')
    print c.get()

# add button behaviour
xml_ui.button('ok', ok)
xml_ui.button('cancel', root.destroy)


So if ‘OK’ is pressed it will output the text inserted in the Box and the state of the Checkbox. Overall you get something like this:

Simple ain’t it? Comments more than welcome – I tend to release this on GitHub soon!

My Software Development Environment for Python

February 21st, 2011 • Comments Off on My Software Development Environment for Python

Python is my favorite programming language for multiple reasons. Most important though is that it has a strong community, a Benevolent Dictator For Life (BDFL) and allows rapid development of high quality software. I love automation of processes wherever possible because it saves time. Here is a list of tools, methodologies, stuff I use to ensure code quality:

Tools I sometimes use during the development of code:

Thinks I would like to have replacements for:

Overall I’m pretty happy with this setup and find it good for fast coding. I usually write unittests (With test for success, failure and sanity for every routine) first before starting coding. I don’t find it a time waste but actually I’m pretty sure that the overall setup allows me to code and refactor faster.

Maybe others or you (?) also want to writeup their setups and we can start a site like The Setup for Software Development? Please Retweet and share the link!

Update: Also have a look at this Python and Dtrace blog post.

OCCI and More

November 15th, 2010 • Comments Off on OCCI and More

Busy times – but this post nicely wraps up what is going on regarding OCCI!

Hudson and Python

September 23rd, 2010 • 3 Comments

Regarding Continuous Integration (CI) systems I probably still like Hudson! Great tool and runs perfectly well. Just get the latest jar file and run it with java – jar hudson.jar. Now to get started you will need to install some plugins:

You can install those plugins in he management interface of hudson. When configuring the job in hudson you simple add a new “Build a free-style software project” job. Add SCM information – and than add some build steps. I had to use two:

python clean --all
python build
coverage erase
nosetests --with-coverage --cover-package=<your packages> --with-xunit
coverage xml

And a second one:

pylint -f parseable <your packages> > pylint.txt
echo "pylint complete"

Both are external scripts. Now in the post-build section activate the JUnit test reporting and tell it to use the **/nosetests.xml file. Also activate the Cobertura Coverage report and tell it to use **/coverage.xml. Finally activate the Report Violations – and add pylint.txt in the right row.

Configure the rest of the stuff just as you like and hit the Build button. Thanks to XML the reporting tools written for java can parser the output generated for your Python project. Now you have nice reports from a Python project in Hudson!

A more detailed and great article about this topic can be found here.

Call graphs for python

September 9th, 2010 • 1 Comment

I’m a big fan of reporting be it reports form automated builds, coverages, API documents etc. To evaluate the python code I’m currently working on I needed Call Graph for Python. After some searching and testing I found this package to be most convenient:

P.S. If you are running Ubuntu (or similar) a sudo apt-get install python-pycallgraph will install the package. To create the graph simple call: pycallgraph –include=<whatever you need> <your>