Archive for the ‘programming’ Category

A simple wxPython image viewer

Sunday, December 11th, 2011

For a project I needed to display an image in a GUI. As I have used wxPython in the past, I choose to use it again. Although the toolkit is extremely simple and easy to use, I still needed some time to write this simple image viewer. The problem was, that I expected to be able to attach a wx.Image to a Sizer. It took me sometime to figure out, that I needed to turn it into a wx.StaticBitmap first.

Here is a very small and simple image viewer with wxPython, may it be of help to the internet ;)

#!/usr/bin/env python
import wx
class FooApp(wx.App):
	# called when the 'change' button is pressed
	def changeImage(self,event):
		img = wx.Image("foo.jpg")
		self.image = wx.StaticBitmap(self.panel, wx.ID_ANY, wx.BitmapFromImage(img))
	def __init__(self):
		# setup code for the window
		self.frame = wx.Frame(None, title='Demo')
		self.panel = wx.Panel(self.frame)
		# load an image
		img = wx.Image("bla.jpg")
		self.image = wx.StaticBitmap(self.panel, wx.ID_ANY, wx.BitmapFromImage(img))
		# create a Sizer to hold one (or more) button
		self.buttons = wx.BoxSizer(wx.VERTICAL)
		self.changeButton = wx.Button(self.panel, -1, "Change")
		self.mainSizer = wx.BoxSizer(wx.VERTICAL)
		# more generic setupcode
if __name__ == '__main__':
    app = FooApp()

Just for the record: here are the websites that helped me write this code:


Mapping postal codes to countries

Thursday, February 5th, 2009

Every now and again I had the problem of matching postal codes and countries. I often wondered if there is a system to (austrian) postal codes and finally found a table that says how to map a postal code to a country.

I encoded it into a simple PHP function – maybe it is useful :-)