6 from twisted.internet import gtk2reactor
9 from twisted.internet import reactor
10 from twisted.spread import pb
12 import sys, gtk, gnomeapplet, pynotify
13 from bbclient import BuildbotClient
20 class BuildbotApplet(pb.Referenceable):
22 def __init__(self, applet, icon):
27 self.applet.show_all()
29 client = BuildbotClient()
31 d = client.connect(HOST, PORT, USER, PASS)
33 d.addCallback(lambda arg: client.subscribe('builds', 5, self))
35 # Callbacks for subscription mode >= MODE_BUILDERS
37 def remote_builderAdded(self, buildername, builder):
40 def remote_builderRemoved(self, buildername):
43 def remote_builderChangedState(self, buildername, statename, eta):
46 # Callbacks for subscription mode >= MODE_BUILDS
48 def remote_buildStarted(self, buildername, build):
50 n = pynotify.Notification('Build started', buildername)
52 n.set_urgency(pynotify.URGENCY_LOW)
54 n.attach_to_widget(self.applet)
57 def remote_buildFinished(self, buildername, build, result):
59 n = pynotify.Notification('Build finished', buildername)
61 n.set_urgency(pynotify.URGENCY_LOW)
63 n.attach_to_widget(self.applet)
66 def BuildbotApplet_factory(applet, iid):
68 pynotify.init("bbapplet")
70 icon = gtk.image_new_from_stock(gtk.STOCK_NEW, gtk.ICON_SIZE_MENU)
71 BuildbotApplet(applet, icon)
75 if __name__ == "__main__":
77 if len(sys.argv) == 2 and sys.argv[1] == "run-in-window":
79 # Run in a window, for debugging
81 main_window = gtk.Window(gtk.WINDOW_TOPLEVEL)
82 main_window.set_title("buildbot applet")
83 main_window.connect('destroy', gtk.main_quit)
85 app = gnomeapplet.Applet()
87 BuildbotApplet_factory(app, None)
89 app.reparent(main_window)
91 main_window.show_all()
96 # Run as bonobo component
98 reactor.startRunning()
101 gnome.applet.bonobo_factory("OAFIID:GNOME_BuildbotApplet_Factory",
102 gnome.applet.Applet.__gtype__,
103 "bbapplet", "0", BuildbotApplet_factory)