#!/usr/bin/python import pygtk import gtk import gobject import time import sexy import os from plugins import feeds, Notification class NotificationWindow(gtk.Window): def __init__(self): gtk.Window.__init__(self, type=gtk.WINDOW_POPUP) self.set_border_width(2) self.set_resizable(False) self.set_name('gtk-tooltips') self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_TOOLTIP) self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#6e99af")) # Notebook self.nb = gtk.Notebook() self.nb.connect("page-removed", self.on_page_removed) # Left vbox vbox = gtk.VBox() vbox.pack_start(gtk.image_new_from_stock(gtk.STOCK_DIALOG_INFO, gtk.ICON_SIZE_MENU), expand=False, padding=10) label = gtk.Label("Activity Notification") label.set_use_markup(True) label.set_angle(90) vbox.pack_start(label, fill=False, padding=5) # Hbox hbox = gtk.HBox() hbox.pack_start(vbox, padding=3) hbox.pack_start(self.nb) self.add(hbox) def on_page_removed(self, widget, a, b): if self.nb.get_n_pages() == 0: self.hide() def on_close_button_clicked(self, w): cur = self.nb.get_current_page() self.nb.remove_page(cur) self.update_position() def update_position(self): screen_width = self.get_screen().get_width() my_width = self.get_size()[0] self.move(10, 30) def new_frame(self, aNotificationFrame): hbox = gtk.HBox() hbox.pack_start(gtk.Label(aNotificationFrame.notification.title)) b = gtk.Button() b.set_image(gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)) b.connect("clicked", self.on_close_button_clicked) hbox.pack_start(b) hbox.show_all() self.nb.append_page(aNotificationFrame, hbox) self.show_all() self.update_position() class NotificationFrame(gtk.Frame): def __init__(self, n): gtk.Frame.__init__(self) self.notification = n # Text title = sexy.UrlLabel("" + n.title + "") body = sexy.UrlLabel(n.body) body.connect("url-activated", self.on_url_activation) # Vbox vbox = gtk.VBox() vbox.set_spacing(10) vbox.set_border_width(10) vbox.pack_start(title, expand=False) align = gtk.Alignment() align.add(body) vbox.pack_start(align) # Eventbox eventbox = gtk.EventBox() eventbox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#faffea")) eventbox.add(vbox) self.add(eventbox); self.show_all() def on_url_activation(self, widget, url): if os.system("mozilla -remote \"openurl(" + url + ", new-tab)\""): if os.system("epiphany -n '" + url + "'"): if os.system("mozilla " + url): print "Unable to open a window" class Acconier(object): def __init__(self): icon = gtk.status_icon_new_from_stock(gtk.STOCK_DIALOG_WARNING) icon.set_visible(True) icon.set_tooltip("Acconier") self.icon = icon self.nw = NotificationWindow() self.plugins = list() self.load_plugins() def load_plugins(self): self.plugins.append(feeds.FeedNotifier()) def main(self): while True: # refreshing UI if gtk.events_pending(): while gtk.events_pending(): gtk.main_iteration() else: time.sleep(0.1) # Run plugins for p in self.plugins: map(lambda i: self.nw.new_frame(NotificationFrame(i)), p.new_round()) acconier = Acconier() acconier.main()