Archive for February, 2009

Python and GTK

February 16th, 2009 Comments off

In my ongoing quest to learn python, I’m writing my first real GUI application since I was traumatized by dealt with swing and Java at university. Since I’m a GNOME user, I’ve gone with GTK. In the past day or two, I have learnt the following;

  1. Use glade for designing your interfaces. Do not pass go, do not attempt to play with direct gtk calls directly, just use glade. It’s far less frustrating, and means you will have something that actually, you know, does something, sooner than later, thus keeping you interested and motivated.
  2. When you dynamically generate a widget, such as another tab, it is imperative that you call show() on this widget, as the code snippet below illustrates.

tabs = self.wTree.get_widget('tabsholder') # tabsholder is the GtkNotebook
foo = gtk.Label("Tab text")
tabs.append_page(foo, gtk.Label("Label text"))

That last line is really important, otherwise the code will run without error, but nothing will actually happen.

Big sigh.

Python and custom Exception classes – Namespaces required

February 9th, 2009 1 comment

Having just spent the last three days fighting with python and it’s handling of custom exceptions, I thought I’d document the problem here for other people who trip over the same problem. Call it document-as-you-fail learning. In hindsight, it’s kind of obvious what’s happened, but it’s just slightly frustrating in the meantime.

Let’s say you’re writing a project called Ripley. In the process of writing this, you spin the reusable code into a nice library, which you then import into your CLI or GUI program like so;

import ripley

Everything works great. Then one day you decide you need some exception code for an internal error. You rock on over to the website, and copy in their example code. Maybe you having something like this in your library.

class RipleyError(Exception):
	def __init__(self, ivalue):
		Exception.__init__( self, ivalue )
		self.value = ivalue
		print "RipleyError Raised!"
	def __str__(self):
		return self.value

This is supposed to be called with something like this;

class session:
	def go():
		raise RipleyError("I'm testing out my error class.")

In your main program in a file called you have something like this;

print "Starting."
session = ripley.session(server)

except RipleyError, ex:
	print "A RipleyError was raised %s" % ex
	print "Failed with non-specific error"
	print "No error raised."
	print "Last thing."

*Deep breath*

You run the program, and the following happens;

edward@entropy:~/working/libmedusa-python$ python ./
RipleyError Raised!
Last thing.

Hang on, the error has been raised, but it’s not being located when you call except on it?

As it turned out, the problem lay in the name space of the two files. The ‘fix’ is to attach the appropriate namespace to the Exception class, like so;

except ripley.RipleyError, ex:
	print "A RipleyError was raised %s" % ex

The problem is that python appears not to be too perturbed that it’s being asked to check for an Exception class that does not in fact, exist.

Update: My preview is horribly horribly broken.

Categories: Tech Tags: ,

Libertarians and use of Financial Violence

February 4th, 2009 1 comment

I have issues with the concept of Libertarians. Specifically, I have issues with what Wikipedia calls Classical liberalism, that stresses laissez-faire free markets, and the liberty to do whatever the hell you want as long as you don’t physically infringe on anyone else’s personal liberty. To further clarify, if you are of the stance that the governments should be stripped down to police and defence, I’m talking about you. If you feel that you are a libertarian to whom the above description does not apply, then blame the often fuzzy nature of social movements and political stances.

The problem with the libertarian stance is that it is based wholly out of selfish motives masquerading as taking the moral high ground. It seeks to marginalize the less well off members of society for the purposes of financial gain via the destruction of social services, under the veil of so-called ‘liberty’.

Loosely speaking, the concept of social services fall into two categories; Natural monopolies where it is impossible to police free riders – such as roads, and social services that attempt to further society as a whole, such as providing a safety net to those who have suffered a physically or medically in some way, providing a basic education to ensure a certain level of participation, and so on. The net effect of this is that society as a whole moves forward, and those who don’t quite manage to move forward at the same rate don’t get mangled in the process.

The libertarian seeks to do away with all of the second set where they perceive it to interfere with right to pursue happiness, while keeping those that could conceivably be used to interfere with theirs. Notably, they seek to retain the comforts of controls against physical violence, while removing all controls that currently prevent them from pursuing financial coercion against anyone else. Price fixing, deliberate monopolization, and predatory market behaviour is now de-facto encouraged to stay ahead.

Of course, if you happen to be one of the few who already wield a significant chunk of financial power – the same few, who incidentally, seem to be the biggest proponents of this system – then this all works to your advantage.

The concept that every person has the right to pursue happiness – as long as it does not impact the right or ability of others to do the same – is basically sound. The problem is that it’s been co-opted by the might-is-right brigade to give them an apparent moral reason for being on top, and incidentally, why they should stay there via the means of legalized financial violence.

Categories: Life Tags: , ,