-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTrayTypical.py
More file actions
executable file
·56 lines (44 loc) · 1.67 KB
/
TrayTypical.py
File metadata and controls
executable file
·56 lines (44 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
# found on <http://files.majorsilence.com/rubbish/pygtk-book/pygtk-notebook-html/pygtk-notebook-latest.html#SECTION00430000000000000000>
# simple example of a tray icon application using PyGTK
# this is a typical tray operation: An action is made on left click - a popup menu appears on right-click.
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()
#By default connect 'popup-menu' works in right click.
#and connect 'activate' works in left click.
#connect popup-menu action sends to right-click function 3 variables
#connect activate action send to left-click function 1 variable