class DockManager(dbus.service.Object): def __new__(cls, dockbar): if "net.launchpad.DockManager" in dbus.SessionBus().list_names(): logger.debug("Name net.launchpad.DockManager is already" + \ " in use. (This instance of) DockbarX will" + \ " not use DockManager.") return None else: return dbus.service.Object.__new__(cls) def __init__(self, dockbar): self.dockbar_r = weakref.ref(dockbar) bus_name = dbus.service.BusName("net.launchpad.DockManager", bus=dbus.SessionBus()) dbus.service.Object.__init__(self, bus_name, "/net/launchpad/DockManager") self.globals = Globals() @dbus.service.method( dbus_interface="net.launchpad.DockManager", in_signature="", out_signature="as", ) def GetCapabilities(self): capabilities = [ "menu-item-container-title", "menu-item-icon-file", "menu-item-icon-name", "menu-item-with-label", "dock-item-badge", "dock-item-progress" ] return capabilities @dbus.service.method( dbus_interface="net.launchpad.DockManager", in_signature="", out_signature="ao", ) def GetItems(self): path_list = [] for path in self.dockbar_r().get_dm_paths(): path_list.append(dbus.ObjectPath(path)) return path_list @dbus.service.method( dbus_interface="net.launchpad.DockManager", in_signature="s", out_signature="ao", ) def GetItemsByDesktopFile(self, name): path_list = [] for path in self.dockbar_r().get_dm_paths_by_desktop_file(name): path_list.append(dbus.ObjectPath(path)) logger.debug("Items gotten by dekstop file: %s" % path_list) return path_list @dbus.service.method( dbus_interface="net.launchpad.DockManager", in_signature="s", out_signature="ao", ) def GetItemsByName(self, name): path_list = [] for path in self.dockbar_r().get_dm_paths_by_name(name): path_list.append(dbus.ObjectPath(path)) logger.debug("Items gotten by name: %s" % path_list) return path_list @dbus.service.method( dbus_interface="net.launchpad.DockManager", in_signature="i", out_signature="ao", ) def GetItemsByPid(self, pid): path_list = [] for path in self.dockbar_r().get_dm_paths_by_pid(pid): path_list.append(dbus.ObjectPath(path)) logger.debug("Items gotten by pid: %s" % path_list) return path_list @dbus.service.method( dbus_interface="net.launchpad.DockManager", in_signature="x", out_signature="ao", ) def GetItemsByXid(self, xid): path_list = [] for path in self.dockbar_r().get_dm_paths_by_xid(xid): path_list.append(dbus.ObjectPath(path)) logger.debug("Items gotten by xid: %s" % path_list) return path_list @dbus.service.signal(dbus_interface='net.launchpad.DockManager', signature='o') def ItemAdded(self, obj_path): pass @dbus.service.signal(dbus_interface='net.launchpad.DockManager', signature='o') def ItemRemoved(self, obj_path): pass @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='ss', out_signature='v') def Get(self, interface_name, property_name): return self.GetAll(interface_name)[property_name] @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='s', out_signature='a{sv}') def GetAll(self, interface_name): if interface_name == "net.launchpad.DockManager": return {} else: raise dbus.exceptions.DBusException( 'com.example.UnknownInterface', 'The Foo object does not implement the %s interface' % interface_name) @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='ssv', out_signature='') def Set(self, interface_name, property_name, property_value): pass @dbus.service.signal(dbus_interface=dbus.PROPERTIES_IFACE, signature='sa{sv}as') def PropertiesChanged(self, interface_name, changed_properties, invalidated_properties): pass def reset(self): try: bus = dbus.SessionBus() proxy = bus.get_object("net.launchpad.DockManager.Daemon", "/net/launchpad/DockManager/Daemon") proxy.RestartAll(dbus_interface="net.launchpad.DockManager.Daemon") except: logger.exception("Restarting DockManager Helpers failed.") def remove(self): self.remove_from_connection() self.globals.disconnect(self.badge_sid)
class CairoAppButton(gtk.EventBox): __gsignals__ = {"expose-event" : "override", "size_allocate": "override"} def __init__(self, surface=None, expose_on_clear=False): gtk.EventBox.__init__(self) self.set_visible_window(False) self.area = gtk.Alignment(0, 0, 1, 1) self.add(self.area) self.area.show() self.globals = Globals() self.surface = surface self.expose_on_clear = expose_on_clear self.badge = None self.badge_text = None self.progress_bar = None self.progress = None self.bl_sid = self.globals.connect("badge-look-changed", self.__on_badge_look_changed) self.pbl_sid = self.globals.connect("progress-bar-look-changed", self.__on_progress_bar_look_changed) def update(self, surface=None): a = self.area.get_allocation() if surface is not None: self.surface = surface if self.window is None: return if self.expose_on_clear: self.area.window.clear_area_e(a.x, a.y, a.width, a.height) else: self.area.window.clear_area(a.x, a.y, a.width, a.height) ctx = self.area.window.cairo_create() ctx.rectangle(a.x, a.y, a.width, a.height) ctx.clip() ctx.set_source_surface(self.surface, a.x, a.y) ctx.paint() for surface in (self.badge, self.progress_bar): if surface is not None: ctx.rectangle(a.x, a.y, a.width, a.height) ctx.clip() ctx.set_source_surface(surface, a.x, a.y) ctx.paint() child = self.area.get_child() if child: child.queue_draw() def do_expose_event(self, event): if self.surface is not None: ctx = self.area.window.cairo_create() ctx.rectangle(event.area.x, event.area.y, event.area.width, event.area.height) ctx.clip() a = self.get_allocation() ctx.set_source_surface(self.surface, a.x, a.y) ctx.paint() for surface in (self.badge, self.progress_bar): if surface is not None: ctx.rectangle(event.area.x, event.area.y, event.area.width, event.area.height) ctx.clip() ctx.set_source_surface(surface, a.x, a.y) ctx.paint() self.propagate_expose(self.area, event) def do_size_allocate(self, allocation): gtk.EventBox.do_size_allocate(self, allocation) if self.badge: self.make_badge(self.badge_text) if self.progress_bar: self.make_progress_bar(self.progress) def make_badge(self, text): if not text: self.badge_text = None self.badge = None return self.badge_text = text a = self.area.get_allocation() self.badge = cairo.ImageSurface(cairo.FORMAT_ARGB32, a.width, a.height) ctx = gtk.gdk.CairoContext(cairo.Context(self.badge)) layout = ctx.create_layout() if self.globals.settings["badge_use_custom_font"]: font = self.globals.settings["badge_font"] font_base, font_size = font.rsplit(" ", 1) font_size = int(font_size) else: font_size = max(int(round(0.2 * a.height)), 6) font_base = "sans bold" font = "%s %s" % (font_base, font_size) layout.set_font_description(pango.FontDescription(font)) layout.set_text(text) te = layout.get_pixel_extents() w = te[1][2] h = te[0][1] + te[0][3] size = min(a.width, a.height) p = 2 d = int(round(0.05 * size)) # Make sure the badge isn't too wide. while w + 2 * p + d >= a.width and font_size > 4: font_size = max(4, font_size - max(2, int(font_size * 0.2))) font = "%s %s" % (font_base, font_size) layout.set_font_description(pango.FontDescription(font)) te = layout.get_pixel_extents() w = te[1][2] h = te[0][1] + te[0][3] x = a.width - w - p - d y = a.height - h - p - d make_path(ctx, x - p, y + te[0][1] - (p + 1), w + 2 * p, h - te[0][1] + 2 * (p + 1), r=4) if self.globals.settings["badge_custom_bg_color"]: color = self.globals.settings["badge_bg_color"] alpha = float(self.globals.settings["badge_bg_alpha"]) / 255 else: color = "#CDCDCD" alpha = 1.0 r = int(color[1:3], 16)/255.0 g = int(color[3:5], 16)/255.0 b = int(color[5:7], 16)/255.0 ctx.set_source_rgba(r, g, b, alpha) ctx.fill_preserve() if self.globals.settings["badge_custom_fg_color"]: color = self.globals.settings["badge_fg_color"] alpha = float(self.globals.settings["badge_fg_alpha"]) / 255 else: color = "#020202" alpha = 1.0 r = int(color[1:3], 16)/255.0 g = int(color[3:5], 16)/255.0 b = int(color[5:7], 16)/255.0 ctx.set_source_rgba(r, g, b, alpha) ctx.set_line_width(0.8) ctx.stroke() ctx.move_to(x,y) ctx.show_layout(layout) def make_progress_bar(self, progress): if progress is None: self.progress = None self.progress_bar = None return self.progress = progress a = self.area.get_allocation() x = max(0.1 * a.width, 2) y = max(0.15 * a.height, 3) w = min(max (0.60 * a.width, 20), a.width - 2 * x) h = max(0.10 * a.height, 3.0) ro = h / 2 self.progress_bar = cairo.ImageSurface(cairo.FORMAT_ARGB32, a.width, a.height) ctx = cairo.Context(self.progress_bar) ctx.move_to(x,y) ctx.line_to(x + w * progress, y) ctx.line_to(x + w * progress, y + h) ctx.line_to(x, y + h) ctx.close_path() ctx.clip() if self.globals.settings["progress_custom_fg_color"]: color = self.globals.settings["progress_fg_color"] alpha = float(self.globals.settings["progress_fg_alpha"]) / 255 else: color = "#772953" alpha = 1.0 r = int(color[1:3], 16)/255.0 g = int(color[3:5], 16)/255.0 b = int(color[5:7], 16)/255.0 ctx.set_source_rgba(r, g, b, alpha) make_path(ctx, x, y, w, h, r=ro, b=0) ctx.fill() ctx.reset_clip() ctx.move_to(x + w * progress,y) ctx.line_to(x + w, y) ctx.line_to(x + w, y + h) ctx.line_to(x + w * progress, y + h) ctx.clip() make_path(ctx, x, y, w, h, r=ro, b=0) if self.globals.settings["progress_custom_bg_color"]: color = self.globals.settings["progress_bg_color"] bg_alpha = float(self.globals.settings["progress_bg_alpha"]) / 255 else: color = "#CDCDCD" bg_alpha = 0.25 br = int(color[1:3], 16)/255.0 bg = int(color[3:5], 16)/255.0 bb = int(color[5:7], 16)/255.0 ctx.set_source_rgba(br, bg, bb, bg_alpha) ctx.fill_preserve() ctx.reset_clip() ctx.set_source_rgba(r, g, b, alpha) ctx.set_line_width(0.8) ctx.stroke_preserve() def __on_badge_look_changed(self, *args): if self.badge: self.make_badge(self.badge_text) self.update() def __on_progress_bar_look_changed(self, *args): if self.progress_bar: self.make_progress_bar(self.progress) self.update() def destroy(self, *args, **kwargs): if self.bl_sid: self.globals.disconnect(self.bl_sid) self.bl_sid = None if self.pbl_sid: self.globals.disconnect(self.pbl_sid) self.pbl_sid = None if self.surface: self.surface = None gtk.EventBox.destroy(self, *args, **kwargs) def pointer_is_inside(self): b_m_x,b_m_y = self.get_pointer() b_r = self.get_allocation() if b_m_x >= 0 and b_m_x < b_r.width and \ b_m_y >= 0 and b_m_y < b_r.height: return True else: return False
class DockManager(dbus.service.Object): def __new__(cls, dockbar): if "net.launchpad.DockManager" in dbus.SessionBus().list_names(): logger.debug("Name net.launchpad.DockManager is already" + \ " in use. (This instance of) DockbarX will" + \ " not use DockManager.") return None else: return dbus.service.Object.__new__(cls) def __init__(self, dockbar): self.dockbar_r = weakref.ref(dockbar) bus_name = dbus.service.BusName("net.launchpad.DockManager", bus = dbus.SessionBus()) dbus.service.Object.__init__(self, bus_name, "/net/launchpad/DockManager") self.globals = Globals() @dbus.service.method(dbus_interface="net.launchpad.DockManager", in_signature="", out_signature="as",) def GetCapabilities(self): capabilities = ["menu-item-container-title", "menu-item-icon-file", "menu-item-icon-name", "menu-item-with-label", "dock-item-badge", "dock-item-progress"] return capabilities @dbus.service.method(dbus_interface="net.launchpad.DockManager", in_signature="", out_signature="ao",) def GetItems(self): path_list = [] for path in self.dockbar_r().get_dm_paths(): path_list.append(dbus.ObjectPath(path)) return path_list @dbus.service.method(dbus_interface="net.launchpad.DockManager", in_signature="s", out_signature="ao",) def GetItemsByDesktopFile(self, name): path_list = [] for path in self.dockbar_r().get_dm_paths_by_desktop_file(name): path_list.append(dbus.ObjectPath(path)) logger.debug("Items gotten by dekstop file: %s" % path_list) return path_list @dbus.service.method(dbus_interface="net.launchpad.DockManager", in_signature="s", out_signature="ao",) def GetItemsByName(self, name): path_list = [] for path in self.dockbar_r().get_dm_paths_by_name(name): path_list.append(dbus.ObjectPath(path)) logger.debug("Items gotten by name: %s" % path_list) return path_list @dbus.service.method(dbus_interface="net.launchpad.DockManager", in_signature="i", out_signature="ao",) def GetItemsByPid(self, pid): path_list = [] for path in self.dockbar_r().get_dm_paths_by_pid(pid): path_list.append(dbus.ObjectPath(path)) logger.debug("Items gotten by pid: %s" % path_list) return path_list @dbus.service.method(dbus_interface="net.launchpad.DockManager", in_signature="x", out_signature="ao",) def GetItemsByXid(self, xid): path_list = [] for path in self.dockbar_r().get_dm_paths_by_xid(xid): path_list.append(dbus.ObjectPath(path)) logger.debug("Items gotten by xid: %s" % path_list) return path_list @dbus.service.signal(dbus_interface='net.launchpad.DockManager', signature='o') def ItemAdded(self, obj_path): pass @dbus.service.signal(dbus_interface='net.launchpad.DockManager', signature='o') def ItemRemoved(self, obj_path): pass @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='ss', out_signature='v') def Get(self, interface_name, property_name): return self.GetAll(interface_name)[property_name] @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='s', out_signature='a{sv}') def GetAll(self, interface_name): if interface_name == "net.launchpad.DockManager": return {} else: raise dbus.exceptions.DBusException( 'com.example.UnknownInterface', 'The Foo object does not implement the %s interface' % interface_name) @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='ssv', out_signature='') def Set(self, interface_name, property_name, property_value): pass @dbus.service.signal(dbus_interface=dbus.PROPERTIES_IFACE, signature='sa{sv}as') def PropertiesChanged(self, interface_name, changed_properties, invalidated_properties): pass def reset(self): try: bus = dbus.SessionBus() proxy = bus.get_object("net.launchpad.DockManager.Daemon", "/net/launchpad/DockManager/Daemon") proxy.RestartAll(dbus_interface="net.launchpad.DockManager.Daemon") except: logger.exception("Restarting DockManager Helpers failed.") def remove(self): self.remove_from_connection() self.globals.disconnect(self.badge_sid)