A simple wxPython image viewer

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:


Installing the NVIDIA driver for multiple kernels

December 1st, 2011

I know it is totally obvious, but I never tried to figure out how to build the NVIDIA driver for more than one kernel. I always just reinstalled it and assumed it has to be that way. As it turns out I was wrong. With the -k switch you can build the driver for any not-running kernel:

sh NVIDIA-Linux-x86-280.13.run -K -k -a

-K builds only the kernel module and does not uninstall the current driver

-a accepts the license

-k is the uname -r output of the kernel to build (you can also use the name of the directory in /lib/modules)

Rebooting via dbus

November 13th, 2011

If you ever wondered how your window manager can shutdown or reboot your computer without asking for a root password, then the most likely answer is dbus.

This command will reboot a machine running dbus:

dbus-send --print-reply --system --dest=org.freedesktop.Hal \
/org/freedesktop/Hal/devices/computer \

You can replace “Reboot” with “Shutdown” to power off the machine completely.

Setting up us_de keyboard layout on Slackware 13.37 and Ubuntu

September 19th, 2011

It’s been some time since I talked about my us_de Keyboard layout (and a long time since I last blogged ;)) so I think it is time to update the installation instructions. You can download the layout here: us_de keyboard layout.

To set it up on Slackware do the following:

  1. Save the us_de file to /etc/X11/xkb/symbols/
  2. Copy 90-keyboard-layout.conf from /usr/share/X11/xorg.conf.d/ to /etc/X11/xorg.conf.d/
  3. Take a look at the example and change the line Option “XkbLayout” “us” to Option “XkbLayout” “us_de”
  4. Save it and restart X :)

For Ubuntu you can find all the information there: http://people.uleth.ca/~daniel.odonnell/Blog/custom-keyboard-in-linuxx11

The short version:

  1. Save the us_de file to /usr/share/X11/xkb/symbols/
  2. Edit /usr/share/X11/xkb/rules/evdev.xml and add a block like this to the <layoutList>section:
  3. Then go to System->Preferences->Keyboard and klick on the Layouts tab.
  4. There click “Add”.
  5. Pick “By language”
  6. Set “Language” to “English” and “Variants” to “USde”.
  7. Click on “Add”
  8. Then remove your old layout (or move USde up as frist choice)

So much for easy to use eh ;)

Have fun with my layout!


Firefox middle mouse button on Linux

January 31st, 2010

I noticed that firefox did *something* when clicking the middle mouse button without hovering a link. I finally found out what it did and how to disable it:


So setting middlemouse.contentLoadURL to false keeps firefox from trying to load the current clipboard content.

Remapping mouse buttons

May 31st, 2009

Yesterday I got a new mouse. A Logitech G5. Being a nice mouse overall it has a small little flaw: clicking the mouse wheel is not that easy because you can click it in three ways. Down and from left and right.

As I frequently use the middle mouse button I was not happy (because it often misinterpreted a click for a wiggle-left). As a geek I thought: wiggling the mouse wheel to the left is even easier than clicking on it. I would no longer have to lift my finger off the left mouse button. The question was: How can I remap this 7th mouse button?

After some research I found it was very easy to remap the button.

First you have to correctly configure the mouse in your Xorg configuration file:

Section "InputDevice"
Identifier "Logitech G5"
Driver "evdev"
Option "CorePointer"
Option "Device" "/dev/input/by-id/usb-Logitech_USB_Gaming_Mouse-event-mouse"
Option "ZAxisMapping" "invert"
Option "Emulate3Buttons" "false"
Option "Buttons" "9"
Option "Resolution" "800"

(My thanks go to chuck)

From there it took a bit more research to learn that I can use xmodmap  to easily remap the mouse buttons:

xmodmap -e "pointer = 1 7 3 4 5 6 2 8 9"

Remaps button 7 into the poistion of button 2 ( mouse- wheel-click). For more information visit the very good tutorial by HP.

Now I just had to put the “pointer = 1 7 3 4 5 6 2 8 9” part into a file into my home directory (surprisingly called .Xmodmap) and let Fluxbox execute it at startup.

Now I just have to get used to other mice not worknig like that ;-)

Mapping postal codes to countries

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 :-)


Connecting two monitor to a NVIDIA card without the proprietary driver

November 16th, 2008

For a long time I searched for a way to connect two monitors to an NVIDIA graphic card without using the proprietary nvidia driver (mainly because I wanted to try use OpenBSD and 64bit FreeBSD).

Somehow I never read nv’s (the free Xorg driver) man page – until today. And there it is, clear as crystal:

Option "Dualhead" "boolean"
    Enables simple VBE-based dual head mode.  This sets the same resolution on both outputs and lays them out
    side-by-side.   The screens will be panned together as one big metamode if the virtual desktop is larger than both
    screens combined.

So I just had to change my Xorg config from:

Section "Device"
    Identifier     "Card0"
    Driver         "nvidia"
    Option        "TwinView"


Section "Device"
    Identifier     "Card0"
    Driver "nv"
    Option	"Dualhead"

So simple!

Ken Thompson on Security

July 11th, 2008

I just stumbled on a very good article by Ken Thompson on computer security:

Reflections on Trusting Trust

In this article Ken shows how easy it is to alter a compiler  to compromise all binaries created with it. Although 24 years old this article is a very interesting read.

us_de Keyboardlayout

July 10th, 2008

The more I used it, the more unhappy I became with the us-intl keyboard layout. Especially all the dead keys (keys that may modify the following key e.g. ” + a to write ä) made typing tiresome. Always typing a space after double quotes is really not suited for programming.

I found a good tutorial on writing your own Xorg keyboard layouts:
Creating custom keyboard layouts for X11 using XKB

Using these instructions I created a us_de layout, that uses the us layout and bind alt + a/u/o/s to the german  umlauts ä/ü/ö/ß.

To install the file, just copy it to /etc/X11/xkb/symbols/ and edit your /etc/X11/xorg.conf (or type setxkbmap -layout us_de -variant basic into a shell): us_de