Precisely …

For the past two months I’ve been using Fedora with Gnome Shell and it’s been great to get used to it as an interface and to become familiar with another distribution. It was like being back at home really because, prior to running Ubuntu, I’d been a RedHat user for several years. Not RHEL, but the old Red Hat Linux that existed before Red Hat went commercial.

Fedora certainly did the job for me and, apart from a few broken packages here and there, I didn’t have any problems with it. I think I always knew I would come back to Ubuntu when the final beta of 12.04 Precise Pangolin was released.

Again, an environment I’m very familiar with but one that’s now much more polished than the early days of 11.04 Natty Narwhal. It’s amazing how far Unity has come on in just a year — or 18 months if you include the 6 month development cycle for that release.

Surprisingly for this long-term support release, Ubuntu adds a new feature — the heads-up display or HUD.

I believe the long-term view is that this will replace menus. I’m not so sure about that, but it’s certainly useful. The idea is you hit the alt key, type a few characters and it will search the menus to give you a list of options you can access with keyboard or mouse.

But it’s actually more sophisticated than that description. It does fuzzy matching and also likely matches in other applications. If you look at the screenshot, I opened the gedit text editor, hit the alt key and typed “print”. Not surprisingly, it comes up with File-Print and File Print-Preview. The third option though, is the printer setup from system settings, which is feasibly something I’d want if I wanted to do some printing.

Things start to get much more interesting when you try it on your web browser. It will search menus but, because web browsers expose all sorts of things as menus, this can also mean recent tabs, history and bookmarks. It gives the browser a whole new dimension. All those bookmarks I have deeply nested in sub-menus suddenly become accessible again. It also picks up on RSS feeds if you use something like Firefox’s live bookmarks so it will pick up on the latest stories you are interested in.

It’s going to take some practice to get used to using it, but it looks like a great feature.

(Reblogged from kaiserlowen)

Thinking in Python

I’m no expert with Python, but I’m enjoying learning it and using it. After what feels like a lifetime of C and Java (and more recently Objective-C), I’ve finally managed to wean myself off adding a semicolon to the end of every line of code. But’s there’s more to being Pythonic than that. I still think in C and Java and here’s an example of how:

I’ve been writing an application in Python with GTK3 and I wanted to take a block of text and normalize the indentation, i.e. preserve its indentation but take the least indented column back to column zero.

The C and Java half of my brain kicked in, it got mangled into Python, and this came out:

def common_indent(text):
    common = -1
    for line in text.splitlines():
        line_indent = indent(line)
        if line_indent == 0:
            return 0
        if common < 0 or line_indent < common:
            common = line_indent
    return common

Only when I got it working did the Python half of my brain catch up and refactor it into this:

def common_indent(text):
    return min([indent(line) for line in text.splitlines()])

Which, apart from being easier to type I think is a lot easier to read. It’s hardly worth writing it as a function any more!

So I’m finding there’s more to Python than learning the language. It’s also a matter of changing the thought process, at least for programmers used to the brace languages. Moving the other way — from Python to C, Java, C++ or C#, must feel like climbing a mountain.

Using libnotify with Python and GTK3

Now that PyGTK is on it’s way out and the Gnome world is thinking GTK3, some old ways of doing things don’t work any more. On-screen notifications using pynotify for example. I hunted around for a long time before I figured this out, but here is how to use the underlying libnotify with Python and GTK3:
from gi.repository import Notify

Notify.init('My Application Name')
notification =
        'Test notification',
Easy when you know how.

Long time no post

Well, it’s been over six months since I’ve managed to post to this blog. From August I got very busy working on a new iPhone/iPad training course and that took up most of my time until Christmas. Looking back, it was a bit like a prison sentence!

So there’s a shiny iMac on my desktop and Ubuntu sat largely disregarded as 11.10 Oneiric Ocelot came and went. When I did get round to upgrading I found myself drawn to Gnome Shell. Which is a surprise because I actually liked Unity. But a combination of problems getting Java development tools installed (Netbeans and Eclipse), Canonical’s flicking between default applications (Thunderbird and Evolution) and perhaps a desire for pastures new led me to …


It was a remarkably swift process. My laptop needed a tidy up and upgrade. I had an impulse to try a Fedora Live USB before I installed Oneric. Liked it. Did the install and spent a few hours setting it up. Then took the plunge and put it on my desktop PC as well.

Don’t get me wrong, I still like Ubuntu but I’m enjoying exploring Fedora. It feels lighter and much closer to a pure Gnome experience. Touch wood, I’ve not had any major issues so far. It’s been a fairly painless transition.

The package manager isn’t as slick as Ubuntu’s software centre or Synaptic. I use yum mostly, but then again I used to use apt-get a lot too.

Fonts looked awful, but a few tweaks got the same settings as Ubuntu - and I installed the Ubuntu font too.

Faenza and Faenza Cupertino icons to match the blueness of it all (was that a subconscious nod to the iMac next door?).

My main issue is finding a decent Twitter client. Gwibber is OK but I always thought it was a bit heavyweight for what it does. Turpial didn’t inspire me. Maybe I’ll just stick to using my Apple devices for Twitter, although I do like seeing the notifications as I am working.

Eclipse and Netbeans were easy to set up, which is just as well as I have some Java work to do over the next month.

So we’ll see how it goes. Maybe I’ll get bored with blue and revert back to purple and orange come April/May when the LTS release of Ubuntu comes out?

Checking whether a window is maximized in PyGTK

I’ve been writing an application using PyGTK recently and one of the things I wanted to do was save the window state on exit (size and whether maximized) so that I can restore the next time the application runs.

Checking whether the window is maximized proved to be more difficult than I expected and the PyGTK documentation and web searches didn’t turn up a direct answer.

The PyGTK documentation for gtk.Window suggests that the window-state-event on the gtk.Widget is the way to go but my first attempts didn’t work. I always got a widget gtkStateType of gtk.STATE_NORMAL, regardless of whether the window was maximized.

The solution is actually quite simple. Simple to do anyway, but more difficult to explain: The window state is associated with the underlying gtk.gdk.Window, not the gtk.Window widget that triggers the window-state-event. Calling get_state() on the gtk.Window is simply calling get_state() on its superclass gtk.Widget. Hence the widget state of gtk.STATE_NORMAL. To get the underlying gtk.gdk.Window you need to use the get_window() method of gtk.Widget (of which gtk.Window is a subclass) and then call get_state(). In the event handler for the window-state-event, the gtk.Window is passed through as the widget parameter (but you could also call get_window() on your gtk.Window directly):

import gtk

class WindowState(gtk.Window):

    def __init__(self):
        super(WindowState, self).__init__()
        self.connect("destroy", gtk.main_quit)
        self.set_size_request(800, 600)
        self.connect("window-state-event", self.on_window_state_event)

    def on_window_state_event(self, widget, event, data=None):
        mask = gtk.gdk.WINDOW_STATE_MAXIMIZED
	maximized = widget.get_window().get_state() & mask == mask
        print maximized


This works as I wanted, printing True when the window is maximized and False when unmaximized.

I’ve been teaching myself Python over the last couple of weeks and exploring GUI options to go with it. I always seem to end up writing text editors to check out GUI toolkits and I have more unfinished versions than I know what to do with …

… but I like this one!