Thursday, 19 November 2009

regex saves the pyqt day

I'm developing openmolar on Ubuntu Karmic, and that creates some backwards compatibility issues for hardy, intrepid and jaunty with code generated by pyuic4.

so I have to make some substitutions, and that's where regex comes in.
the python regex module is "re", and I am using a few of it's features here. Anyways, I'll let the code speak for itself.

the problem is to turn generated code like this (on pyqt 4.6 where native python integers are acceptable)
spinBox.setProperty("value", 8)
progressBar.setProperty("value", 10)
randomWidget.setProperty("value", 260)
into this....
spinBox.setProperty("value", QtCore.QVariant(8))
progressBar.setProperty("value", QtCore.QVariant(10))
randomWidget.setProperty("value", QtCore.QVariant(260)
Here's one way to do it...
import re

matches = re.finditer('setProperty\("value", (\d+)\)', data)
for m in matches:
    data = data.replace(m.group(), "QtCore.QVariant(%s)"% m.groups()[0])

my script for compiling any qt-designer generated ui files into python code can be found here the above code is in lines 38 - 48.

Sunday, 1 November 2009

Using an mdiArea in PyQt


I am adding a notifications area to openmolar, and experimenting with an mdiArea for this.
I couldn't find a nice python (PyQt) example on the web, so offer this for google's sake.
import sys
from PyQt4 import QtCore, QtGui

app = QtGui.QApplication(sys.argv)

mdiArea = QtGui.QMdiArea()
mdiArea.show()

labels = []

for i in range(5):
    labels.append(QtGui.QLabel())
    labels[i].setText("hello world")
    mdiArea.addSubWindow(labels[i])
    labels[i].show()
    
mdiArea.cascadeSubWindows()

sys.exit(app.exec_())

Monday, 5 October 2009

Internationalising Openmolar


I was approached by 2 fine gents who offered to translate OpenMolar.

Firstly Ariel Cornejo offered a Spanish translation, closely followed by Philippe Le Toquin who offered a French Version.


Anyways, the experience has been 100% positive. Lots of fun, and valuable learning again. The Gnu Gettext stuff, and the Launchpad translation facilities are very well thought out. Ditto Python's own implementation of such tools.


The screenshots to the right show the application
switching into French Mode.

Tres bon, n' est ce pas??


I'll do a technical write up on what I learned in doing this over on the openmolar wiki.

Sunday, 20 September 2009

OpenMolar on the Ubuntu-uk podcast

This week I was interviewed by the ubuntu loco team for the ubuntu-uk podcast.
I was totally overwhelmed (as I always am when in the company of REAL nerds/geeks), but they were kind to me, and their editing skills have produced some audio of which I am proud to be a part of.

The ubuntu-uk podcast is a professional and highly regarded podcast within the linux community and beyond. What an honour! I have already had lots of interesting feedback.

If you haven't heard the podcast, choose on of these formats.

Many thanks to Alan, Daviey, Ciemon, Daviey, Tony and Laura.

Wednesday, 2 September 2009

OpenMolar - screencast

ok.. I finally got around to doing this. A 15 minute intro to openmolar.

http://tinyvid.tv/show/1174zh4v3sldz

as an aside... A note about tinyvid.tv.

I didn't use youtube because they have a 10 minute restriction on length.
Trawling the web, I came across tinyvid via floss manuals... there is some seriously good community content on there (Stallman vids etc..)... and all the content is ogg.

Putting content onto Tinyvid is a wonderful experience, from start to finish.
It accepted my launchpad page as openID. Uploaded the video without fuss, and even transcodes non-ogg content into ogg "in the cloud".

I hope they are around for a long time to come. I tried to leave a donation, but couldn't see how to do that.

Hope you enjoy the video. Comments, as always, very welcome.

(screencast done on dell-mini9 using gtk-recordmydesktop and logitech USB headset)

Saturday, 29 August 2009

Ubuntu mysql and ssl

4 flippin' hours I have been tearing my hair out trying to force an ssl connection with mysql.
I generated keys, wrote the code, but it didn't work.

finally got it going though.
this HOW TO is the bomb.

for ubuntu swap all references to /var/db/mysql to /etc/mysql

so now you can all sniff my packets, see if I care.

Thursday, 27 August 2009

pyAppTemplate

So I've started an application to help make and deploy python apps on Ubuntu.

Here's a screencast showing it in use (version 0.2)
http://www.youtube.com/watch?v=jklX-IlXL9Y

project is at https://launchpad.net/pyapptemplate

I would love feedback as to whether this application is of interest to anyone.

Tuesday, 25 August 2009

pyAppTemplate

to get a break from programming openMolar... but to help cement what I had learned about ubuntu packaging, I started another project pyAppTemplate.

The goal of pyAppTemplate is to create a "debianisable" source tree from the get go of a project and... it works! The debs put the app onto the python path, and an executable in /usr/bin an icon into /usr/share/icons/hicolor/scalable and create a menu item.

pyAppTemplate is currently a command-line only app, (I had my first play with the getopt module to parse the command line args passed), but I intend to create a qt, gtk, wx and tkinter frontend for it... just for fun!


I quickly made 2 virgin packages... and deployed them locally.

pyAppTemplate is, of course, gplv3 code, and available at https://launchpad.net/pyAppTemplate.

I'll put a deb into My PPA soon, and create a demo of the tool in use.

Monday, 24 August 2009

Silly python lyrics....

To the lyrics of "Always on your side" by Sheryl Crow.

My pyqt apps are all boxed up and neatly put away
The qt kit with python they did bind
But we were always waiting for the license to be changed
From the LGPL, it found a place to hide
Which is a shame but now we have PySide.


why is my head full of such garbage?

Sunday, 23 August 2009

.bashrc for pythonistas

It's a great trick for creating a clean copy of a directory of python stuff, but I got sick of typing

~$ rsync -av --exclude="*~" --exclude="*.pyc" ~/tests/ ~/tested/

so I decided to add an alias to ~/.bashrc

alias rsync='rsync --exclude="*~" --exclude="*.pyc"'

works fine.

Saturday, 22 August 2009

Ubuntu Karmic alpha4 - 1st impressions

2 months before the release of Ubuntu 9.10 "Karmic Koala" (due 29th October), I am trying out the alpha 64-bit live CD on my advent 9112 laptop.

I have to tell you I am MIGHTILY impressed.

First linux distro that has recognised my rf (wireless) switch.
And palimpsest gave me a warning about my failing hard drive.
Time to run captain spinrite methinks.

My keyboard was incorrectly recognised as us... but that gave me my first look at the keyboard settings app. A thing of beauty. Dunno if that's new to karmic?
Anyways I would stake my mortgage on the keyboard layout being correct if I choose to install this to disk......

.... and do you know what? I am going to, because this just feels RIGHT.

congrats and thanks to everyone involved!

Thursday, 13 August 2009

Pylint Recursively

Not sure why I am blogging this, but I've been having a bit of fun with pylint, which checks python code for "bad smells" (ie. code which doesn't match the PEP standards).
Pylint also finds unused imports, variables etc...

