Paul
Paul

Reputation: 829

Threading with PyGTK

To begin, I must say that I have searched for quite a long time on this subject and I probably know of most basic resources. I am attempting to use this: https://github.com/woodenbrick/gtkPopupNotify to add a system of notifications to a previously all command line program. Sadly, this usually will hang due to the fact that I perform lots of sleep operations, etc. I would assume it would work if I could get a system of threading in place. Essentially, all I want is to make a notification that doesn't interfere with any other operations of the program including other PyGTK components. Functions to make these notifications at the moment are looking like this for me:

    def showMessage(title, message):
        notifier1 = gtkPopupNotify.NotificationStack(timeout=4)
        notifier1.bg_color = gtk.gdk.Color("black")
        notifier1.fg_color = gtk.gdk.Color("white")
        notifier1.edge_offset_x = 5-27 #-27 for odd bugginess
        notifier1.edge_offset_y = 5
        notifier1.new_popup(title=title, message=message)

Any help would be greatly appreciated as I am becoming really fed up with this problem.

Upvotes: 3

Views: 305

Answers (1)

user626998
user626998

Reputation:

With PyGTK, I highly recommend avoiding threads altogether. The GTK libraries aren't fully thread-safe and, under Win-32, they don't support threads at all. So, trying to work with them ends up being a pain. You can get some really nice results by "faking it" using Python generators and the gobject.idle_add() method

As an alternative to coding it yourself, you can also just use Zenity, which is a Gnome program for launching notification dialogs from the command line. This should be thread-safe.

import subprocess
subprocess.call(["zenity", "--notification", "--text=You have been notified"])

Upvotes: 1

Related Questions