def get_x(self, w): x = self.stack.get_origin_x() - w/2 if (x + w) >= self.stack.max_width: #dont overflow on the right x = self.stack.max_width - w if x <= 0: #or on the left x = 0 log("get_x(%s)=%s", w, x) return x
def get_x(self, w): x = self.stack.get_origin_x() - w/2 if (x + w) >= self.stack.max_width: #dont overflow on the right x = self.stack.max_width - w if x <= 0: #or on the left x = 0 log("get_x(%s)=%s", w, x) return x
def hide_notification(self, *args): """Destroys the notification and tells the stack to move the remaining notification windows""" log(None, *args) for timer in ("fade_in_timer", "fade_out_timer", "wait_timer"): if hasattr(self, timer): gobject.source_remove(getattr(self, timer)) self.destroy() self.destroy_cb(self)
def hide_notification(self, *args): """Destroys the notification and tells the stack to move the remaining notification windows""" log(None, *args) for timer in ("fade_in_timer", "fade_out_timer", "wait_timer"): if hasattr(self, timer): gobject.source_remove(getattr(self, timer)) self.destroy() self.destroy_cb(self)
def setup_dbusnotify(self): self.dbus_session = dbus.SessionBus() FD_NOTIFICATIONS = 'org.freedesktop.Notifications' self.org_fd_notifications = self.dbus_session.get_object( FD_NOTIFICATIONS, '/org/freedesktop/Notifications') self.dbusnotify = dbus.Interface(self.org_fd_notifications, FD_NOTIFICATIONS) log("using dbusnotify: %s(%s)", type(self.dbusnotify), FD_NOTIFICATIONS)
def get_y(self, h): y = self.stack.get_origin_y() if y >= (self.stack.max_height/2): #if near bottom, substract window height y = y - h if (y + h) >= self.stack.max_height: y = self.stack.max_height - h if y<= 0: y = 0 log("get_y(%s)=%s", h, y) return y
def get_y(self, h): y = self.stack.get_origin_y() if y >= (self.stack.max_height/2): #if near bottom, substract window height y = y - h if (y + h) >= self.stack.max_height: y = self.stack.max_height - h if y<= 0: y = 0 log("get_y(%s)=%s", h, y) return y
def hide_notification(self, *args): """Destroys the notification and tells the stack to move the remaining notification windows""" log("hide_notification%s", args) for timer in ("fade_in_timer", "fade_out_timer", "wait_timer"): v = getattr(self, timer) if v: setattr(self, timer, None) glib.source_remove(v) self.destroy() self.destroy_cb(self)
def hide_notification(self, *args): """Destroys the notification and tells the stack to move the remaining notification windows""" log("hide_notification%s", args) for timer in ("fade_in_timer", "fade_out_timer", "wait_timer"): v = getattr(self, timer) if v: setattr(self, timer, None) glib.source_remove(v) self.destroy() self.destroy_cb(self)
def __init__(self, size_x=DEFAULT_WIDTH, size_y=DEFAULT_HEIGHT, timeout=5): """ Create a new notification stack. The recommended way to create Popup instances. Parameters: `size_x` : The desired width of the notifications. `size_y` : The desired minimum height of the notifications. If the text is longer it will be expanded to fit. `timeout` : Popup instance will disappear after this timeout if there is no human intervention. This can be overridden temporarily by passing a new timout to the new_popup method. """ self.size_x = size_x self.size_y = size_y self.timeout = timeout """ Other parameters: These will take effect for every popup created after the change. `max_popups` : The maximum number of popups to be shown on the screen at one time. `bg_color` : if None default is used (usually grey). set with a gtk.gdk.Color. `fg_color` : if None default is used (usually black). set with a gtk.gdk.Color. `show_timeout : if True, a countdown till destruction will be displayed. """ self.max_popups = 5 self.fg_color = DEFAULT_FG_COLOUR self.bg_color = DEFAULT_BG_COLOUR self.show_timeout = False self._notify_stack = [] self._offset = 0 display = gtk.gdk.display_get_default() screen = display.get_default_screen() n = screen.get_n_monitors() log("screen=%s, monitors=%s", screen, n) if n < 2: self.max_width = screen.get_width() self.max_height = screen.get_height() log("screen dimensions: %dx%d", self.max_width, self.max_height) else: rect = screen.get_monitor_geometry(0) self.max_width = rect.width self.max_height = rect.height log("first monitor dimensions: %dx%d", self.max_width, self.max_height) self.x = self.max_width - 20 #keep away from the edge self.y = self.max_height - 64 #space for a panel log("our reduced dimensions: %dx%d", self.x, self.y)
def __init__(self, size_x=DEFAULT_WIDTH, size_y=DEFAULT_HEIGHT, timeout=5): """ Create a new notification stack. The recommended way to create Popup instances. Parameters: `size_x` : The desired width of the notifications. `size_y` : The desired minimum height of the notifications. If the text is longer it will be expanded to fit. `timeout` : Popup instance will disappear after this timeout if there is no human intervention. This can be overridden temporarily by passing a new timout to the new_popup method. """ self.size_x = size_x self.size_y = size_y self.timeout = timeout """ Other parameters: These will take effect for every popup created after the change. `max_popups` : The maximum number of popups to be shown on the screen at one time. `bg_color` : if None default is used (usually grey). set with a gtk.gdk.Color. `fg_color` : if None default is used (usually black). set with a gtk.gdk.Color. `show_timeout : if True, a countdown till destruction will be displayed. """ self.max_popups = 5 self.fg_color = DEFAULT_FG_COLOUR self.bg_color = DEFAULT_BG_COLOUR self.show_timeout = False self._notify_stack = [] self._offset = 0 display = gtk.gdk.display_get_default() screen = display.get_default_screen() n = screen.get_n_monitors() log("screen=%s, monitors=%s", screen, n) if n<2: self.max_width = screen.get_width() self.max_height = screen.get_height() log("screen dimensions: %dx%d", self.max_width, self.max_height) else: rect = screen.get_monitor_geometry(0) self.max_width = rect.width self.max_height = rect.height log("first monitor dimensions: %dx%d", self.max_width, self.max_height) self.x = self.max_width - 20 #keep away from the edge self.y = self.max_height - 64 #space for a panel log("our reduced dimensions: %dx%d", self.x, self.y)
def popup_cb_clicked(*args): self.hide_notification() log(None, *args) cb()
def popup_cb_clicked(*args): self.hide_notification() log(None, *args) cb()
def __init__(self, stack, title, message, callback, image): log("Popup%s", (stack, title, message, callback, image)) self.stack = stack gtk.Window.__init__(self) self.set_size_request(stack.size_x, -1) self.set_decorated(False) self.set_deletable(False) self.set_property("skip-pager-hint", True) self.set_property("skip-taskbar-hint", True) self.connect("enter-notify-event", self.on_hover, True) self.connect("leave-notify-event", self.on_hover, False) self.set_opacity(0.2) self.set_keep_above(True) self.destroy_cb = stack.destroy_popup_cb main_box = gtk.VBox() header_box = gtk.HBox() self.header = gtk.Label() self.header.set_markup("<b>%s</b>" % title) self.header.set_padding(3, 3) self.header.set_alignment(0, 0) header_box.pack_start(self.header, True, True, 5) if True: close_button = gtk.Image() close_button.set_from_stock(gtk.STOCK_CANCEL, gtk.ICON_SIZE_BUTTON) close_button.set_padding(3, 3) close_window = gtk.EventBox() close_window.set_visible_window(False) close_window.connect("button-press-event", self.hide_notification) close_window.add(close_button) header_box.pack_end(close_window, False, False) main_box.pack_start(header_box) body_box = gtk.HBox() if image is not None: self.image = gtk.Image() self.image.set_size_request(70, 70) self.image.set_alignment(0, 0) self.image.set_from_pixbuf(image) body_box.pack_start(self.image, False, False, 5) self.message = gtk.Label() self.message.set_property("wrap", True) self.message.set_size_request(stack.size_x - 90, -1) self.message.set_alignment(0, 0) self.message.set_padding(5, 10) self.message.set_text(message) self.counter = gtk.Label() self.counter.set_alignment(1, 1) self.counter.set_padding(3, 3) self.timeout = stack.timeout body_box.pack_start(self.message, True, False, 5) body_box.pack_end(self.counter, False, False, 5) main_box.pack_start(body_box) if callback: cb_text, cb = callback button = gtk.Button(cb_text) button.set_relief(gtk.RELIEF_NORMAL) def popup_cb_clicked(*args): self.hide_notification() log("popup_cb_clicked%s", args) cb() button.connect("clicked", popup_cb_clicked) alignment = gtk.Alignment(xalign=1.0, yalign=0.5, xscale=0.0, yscale=0.0) alignment.add(button) main_box.pack_start(alignment) self.add(main_box) if stack.bg_color is not None: self.modify_bg(gtk.STATE_NORMAL, stack.bg_color) if stack.fg_color is not None: self.message.modify_fg(gtk.STATE_NORMAL, stack.fg_color) self.header.modify_fg(gtk.STATE_NORMAL, stack.fg_color) self.counter.modify_fg(gtk.STATE_NORMAL, stack.fg_color) self.show_timeout = stack.show_timeout self.hover = False self.show_all() self.w, self.h = self.size_request() self.move(self.get_x(self.w), self.get_y(self.h)) self.wait_timer = None self.fade_out_timer = None self.fade_in_timer = glib.timeout_add(100, self.fade_in) #ensure we dont show it in the taskbar: self.window.set_skip_taskbar_hint(True) self.window.set_skip_pager_hint(True) self.realize() add_close_accel(self, self.hide_notification)
def reposition(self, offset, stack): """Move the notification window down, when an older notification is removed""" log("reposition(%s, %s)", offset, stack) new_offset = self.h + offset self.move(self.get_x(self.w), self.get_y(new_offset)) return new_offset
def popup_cb_clicked(*args): self.hide_notification() log("popup_cb_clicked%s", args) cb()
def popup_cb_clicked(*args): self.hide_notification() log("popup_cb_clicked%s", args) cb()
def __init__(self, stack, title, message, callback, image): log("Popup%s", (stack, title, message, callback, image)) self.stack = stack gtk.Window.__init__(self) self.set_size_request(stack.size_x, -1) self.set_decorated(False) self.set_deletable(False) self.set_property("skip-pager-hint", True) self.set_property("skip-taskbar-hint", True) self.connect("enter-notify-event", self.on_hover, True) self.connect("leave-notify-event", self.on_hover, False) self.set_opacity(0.2) self.set_keep_above(True) self.destroy_cb = stack.destroy_popup_cb main_box = gtk.VBox() header_box = gtk.HBox() self.header = gtk.Label() self.header.set_markup("<b>%s</b>" % title) self.header.set_padding(3, 3) self.header.set_alignment(0, 0) header_box.pack_start(self.header, True, True, 5) if True: close_button = gtk.Image() close_button.set_from_stock(gtk.STOCK_CANCEL, gtk.ICON_SIZE_BUTTON) close_button.set_padding(3, 3) close_window = gtk.EventBox() close_window.set_visible_window(False) close_window.connect("button-press-event", self.hide_notification) close_window.add(close_button) header_box.pack_end(close_window, False, False) main_box.pack_start(header_box) body_box = gtk.HBox() if image is not None: self.image = gtk.Image() self.image.set_size_request(70, 70) self.image.set_alignment(0, 0) self.image.set_from_pixbuf(image) body_box.pack_start(self.image, False, False, 5) self.message = gtk.Label() self.message.set_property("wrap", True) self.message.set_size_request(stack.size_x - 90, -1) self.message.set_alignment(0, 0) self.message.set_padding(5, 10) self.message.set_text(message) self.counter = gtk.Label() self.counter.set_alignment(1, 1) self.counter.set_padding(3, 3) self.timeout = stack.timeout body_box.pack_start(self.message, True, False, 5) body_box.pack_end(self.counter, False, False, 5) main_box.pack_start(body_box) if callback: cb_text, cb = callback button = gtk.Button(cb_text) button.set_relief(gtk.RELIEF_NORMAL) def popup_cb_clicked(*args): self.hide_notification() log("popup_cb_clicked%s", args) cb() button.connect("clicked", popup_cb_clicked) alignment = gtk.Alignment(xalign=1.0, yalign=0.5, xscale=0.0, yscale=0.0) alignment.add(button) main_box.pack_start(alignment) self.add(main_box) if stack.bg_color is not None: self.modify_bg(gtk.STATE_NORMAL, stack.bg_color) if stack.fg_color is not None: self.message.modify_fg(gtk.STATE_NORMAL, stack.fg_color) self.header.modify_fg(gtk.STATE_NORMAL, stack.fg_color) self.counter.modify_fg(gtk.STATE_NORMAL, stack.fg_color) self.show_timeout = stack.show_timeout self.hover = False self.show_all() self.w, self.h = self.size_request() self.move(self.get_x(self.w), self.get_y(self.h)) self.wait_timer = None self.fade_out_timer = None self.fade_in_timer = glib.timeout_add(100, self.fade_in) #ensure we dont show it in the taskbar: self.window.set_skip_taskbar_hint(True) self.window.set_skip_pager_hint(True) self.realize() add_close_accel(self, self.hide_notification)
def reposition(self, offset, stack): """Move the notification window down, when an older notification is removed""" log("reposition(%s, %s)", offset, stack) new_offset = self.h + offset self.move(self.get_x(self.w), self.get_y(new_offset)) return new_offset
def cbReply(self, *args): log("notification reply: %s", args) return False
def cbReply(self, *args): log("notification reply: %s", args) return False
def setup_dbusnotify(self): self.dbus_session = dbus.SessionBus() FD_NOTIFICATIONS = 'org.freedesktop.Notifications' self.org_fd_notifications = self.dbus_session.get_object(FD_NOTIFICATIONS, '/org/freedesktop/Notifications') self.dbusnotify = dbus.Interface(self.org_fd_notifications, FD_NOTIFICATIONS) log("using dbusnotify: %s(%s)", type(self.dbusnotify), FD_NOTIFICATIONS)