Fork me on GitHub

Sunday, January 27, 2013

Wanda The Fish in Ubuntu Unity (Precise 12.04)

When I upgraded my Ubuntu OS to 12.04 I was really really happy at the way things were. The new interface is a huge improvement over the old Gnome environment. And the launcher is such a brilliant idea it makes you wonder why it took so long for someone to come up with it. But I was missing a rather fun little applet- Wanda The Fish was gone. So I decided to do what all Linux users do and wrote it myself.

I have used  GTK+  with Python to access the fortune database and display fortunes. (I didn't like the Indicator-fish port because of the absence of a "Speak Again!" button.) The code for resurrecting good old Wanda is hardly a page long. Here it is.

Code:


#!/usr/bin/env python
from gi.repository import Gtk
import os


class Wanda(Gtk.Window):

    label = None

    def __init__(self):
        Gtk.Window.__init__(self, title="Wanda The Fish Says...")
        self.set_default_size(700,300)
        self.label = Gtk.Label()
        self.label.set_line_wrap(False)
self.label.set_justify(Gtk.Justification.CENTER)
self.display_fortune()                             #first fortune when it starts up.
        self.set_icon_from_file("wanda.jpg")
     
        table = Gtk.Table(1, 2, True)
        table.set_row_spacings(200)
        table.set_col_spacings(50)
self.add(table)

        button1 = Gtk.Button(label="Speak Again!")
        button1.connect("clicked", self.on_button1_clicked)

        button2 = Gtk.Button(label="Enough Wisdom for Now!")
button2.connect("clicked", self.on_button2_clicked)

table.attach(self.label,0,1,0,1)    
        table.attach(button2, 1, 2, 1, 2)
        table.attach(button1, 0, 1, 1, 2)
     
    def on_button1_clicked(self, widget):
         self.display_fortune()

    def on_button2_clicked(self, widget):
self.display_fortune()
        self.iconify()
 
    def display_fortune(self):
      os.system("fortune -a > .last.txt")
       with open(".last.txt") as f:
        text = str(f.read())
self.label.set_label(text)
self.resize(700,300)    
   
win = Wanda()
win.resize(700,300)
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()



You could make it a Start up application and then lock it to the launcher. Wanda will continue to swim on our desktops peacefully for many years to come.
For complete instructions follow this link to github:
Wanda