#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0

    Notification Problem in (k)ubuntu


    Hi!
    (My OS Kubuntu 12.04 should work the same in Ubuntu )

    This code is timing out at once the first time I have clicked Next.
    Every thing works fine including the next button. The problem is when the code runs next time, then the notification is timed out at once.

    The problem is repitable,

    1. Just run this code and press Enter when told, it will show you a notification and it is timed out automatically after 5 sec. Printing "Timed out", "n.closed" and "GlibMainLoop Closed" as expected( I am printing it)

    2. Repeat 1. and see that it works.

    3. Click the Next button in the Notification. See that the "Action Next was clicked" , "n.closed" and "GlibMainLoop Closed" is printed out as expected( I am printing it).

    4.This time just press Enter and now it will not wait 5 sec to time out it will just time out. The messege in the terminal is "Timed out", "n.closed", GlibMainLoop Closed( I am printing it).

    5. Repeat 1. and now it works again, until you press Next and this chain will reapet.

    What am I doing wrong?


    Code:
    #!/usr/bin/python3.2
    
    from gi.repository import GLib
    from gi.repository import Notify
    
    import sys
    import time
    
    def next_cb(n, action, data):
       print("Action Next was clicked")
       n.close()
       print("n.closed")
       loop.quit()
    
    def closed_cb(user_data):
        print("Timed out")
        n.close()
        print("n.closed")
        loop.quit()
    
    if __name__ == '__main__':
        print("", end='\n')
        while True:
          loop=GLib.MainLoop()
          print("running")
          
          # Just for testing, stops the while loop until Enter pressed
          indata=input("Press Enter or q to quit: ")
          if (indata=='q'):
            loop.quit()
            sys.exit()
    
    
          label = "Min Notification" 
          actionlabel = "Next"
          Notify.init(label)
          n = Notify.Notification.new("Hello World!", "Testing\n" +
    	  "Testing ",None)
          n.set_urgency(Notify.Urgency.CRITICAL)
          n.connect("closed", closed_cb)
          n.add_action("Next", actionlabel, next_cb, None, None)
          Notify.Notification.show(n)
    
          loop.run()
          
          print("GlibMainLoop Closed")
          print("", end='\n')
          time.sleep(2)
    Last edited by BadOmen; February 21st, 2013 at 09:12 AM. Reason: Removed unrelevant code :)
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,709
    Rep Power
    480

    Still worse...


    It core dumps too! I clicked Next each time.

    $ python3 p.py

    running
    Press Enter or q to quit:

    Action Next was clicked
    n.closed
    Timed out
    n.closed
    GlibMainLoop Closed

    running
    Press Enter or q to quit:

    Action Next was clicked
    n.closed
    Action Next was clicked
    n.closed
    GlibMainLoop Closed

    running
    Press Enter or q to quit:

    Segmentation fault (core dumped)
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0
    Hi,
    Thanks for trying it!

    I don't get a Segmentation fault, no errors at all.

    How did you get this without a Press Enter between and no "GlibMainLoop Closed" printed?:
    Action Next was clicked
    n.closed
    Action Next was clicked
    n.closed
    GlibMainLoop Closed
    The GLib.MainLoop should have quit in the next_cb function.

    If you just skip pressing Next and do that a couple of loops, does it time out ok after 5 sec each time?

    Did it time out automatically the first loop after you run it and pressed Next? almost direct upon hitting the Enter key.(that is the problem I have had)

    Sorry for my English.. It's my second language and I'm not good at writing

    What am I doing wrong?
    Last edited by BadOmen; February 21st, 2013 at 10:44 AM. Reason: typo
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,709
    Rep Power
    480
    I would need to read more manual pages to understand your program than I'm willing to read right now.

    The output looks like something recursive takes place.

    What do you mean by "did it time out?" The notification does not close automatically if I wait longer than 5 seconds.

    I'm using up-to-date code on the current ubuntu release.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0
    Originally Posted by b49P23TIvg
    I would need to read more manual pages to understand your program than I'm willing to read right now.

    The output looks like something recursive takes place.

    What do you mean by "did it time out?" The notification does not close automatically if I wait longer than 5 seconds.

    I'm using up-to-date code on the current ubuntu release.
    As I understand it, the Notification module has a default time-out set to five sec, i.e It will close the notification without any interaction from the user.

    For me it does that and at the same time calls my closed_cb function that is connected to the close signal so it is triggered every time that the notification is closed with the x or is timed out. (so have I understood it, can't find any manuals about any signals)
    The segmentation fault is probably me not using the module in the right way, most likely the n.connection part.

    I cant find a good manual, I have just read a lot of random pages about it and put it together...

    There is a "libnotify" and then it is "from gi.repository import Notify" don't really know the differers

    If you know of a good manual page please tell me

    I understand you don't feel like spending your time on this

    thank you
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0
    I changed the n.close() to Notify.uninit() and it now work as supposed to. But it is generating warnings:
    Warning: /build/buildd/glib2.0-2.32.3/./gobject/gsignal.c:2572: instance `0x984ff78' has no handler with id `4'
    "Testing ",None)
    and this when i exit the program:
    (process:9936): GLib-GObject-WARNING **: /build/buildd/glib2.0-2.32.3/./gobject/gsignal.c:2572: instance `0x9850068' has no handler with id `8'
    I have to google some more I think
  12. #7
  13. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,709
    Rep Power
    480
    notify-send works like you suggest, with the 5 second post time,

    $ notify-send --urgency=critical hi

    I've spent a lot of time looking at the gtk+ manuals. I mostly learned that by following pages found by web search I'd get a mix of version 2 and version 3, usually version 2. Since I was using gtk+ version 3 the programs didn't work; the experience was miserable. Make sure you're using the correct manual version!
    [code]Code tags[/code] are essential for python code and Makefiles!
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0
    Thank you for spending all this time!

    The problem with notify-send is that it does not support buttons.

    I have changed a little in the code and I think I understand the code better now.

    The closed_cb is always called when the notification is closed, by time out or by clicking a button on it. So I have put the cleanup code in that function.

    I have also added a line that prints out what capabilities the notification service have, if it include actions than it support buttons.
    ['body', 'body-hyperlinks', 'body-markup', 'icon-static', 'actions']
    I now don't really think the problem is in my code but rather in Glib.

    while running the script i sometimes get this warning:
    Warning: /build/buildd/glib2.0-2.32.3/./gobject/gsignal.c:2572: instance `0x98b2ed8' has no handler with id `2'
    n = Notify.Notification.new(label, body,None)
    And sometimes when I exit the script I get this warning:
    (process:4721): GLib-GObject-WARNING **: /build/buildd/glib2.0-2.32.3/./gobject/gsignal.c:2572: instance `0x9136ed8' has no handler with id `2'
    New code:
    Code:
    #!/usr/bin/python3.2
    
    from gi.repository import GLib
    from gi.repository import Notify
    
    import sys
    import time
    
    def next_cb(n, action, data):
      print("", end='\n')
      print("Next button was clicked")
    
    def closed_cb(user_data):
      print("", end='\n')
      print("Now cleaning up in closed_cb")
      Notify.uninit()
      loop.quit()
    
    
    if __name__ == '__main__':
    
      print("", end='\n')
      while True:
        loop=GLib.MainLoop()
        print("running")
        
        # Just for testing, stops the while loop until Enter pressed
        indata=input("Press Enter or q to quit: ")
        if (indata=='q'):
          loop.quit()
          sys.exit()
    
        label = "My Notification"
        body="Testing\n Testing "
        actionlabel = "Next"
        Notify.init(label)
        
        caps = Notify.get_server_caps()
        print(caps)
        print("", end='\n')
        
        n = Notify.Notification.new(label, body,None)
        n.set_urgency(Notify.Urgency.CRITICAL)
        n.connect("closed", closed_cb)
        n.add_action("next", actionlabel, next_cb, None, None)
        Notify.Notification.show(n)
    
        loop.run()
    
        print("GlibMainLoop Closed")
        print("", end='\n')
        time.sleep(2)

    This is the manual I am using, I don't know if it's the right one.:
    Notification manual
    Finding and following manuals is not my strong side...
    Last edited by BadOmen; February 22nd, 2013 at 01:44 PM. Reason: nothing important :)
  16. #9
  17. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,709
    Rep Power
    480
    I don't know what is the question. You resolved the core dump, and I get this sort of output:


    running
    Press Enter or q to quit:

    ['body', 'body-markup', 'icon-static', 'image/svg+xml', 'x-canonical-private-synchronous', 'x-canonical-append', 'x-canonical-private-icon-only', 'x-canonical-truncation', 'private-synchronous', 'append', 'private-icon-only', 'truncation']

    p.py:42: Warning: /build/buildd/glib2.0-2.34.1/./gobject/gsignal.c:2576: instance `0x25ce560' has no handler with id `36'
    n = Notify.Notification.new(label, body,None)

    Now cleaning up in closed_cb
    GlibMainLoop Closed

    running
    [code]Code tags[/code] are essential for python code and Makefiles!
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0
    lol, I forgot to ask the question!

    I think I just have to accept does warnings, and move on

    The notification works like I want it to do on my Kubuntu 12.04 (with lots of extra libs installed), It pops up and dissapear after 5 sec or when I click "Next".

    How does the notification work now on your Ubuntu 12.10 with my script?
  20. #11
  21. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,709
    Rep Power
    480
    The message persists until I actively terminate it by clicking one of the buttons or otherwise.
    [code]Code tags[/code] are essential for python code and Makefiles!
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0
    Originally Posted by b49P23TIvg
    The message persists until I actively terminate it by clicking one of the buttons or otherwise.
    hmmm.
    hope this help then, try to add this line:
    Code:
        n.set_timeout(5000)
    like this:
    Code:
     
     .....
     n.add_action("next", actionlabel, next_cb, None, None)
     n.set_timeout(5000)
     Notify.Notification.show(n)
     ....
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0
    The loop=GLib.MainLoop() and loop.run() was on wrong places. Now with the new code, it should work better and be easy to integrate with other scripts.

    Thank you b49P23TIvg for having patience with me

    Code:
    #!/usr/bin/python3.2
    
    from gi.repository import GLib
    from gi.repository import Notify
    
    import sys
    import time
    
    def next_cb(n, action, data):
      print("", end='\n')
      print("Next button was clicked")
    
    def closed_cb(user_data):
      print("", end='\n')
      print("Now cleaning up in closed_cb")
      Notify.uninit()
      loop.quit()
    
    
    if __name__ == '__main__':
    
      print("", end='\n')
      while True:
        print("running")
        
        # Just for testing, stops the while loop until Enter pressed
        indata=input("Press Enter or q to quit: ")
        if (indata=='q'):
          loop.quit()
          sys.exit()
    
        label = "My Notification"
        body="Testing\n Testing "
        actionlabel = "Next"
        Notify.init(label)
        
        n = Notify.Notification.new(label, body,None)
        n.set_urgency(Notify.Urgency.CRITICAL)
        n.connect("closed", closed_cb)
        n.add_action("next", actionlabel, next_cb, None, None)
        n.set_timeout(5000)
    
        loop=GLib.MainLoop()
        Notify.Notification.show(n)
        loop.run()
    
        print("GlibMainLoop Closed")
        print("", end='\n')
        time.sleep(2)

IMN logo majestic logo threadwatch logo seochat tools logo