I have written a little script to get only errors and scores out of pylint.
It works recursively looking for *.py scripts within a directory passed to it on the command line, or (if that is missing) within the current working directory.

Posted here in case it is of any use to anyone.

#! /usr/bin/env python
'''
this module runs pylint on all python scripts found in a directory tree
'''

import os
import re
import sys

total = 0.0
count = 0

def check(module):
'''
apply pylint to the file specified if it is a *.py file
'''
global total, count

if module[-3:] == ".py":

print "CHECKING ", module
pout = os.popen('pylint %s'% module, 'r')
for line in pout:
if re.match("E....:.", line):
print line
if "Your code has been rated at" in line:
print line
score = re.findall("\d.\d\d", line)[0]
total += float(score)
count += 1

if __name__ == "__main__":
try:
print sys.argv
BASE_DIRECTORY = sys.argv[1]
except IndexError:
print "no directory specified, defaulting to current working directory"
BASE_DIRECTORY = os.getcwd()

print "looking for *.py scripts in subdirectories of ", BASE_DIRECTORY
for root, dirs, files in os.walk(BASE_DIRECTORY):
for name in files:
filepath = os.path.join(root, name)
check(filepath)

print "==" * 50
print "%d modules found"% count
print "AVERAGE SCORE = %.02f"% (total / count)

gmail-notifier

I went trawling through synaptic to find a little app to notify me when a new piece of email arrived in my googlemail account, and found "gmail-notifier". I installed it, and decided that this was perfect for me.

however....

the project looks stale (last commit in 2007) and the project's mailing list is full of spam.

the app has IMHO two major shortcomings...
  • password is stored in plain text in a config file

  • I suspect the password is sent in the clear


I may be wrong about point number 2, I was going to ask via the mailing list, but I very much doubt anyone reads it unless they want a bigger willy or cheap pharmaceuticals.

So it looks like I will have to use the FF plug in like everybody else :(

Thursday, 23 July 2009

Sansa Clip Firmware upgrade

Just sucessfully updated the firmware on my sansa clip player following
This thread

Did not need to resort to the windows method :)

Thursday, 16 July 2009

Programming resource

Highly recommended reading, on object orientation and software design in general.

http://homepage.mac.com/s_lott/books/oodesign.html