-
Notifications
You must be signed in to change notification settings - Fork 1
/
mateAppletExample.py
executable file
·69 lines (56 loc) · 1.83 KB
/
mateAppletExample.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
import pygtk
import sys
pygtk.require('2.0')
import mateapplet
import gtk
import subprocess
def factory(applet, iid):
button = gtk.Button()
button.set_relief(gtk.RELIEF_NONE)
button.set_label("ExampleButton")
button.connect("button_press_event", showMenu, applet)
applet.add(button)
applet.show_all()
return True
def showMenu(widget, event, applet):
if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1:
showMainDialog()
if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
widget.emit_stop_by_name("button_press_event")
create_menu(applet)
def create_menu(applet):
propxml="""
<popup name="button3">
<menuitem name="Item 3" verb="About" label="_About" pixtype="stock" pixname="gtk-about"/>
</popup>"""
verbs = [("About", showAboutDialog)]
applet.setup_menu(propxml, verbs, None)
def showMainDialog():
window = gtk.Window()
window.connect("delete-event", gtk.main_quit)
window.set_border_width(10)
button = gtk.Button("Hello World")
button.connect("clicked", on_button_clicked)
window.add(button)
window.show_all()
gtk.main()
def on_button_clicked(button):
subprocess.call("mate-calculator")
def showAboutDialog(*arguments, **keywords):
subprocess.call("mate-about")
# If applet is run directly from the command line with the -d debug option we create a window to host it
if len(sys.argv) == 2:
if sys.argv[1] == "-d":
mainWindow = gtk.Window(gtk.WINDOW_TOPLEVEL)
mainWindow.set_title("System Panel")
mainWindow.connect("destroy", gtk.main_quit)
applet = mateapplet.Applet()
factory(applet, None)
applet.reparent(mainWindow)
mainWindow.show_all()
gtk.main()
sys.exit()
if __name__ == '__main__':
print "Starting factory"
mateapplet.matecomponent_factory("OAFIID:Mate_Panel_Example_Factory", mateapplet.Applet.__gtype__, "Simple mate applet example", "1.0", factory)