You are not logged in.

#1 2007-12-09 05:30:39

buttons
Member
From: NJ, USA
Registered: 2007-08-04
Posts: 620

[SOLVED]pynotify and libnotify frustrations

I've found working with notify incredibly frustrating.  I have a python program that puts a button on notify, but if you don't stick a gtk.main() right after showing it, the actions won't have any effect.  If the popup times out, guess what?  Stuck in gtk.main().

So I made it a link instead.  Except, I use a dark theme and the link colours are #0000FF.  Does anyone know it is possible to change this?  I had a look through the libnotify source, and the pynotify source, and I can't even figure out where it decides what tags are parsed.  The ugly blue nonsense has to come from SOME where.

And before anyone asks, I've tried the usual GtkHtml::link-color settings in my gtkrc, but libnotify conveniently ignores them.

If someone has a fix for either of these issues I would gladly use either implementation.

Last edited by buttons (2007-12-10 00:27:03)


Cthulhu For President!

Offline

#2 2007-12-10 00:33:34

buttons
Member
From: NJ, USA
Registered: 2007-08-04
Posts: 620

Re: [SOLVED]pynotify and libnotify frustrations

I found it!  After a good code trawl (and a look at several themes from libnotify), I found most of them rely on libsexy to parse markup and use sexy_url_label to put the results in the notify boxes.

So, in sexy_url_label.c from libsexy, I found the line:

680        g_string_append(priv->temp_markup_result,
681                    "<span color=\"blue\" underline=\"single\">");

Why?  WHY?

Needless to say you can change this to whatever you want, recompile, and away you go.

EDIT: I have a PKGBUILD if anyone wants.

Last edited by buttons (2007-12-10 00:48:12)


Cthulhu For President!

Offline

#3 2007-12-10 00:38:12

buttons
Member
From: NJ, USA
Registered: 2007-08-04
Posts: 620

Re: [SOLVED]pynotify and libnotify frustrations

Aaand here's what it looks like:

200712091934591280x1024qd4.th.png

With green.


Cthulhu For President!

Offline

#4 2007-12-10 04:27:42

iphitus
Forum Fellow
From: Melbourne, Australia
Registered: 2004-10-09
Posts: 4,927

Re: [SOLVED]pynotify and libnotify frustrations

There's gotta be a better way than that though, try filing a bug or contacting the pynotify developers. I do remember there being some 'loop_once' sorta functions for the gtk main loop, so maybe those would work.

hackish, yeah, but beats patching libsexy.

Last edited by iphitus (2007-12-10 04:28:08)

Offline

#5 2007-12-10 15:11:57

buttons
Member
From: NJ, USA
Registered: 2007-08-04
Posts: 620

Re: [SOLVED]pynotify and libnotify frustrations

Yes, gtk does have a run-once kind of thing, and it's gtk.main_iteration().  Unfortunately, that doesn't work.

Since main_iteration() runs nigh-instantaneously, I made a timeout call it, to "check if there are events waiting," as it were.  Clicking the button, however, does nothing.  It really only seems to work if you put gtk.main() after it and set the timeout to 0 and force the user to make a decision.

I could make a timeout wait some length of time and kill gtk.main() automatically, but this screws the user that can't make a decision.  Since notify conveniently pauses the timer while the user's mouse is over the notification, I have no way of knowing when the notification is actually going to disappear.  It does emit a signal (closed), but again, signals are handled by gtk.main.

EDIT: Solution below.  Was obvious the minute I wrote that last line here...

Last edited by buttons (2007-12-10 15:24:45)


Cthulhu For President!

Offline

#6 2007-12-10 15:26:54

buttons
Member
From: NJ, USA
Registered: 2007-08-04
Posts: 620

Re: [SOLVED]pynotify and libnotify frustrations

Finally.

The solution is easy, connect the 'closed' signal to something that kills gtk.main().

    def notify(self, title, message):
        """Show notification, adding a buy link"""
    
        init('sac.py')
   
        a = Notification(title, message, gtk.STOCK_DIALOG_WARNING)
    
        a.set_urgency(URGENCY_LOW)
        a.set_timeout(TIMEOUT)
  
        a.connect('closed', self.destroy)

        a.add_action('buy', 'Buy this item', self.open_site)
        a.add_action('default', 'Default Action', self.destroy)

        a.show()
        gtk.main()

    def open_site(self, n, action):

        subprocess.Popen([BROWSER, WEBSITE])

    def destroy(self, n, action=None):

        gtk.main_quit()

Now no matter what, destroy gets called and it will safely escape gtk.main() without any timing tricks.

Last edited by buttons (2007-12-10 15:31:56)


Cthulhu For President!

Offline

Board footer

Powered by FluxBB