Example #1
0
def main():
    logger.info('loading configuration')
    import conf

    debug_levels = ['DEBUG', 'INFO', 'WARNING', 'ERROR']

    parser = argparse.ArgumentParser(
        description="Simple panel written in Python for holding widgets")
    parser.add_argument('--verbosity', '-v', dest='verbosity',
                        choices=debug_levels, default=None)

    args = parser.parse_args()

    level = args.verbosity or getattr(conf, 'VERBOSITY', 'INFO')
    if level not in debug_levels:
        logger.critical('Log level %s not supported!', level)
        return 1
    logging.basicConfig(level=level)

    logger.info('creating panel')
    app = PanelWindow(position=getattr(conf, 'POSITION', None),
                      widgets=getattr(conf, 'WIDGETS', []))
    logger.info('starting main loop')
    gtk.gdk.threads_init()
    with GdkLock():
        gtk.main()
Example #2
0
 def __init__(self):
     super(NotificationsWidget, self).__init__()
     self.daemon = NotificationDaemon(listeners=[self])
     self.notifications = OrderedDict()
     self._gdk_lock = GdkLock()
Example #3
0
class NotificationsWidget(gtk.HBox, NotificationObserver):
    def __init__(self):
        super(NotificationsWidget, self).__init__()
        self.daemon = NotificationDaemon(listeners=[self])
        self.notifications = OrderedDict()
        self._gdk_lock = GdkLock()

    def _get_notification_by_id(self, n_id):
        for _, notifs in self.notifications.items():
            for n in notifs:
                if n.n_id == n_id:
                    return n

    def notify(self, daemon, n_id):
        notif = daemon.notifications[n_id]
        logger.debug('Received notification %s', notif)
        old_notif = self._get_notification_by_id(n_id)
        if old_notif:
            self.update_notification(old_notif, notif)
        else:
            self.add_notification(notif)
        with self._gdk_lock:
            self.refresh()

    def close(self, daemon, n_id):
        notif = self._get_notification_by_id(n_id)
        logger.debug('Removing notification %s', notif)
        self.remove_notification(notif)
        with self._gdk_lock:
            self.refresh()

    def add_notification(self, notif):
        notif_l = self.notifications.get(notif.app, [])
        notif_l.append(notif)
        if notif.app in self.notifications:
            del self.notifications[notif.app]
        self.notifications[notif.app] = notif_l

    def remove_notification(self, notif):
        self.notifications[notif.app].remove(notif)
        if len(self.notifications[notif.app]) < 1:
            del self.notifications[notif.app]

    def update_notification(self, old_notif, notif):
        self.remove_notification(old_notif)
        self.add_notification(notif)

    def refresh(self):
        for c in self.get_children():
            self.remove(c)

        if not self.notifications:
            return

        last_app = self.notifications.keys()[-1]
        for app, notifs in self.notifications.items():
            icon = AppNotificationsIcon(notifs, expanded=(app == last_app))
            eventbox = gtk.EventBox()
            eventbox.add(icon)
            eventbox.connect('button-press-event', self.notification_clicked,
                             notifs[-1].n_id)
            self.pack_end(eventbox, padding=5)
        self.show_all()
        self.queue_draw()

    def notification_clicked(self, widget, event, n_id):
        with self._gdk_lock.fake():
            self.daemon.NotificationClosed(n_id, 2)
        return True
Example #4
0
 def workspace_callback(self, event, data, subscription):
     sys.stdout.flush()
     with GdkLock():
         self.workspaces = data
         self.update()
Example #5
0
 def __init__(self):
     super(NotificationsWidget, self).__init__()
     self.daemon = NotificationDaemon(listeners=[self])
     self.notifications = OrderedDict()
     self._gdk_lock = GdkLock()
Example #6
0
class NotificationsWidget(gtk.HBox, NotificationObserver):
    def __init__(self):
        super(NotificationsWidget, self).__init__()
        self.daemon = NotificationDaemon(listeners=[self])
        self.notifications = OrderedDict()
        self._gdk_lock = GdkLock()

    def _get_notification_by_id(self, n_id):
        for _, notifs in self.notifications.items():
            for n in notifs:
                if n.n_id == n_id:
                    return n

    def notify(self, daemon, n_id):
        notif = daemon.notifications[n_id]
        logger.debug('Received notification %s', notif)
        old_notif = self._get_notification_by_id(n_id)
        if old_notif:
            self.update_notification(old_notif, notif)
        else:
            self.add_notification(notif)
        with self._gdk_lock:
            self.refresh()

    def close(self, daemon, n_id):
        notif = self._get_notification_by_id(n_id)
        logger.debug('Removing notification %s', notif)
        self.remove_notification(notif)
        with self._gdk_lock:
            self.refresh()

    def add_notification(self, notif):
        notif_l = self.notifications.get(notif.app, [])
        notif_l.append(notif)
        if notif.app in self.notifications:
            del self.notifications[notif.app]
        self.notifications[notif.app] = notif_l

    def remove_notification(self, notif):
        self.notifications[notif.app].remove(notif)
        if len(self.notifications[notif.app]) < 1:
            del self.notifications[notif.app]

    def update_notification(self, old_notif, notif):
        self.remove_notification(old_notif)
        self.add_notification(notif)

    def refresh(self):
        for c in self.get_children():
            self.remove(c)

        if not self.notifications:
            return

        last_app = self.notifications.keys()[-1]
        for app, notifs in self.notifications.items():
            icon = AppNotificationsIcon(notifs, expanded=(app==last_app))
            eventbox = gtk.EventBox()
            eventbox.add(icon)
            eventbox.connect('button-press-event', self.notification_clicked,
                             notifs[-1].n_id)
            self.pack_end(eventbox, padding=5)
        self.show_all()
        self.queue_draw()

    def notification_clicked(self, widget, event, n_id):
        with self._gdk_lock.fake():
            self.daemon.NotificationClosed(n_id, 2)
        return True