Results 1 to 3 of 3

Thread: Python StatusIcon

  1. #1
    Join Date
    Jul 2005
    Location
    London,England
    Beans
    1,022
    Distro
    Ubuntu Karmic Koala (testing)

    Python StatusIcon

    hi all, im trying to get a statusicon right click menu to work in pygobject the icon appears fine and no errors are output, however no menu appears, the problem line i think is
    Code:
    menu.popup(None, None, None, Gtk.StatusIcon.position_menu, button, time)
    the old working code in pygtk was

    Code:
    menu.popup(None, None, gtk.status_icon_position_menu, button, time, self.statusicon)
    this is the complete example code.

    Code:
    from gi.repository import Gtk
    
    class StatusIcon:
        def __init__(self):
            self.statusicon = Gtk.StatusIcon()
            self.statusicon.set_from_stock(Gtk.STOCK_HOME) 
            self.statusicon.connect("popup-menu", self.right_click_event)
            
            window = Gtk.Window()
            window.connect("destroy", lambda w: Gtk.main_quit())
            window.show_all()
    		
        def right_click_event(self, icon, button, time):
            menu = Gtk.Menu()
    
            about = Gtk.MenuItem()
    	about.set_label("About")
            quit = Gtk.MenuItem()
    	quit.set_label("Quit")
            
            about.connect("activate", self.show_about_dialog)
            quit.connect("activate", Gtk.main_quit)
            
            menu.append(about)
            menu.append(quit)
            
            menu.show_all()
    
            #menu.popup(None, None, gtk.status_icon_position_menu, button, time, self.statusicon)
            menu.popup(None, None, None, Gtk.StatusIcon.position_menu, button, time)
            
        def show_about_dialog(self, widget):
            about_dialog = Gtk.AboutDialog()
    
            about_dialog.set_destroy_with_parent(True)
            about_dialog.set_name("StatusIcon Example")
            about_dialog.set_version("1.0")
            about_dialog.set_authors(["Andrew Steele"])
            		
            about_dialog.run()
            about_dialog.destroy()
    
    StatusIcon()
    Gtk.main()
    anyone got any ideas what im doing wrong?
    Jeremy Clarkson - "A Dazzling Hero of Political Incorrectness"
    My LastFM profile
    want to Give each GTK program its own theme? well look Here

  2. #2
    Join Date
    Jul 2005
    Location
    London,England
    Beans
    1,022
    Distro
    Ubuntu Karmic Koala (testing)

    Re: Python StatusIcon

    bump
    Jeremy Clarkson - "A Dazzling Hero of Political Incorrectness"
    My LastFM profile
    want to Give each GTK program its own theme? well look Here

  3. #3
    Join Date
    Jul 2005
    Location
    London,England
    Beans
    1,022
    Distro
    Ubuntu Karmic Koala (testing)

    Re: Python StatusIcon

    if anyone else has this problem, youve got to keep your menu in scope or it gets garbage collected, so you get no errors but no menu either, this is the working code

    Code:
    from gi.repository import Gtk
    
    class aStatusIcon:
        def __init__(self):
            self.statusicon = Gtk.StatusIcon()
            self.statusicon.set_from_stock(Gtk.STOCK_HOME) 
            self.statusicon.connect("popup-menu", self.right_click_event)
    
            window = Gtk.Window()
            window.connect("destroy", lambda w: Gtk.main_quit())
            window.show_all()
    
        def right_click_event(self, icon, button, time):
            self.menu = Gtk.Menu()
    
            about = Gtk.MenuItem()
        about.set_label("About")
            quit = Gtk.MenuItem()
        quit.set_label("Quit")
    
            about.connect("activate", self.show_about_dialog)
            quit.connect("activate", Gtk.main_quit)
    
            self.menu.append(about)
            self.menu.append(quit)
    
            self.menu.show_all()
    
        def pos(menu, ignore, icon):
            return (Gtk.StatusIcon.position_menu(menu, icon))
    
            self.menu.popup(None, None, pos, self.statusicon, button, time) 
    
        def show_about_dialog(self, widget):
            about_dialog = Gtk.AboutDialog()
    
            about_dialog.set_destroy_with_parent(True)
            about_dialog.set_name("StatusIcon Example")
            about_dialog.set_version("1.0")
            about_dialog.set_authors(["Andrew Steele"])
    
            about_dialog.run()
            about_dialog.destroy()
    
    aStatusIcon()
    Gtk.main()
    Jeremy Clarkson - "A Dazzling Hero of Political Incorrectness"
    My LastFM profile
    want to Give each GTK program its own theme? well look Here

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •