313cb4baaee235e48a2a93133f79a892a1dc9415
[tpot/bbremote.git] / bbapplet
1 #!/usr/bin/python
2
3 import pygtk
4 pygtk.require('2.0')
5
6 from twisted.internet import gtk2reactor
7 gtk2reactor.install()
8
9 from twisted.internet import reactor
10 from twisted.spread import pb
11
12 import sys, gtk, gnomeapplet, pynotify
13 from bbclient import BuildbotClient
14
15 HOST = 'localhost'
16 PORT = 1234
17 USER = 'statusClient'
18 PASS = 'clientpw'
19
20 class BuildbotApplet(pb.Referenceable):
21       
22     def __init__(self, applet, icon):
23
24         self.applet = applet
25
26         self.applet.add(icon)
27         self.applet.show_all()
28
29         client = BuildbotClient()
30
31         d = client.connect(HOST, PORT, USER, PASS)
32
33         d.addCallback(lambda arg: client.subscribe('builds', 5, self))
34
35     # Callbacks for subscription mode >= MODE_BUILDERS
36
37     def remote_builderAdded(self, buildername, builder):
38         pass
39
40     def remote_builderRemoved(self, buildername):
41         pass
42
43     def remote_builderChangedState(self, buildername, statename, eta):
44         pass
45
46     # Callbacks for subscription mode >= MODE_BUILDS
47
48     def remote_buildStarted(self, buildername, build):
49         
50         n = pynotify.Notification('Build started', buildername)
51
52         n.set_urgency(pynotify.URGENCY_LOW)
53         n.set_category('eep')
54         n.attach_to_widget(self.applet)
55         n.show()
56
57     def remote_buildFinished(self, buildername, build, result):
58
59         n = pynotify.Notification('Build finished', buildername)
60
61         n.set_urgency(pynotify.URGENCY_LOW)
62         n.set_category('eep')
63         n.attach_to_widget(self.applet)
64         n.show()
65
66 def BuildbotApplet_factory(applet, iid):
67
68     pynotify.init("bbapplet")
69
70     icon = gtk.image_new_from_stock(gtk.STOCK_NEW, gtk.ICON_SIZE_MENU)
71     BuildbotApplet(applet, icon)
72
73     return gtk.TRUE
74
75 if __name__ == "__main__":
76     
77     if len(sys.argv) == 2 and sys.argv[1] == "run-in-window":
78
79         # Run in a window, for debugging
80
81         main_window = gtk.Window(gtk.WINDOW_TOPLEVEL)
82         main_window.set_title("buildbot applet")
83         main_window.connect('destroy', gtk.main_quit)
84
85         app = gnomeapplet.Applet()
86
87         BuildbotApplet_factory(app, None)
88
89         app.reparent(main_window)
90
91         main_window.show_all()
92         reactor.run()
93
94     else:
95
96         # Run as bonobo component
97
98         reactor.startRunning()
99         reactor.simulate()
100
101         gnome.applet.bonobo_factory("OAFIID:GNOME_BuildbotApplet_Factory",
102                                     gnome.applet.Applet.__gtype__,
103                                     "bbapplet", "0", BuildbotApplet_factory)