Exemple #1
0
 def __init__(self):
     self.conf = Config()
     self.app = QtGui.QApplication(sys.argv)
     self.build_icons = BuildIcons()
     self.app.setWindowIcon(self.build_icons.for_status("Success.Sleeping"))
     self.app.setQuitOnLastWindowClosed(False)
     self.ready = False
     self.timed_event = RepeatTimedEvent(self.app, self.delayed_start, 5)
     self.timed_event.start()
     sys.exit(self.app.exec_())
Exemple #2
0
    def __init__(self):
        gtk.Window.__init__(self)

        pynotify.init('PyCruiseTray')

        # Create ServerManager
        self.server_manager = ServerManager()

        # Load servers
        self.load_servers()

        # Load BuildIcons
        self.build_icons = BuildIcons()

        self.statusicon = gtk.StatusIcon()
        self.statusicon.set_from_stock(gtk.STOCK_APPLY)
        self.statusicon.connect("popup-menu", self.right_click_event)
        self.statusicon.connect("activate", self.status_clicked)
        self.statusicon.set_tooltip("PyCruiseTray")

        self.connect("delete-event", self.delete_event)
        self.connect("destroy", lambda w: gtk.main_quit())

        # Create TreeStore for Server list
        self.liststore = gtk.ListStore(gtk.gdk.Pixbuf, str, str)
        self.treeview = gtk.TreeView(self.liststore)

        # Create TreeViewColumns to display data
        cell = gtk.CellRendererPixbuf()
        col = gtk.TreeViewColumn("Status", cell, pixbuf=0)
        self.treeview.append_column(col)

        cell = gtk.CellRendererText()
        col = gtk.TreeViewColumn("Name", cell, text=1)
        self.treeview.append_column(col)

        cell = gtk.CellRendererText()
        col = gtk.TreeViewColumn("URL", cell, text=2)
        self.treeview.append_column(col)

        self.add(self.treeview)
        self.set_size_request(450, 300)
        self.set_position(gtk.WIN_POS_CENTER)
        self.set_title("PyCruiseTray")

        self.menu = ContextMenu(self, self.build_icons)
        self.show_all()

        # Start update thread (run every 5 minutes)
        self.update_projects()
        self.thread = gobject.timeout_add(60000, self.update_projects)
Exemple #3
0
class BuildNotify:
    def __init__(self):
        self.conf = Config()
        self.app = QtGui.QApplication(sys.argv)
        self.build_icons = BuildIcons()
        self.app.setWindowIcon(self.build_icons.for_status("Success.Sleeping"))
        self.app.setQuitOnLastWindowClosed(False)
        self.ready = False
        self.timed_event = RepeatTimedEvent(self.app, self.delayed_start, 5)
        self.timed_event.start()
        sys.exit(self.app.exec_())

    def delayed_start(self, event_count):
        if not QtGui.QSystemTrayIcon.isSystemTrayAvailable():
            if event_count == 5:
                QtGui.QMessageBox.critical(None, "BuildNotify", "I couldn't detect any system tray on this system.")
                sys.exit(1)
            self.timed_event.start()
        if not self.ready:
            self.ready = True
            self.run_app()

    def run_app(self):
        self.projects_populator = ProjectsPopulator(self.conf, self.app)
        self.app.connect(self.projects_populator, QtCore.SIGNAL('updated_projects'), self.update_projects)
        self.app.connect(self.app, QtCore.SIGNAL('reload_project_data'), self.reload_project_data)
        self.app_ui = AppUi(self.app, self.conf, self.build_icons)
        self.app_notification = AppNotification(self.conf, self.app_ui.tray)
        self.auto_poll()

    def reload_project_data(self):
        self.projects_populator.reload()

    def update_projects(self, integration_status):
        self.app_notification.update_projects(integration_status)
        self.app_ui.update_projects(integration_status)

    def auto_poll(self):
        self.timed_event = TimedEvent(self.app, self.check_nodes)
        self.timed_event.set_interval(1000)
        self.timed_event.start()

    def check_nodes(self):
        self.projects_populator.load_from_server()
        self.timed_event.set_interval(self.conf.get_interval_in_millis())
        self.timed_event.start()
Exemple #4
0
class PyCruiseTray(gtk.Window):
    def __init__(self):
        gtk.Window.__init__(self)

        pynotify.init('PyCruiseTray')

        # Create ServerManager
        self.server_manager = ServerManager()

        # Load servers
        self.load_servers()

        # Load BuildIcons
        self.build_icons = BuildIcons()

        self.statusicon = gtk.StatusIcon()
        self.statusicon.set_from_stock(gtk.STOCK_APPLY)
        self.statusicon.connect("popup-menu", self.right_click_event)
        self.statusicon.connect("activate", self.status_clicked)
        self.statusicon.set_tooltip("PyCruiseTray")

        self.connect("delete-event", self.delete_event)
        self.connect("destroy", lambda w: gtk.main_quit())

        # Create TreeStore for Server list
        self.liststore = gtk.ListStore(gtk.gdk.Pixbuf, str, str)
        self.treeview = gtk.TreeView(self.liststore)

        # Create TreeViewColumns to display data
        cell = gtk.CellRendererPixbuf()
        col = gtk.TreeViewColumn("Status", cell, pixbuf=0)
        self.treeview.append_column(col)

        cell = gtk.CellRendererText()
        col = gtk.TreeViewColumn("Name", cell, text=1)
        self.treeview.append_column(col)

        cell = gtk.CellRendererText()
        col = gtk.TreeViewColumn("URL", cell, text=2)
        self.treeview.append_column(col)

        self.add(self.treeview)
        self.set_size_request(450, 300)
        self.set_position(gtk.WIN_POS_CENTER)
        self.set_title("PyCruiseTray")

        self.menu = ContextMenu(self, self.build_icons)
        self.show_all()

        # Start update thread (run every 5 minutes)
        self.update_projects()
        self.thread = gobject.timeout_add(60000, self.update_projects)

    def load_servers(self):
        self.servers = []
        for server in self.server_manager.list():
            self.servers.append(CruiseControlServer(server['name'], server['url']))

    def update_projects(self):
        projects = []
        for server in self.servers:
            server.load_projects()
            projects.extend(server.projects)

        self.show_projects_list(projects)
        self.menu.update(projects)
        failures = filter((lambda p: 'Failure' in p.get_build_status()), projects)


        # Change StatusIcon accordingly
        if len(failures) > 0:
            self.statusicon.set_from_pixbuf(self.build_icons.get_icon('Failure.Sleeping'))
        else:
            self.statusicon.set_from_pixbuf(self.build_icons.get_icon('Success.Sleeping'))

        for fail in failures:
            notification = pynotify.Notification("Build failure", "Project %s failed to build!" % fail.name)
            notification.attach_to_status_icon(self.statusicon)
            notification.set_urgency(pynotify.URGENCY_CRITICAL)
            notification.set_timeout(10000)
            notification.show()
        return True

    def show_projects_list(self, projects):
        self.liststore.clear()
        for project in projects:
            icon = self.build_icons.get_icon(project.get_build_status())
            self.liststore.append([icon, project.name, project.url])

    def status_clicked(self, status):
        self.show_all()

    def delete_event(self, window, event):
        self.hide_on_delete()
        return True
		
    def right_click_event(self, icon, button, time):
        self.menu.popup(None, None, gtk.status_icon_position_menu, button, time, self.statusicon)