Skip to content

Instantly share code, notes, and snippets.

@pklaus
Created February 15, 2010 20:36

Revisions

  1. pklaus revised this gist Feb 15, 2010. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion StatusIcon.py
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,9 @@
    #!/usr/bin/env python

    # found on <http://files.majorsilence.com/rubbish/pygtk-book/pygtk-notebook-html/pygtk-notebook-latest.html#SECTION00430000000000000000>
    import gtk
    # simple example of a tray icon application using PyGTK

    import gtk

    def message(data=None):
    "Function to display messages to the user."
  2. pklaus revised this gist Feb 15, 2010. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions StatusIcon.py
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@

    # found on <http://files.majorsilence.com/rubbish/pygtk-book/pygtk-notebook-html/pygtk-notebook-latest.html#SECTION00430000000000000000>
    import gtk
    # simple example of a tray icon application using PyGTK

    def message(data=None):
    "Function to display messages to the user."
  3. pklaus created this gist Feb 15, 2010.
    49 changes: 49 additions & 0 deletions StatusIcon.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    #!/usr/bin/env python

    # found on <http://files.majorsilence.com/rubbish/pygtk-book/pygtk-notebook-html/pygtk-notebook-latest.html#SECTION00430000000000000000>
    import gtk

    def message(data=None):
    "Function to display messages to the user."

    msg=gtk.MessageDialog(None, gtk.DIALOG_MODAL,
    gtk.MESSAGE_INFO, gtk.BUTTONS_OK, data)
    msg.run()
    msg.destroy()

    def open_app(data=None):
    message(data)

    def close_app(data=None):
    message(data)
    gtk.main_quit()

    def make_menu(event_button, event_time, data=None):
    menu = gtk.Menu()
    open_item = gtk.MenuItem("Open App")
    close_item = gtk.MenuItem("Close App")

    #Append the menu items
    menu.append(open_item)
    menu.append(close_item)
    #add callbacks
    open_item.connect_object("activate", open_app, "Open App")
    close_item.connect_object("activate", close_app, "Close App")
    #Show the menu items
    open_item.show()
    close_item.show()

    #Popup the menu
    menu.popup(None, None, None, event_button, event_time)

    def on_right_click(data, event_button, event_time):
    make_menu(event_button, event_time)

    def on_left_click(event):
    message("Status Icon Left Clicked")

    if __name__ == '__main__':
    icon = gtk.status_icon_new_from_stock(gtk.STOCK_ABOUT)
    icon.connect('popup-menu', on_right_click)
    icon.connect('activate', on_left_click)
    gtk.main()