June 16th, 2011 • Comments Off on The Power of Python & Solaris
Here is a presentation I gave today to demo the power of Python and Solaris. It’s about creating a fictitious service similar to no.de or Google App Engine but with Python & Solaris. Warning: contains OCCI and DTrace!
April 26th, 2011 • Comments Off on Build Python with custom TCL/TK libs
Issue with my Solaris installation is that it has slightly older TCK/TK libs. Since I’m currently playing around with some Tkinter stuff and python I needed a newer version to test the TreeView and Notebook widgets for example.
Here is how yo can get Python 2.7.1 up and running against TCL/TK libs which are not system wide installed:
# Switch to TCL directory
# Switch to TK directory
./configure --prefix=<some_path> --with-tcl=<some_path>
# Switch to Python source directory
Please note the following:
April 21st, 2011 • 2 Comments
- <some_path> needs to be the same in all calls
- you need to set the LD_LIBRARY_PATH before calling the configure script in the Python source directory
Source available on GitHub…
Yesterday I posted something about creating Tkinter based GUIs via an XML. Thanks to python and all its build in features (like JSON support) it was a piece of cake to rewrite it an now you can create Tkinter GUIs from a JSON definition. Just a few lines (ca 25 lines needed to be changed) later and this request was fulfilled:
To create the same GUI as in the last post the JSON file should look like:
And for sure: the sample code from yesterday – didn’t change 🙂 Again: you gotta love python! And right now the JSON UI definitions are nicer so I might follow this approach for the future.
Also nice about this approach is that within the JSON or XML file you define everything for the Tkinter widgets. Every value of the configuration of an Tkinter widget can be defined in the files. For example all these values could be put in the file for the ‘Entry’ Tkinter widget. Nice ain’t it?
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')
# add button behaviour
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!
April 2nd, 2011 • Comments Off on Fun with Joyent’s Node.js cloud analytics
Since Joyent release their no.de service I wanted to give it a try. Especially since they added an analytic feature based on DTrace which is described in all details here: Joyent’s wiki. Also nice is this blog post.
So I was tempted to play around with both for a while now. Finally I came up with the idea of drawing words in the analytics panel of the no.de service. Just like a stock exchange ticker with some scrolling test.
So I wrote a simple server.js which responses to different HTTP method (POST, PUT, GET, DELETE, HEAD) request with different latencies. I created an instrumentation in the cloud analytics panel of the no.de service for HTTP server operations (method) over latency. Now only thing left was to write some python code to execute concurrent HTTP requests using different HTTP methods. So 5 concurrent requests with HTTP GET, POST, PUT, DELETE and HEAD would result in vertical 5 dots. 3 concurrent request with HTTP HEAD, PUT and GET in 3 vertical dots with some space between them. I guess you get the picture.
Here are some screenshots:
Hardest part was to figure out the right values for the latencies. Took a while to figure out those who printed the nicest characters without too many ‘drawing erros’.