示例#1
0
	def __init__(self, adapter=None, tabledata=[]):
		def on_adapter_removed(path):
			self.emit("adapter-removed", path)
			if path == self.__adapter_path:
				self.clear()
				self.Adapter = None
				self.SetAdapter()	
				
		def on_adapter_added(path):
			def on_activate():
				dprint("adapter powered", path)
					
				if self.Adapter == None:
					self.SetAdapter(path)	
				
				self.emit("adapter-added", path)
								
			
			a = Bluez.Adapter(path)
			wait_for_adapter(a, on_activate)
			
		#cache for fast lookup in the list	
		self.address_to_row = {}
		self.path_to_row = {}
		
		self.monitored_devices = []
		self.discovered_devices = []

		self.signals = SignalTracker()
		
		try:
			self.Manager = Bluez.Manager("gobject")
			self.signals.Handle(self.Manager, on_adapter_removed, "AdapterRemoved")
			self.signals.Handle(self.Manager, on_adapter_added, "AdapterAdded")
		except:
			self.Manager = None
			
		self.__discovery_time = 0
		self.__adapter_path = None
		self.Adapter = None
		self.discovering = False
		

		
		data = []
		data = data + tabledata

		data = data +	[
			["device", object],
			["dbus_path", str]
		]
		
		GenericList.__init__(self, data)
		self.adapter_signals = SignalTracker()
		self.device_signals = SignalTracker()
		
		self.SetAdapter(adapter)
		
		
		self.signals.Handle(self.selection, "changed", self.on_selection_changed)
示例#2
0
    def __init__(self, adapter=None, tabledata=None):
        if not tabledata:
            tabledata = []

        def on_adapter_removed(path):
            self.emit("adapter-removed", path)
            if path == self.__adapter_path:
                self.clear()
                self.Adapter = None
                self.SetAdapter()

        def on_adapter_added(path):
            def on_activate():
                dprint("adapter powered", path)

                if self.Adapter is None:
                    self.SetAdapter(path)

                self.emit("adapter-added", path)

            a = Bluez.Adapter(path)
            wait_for_adapter(a, on_activate)

        #cache for fast lookup in the list
        self.address_to_row = {}
        self.path_to_row = {}

        self.monitored_devices = []
        self.discovered_devices = []

        self.signals = SignalTracker()

        try:
            self.Manager = Bluez.Manager("gobject")
            self.signals.Handle(self.Manager, on_adapter_removed, "AdapterRemoved")
            self.signals.Handle(self.Manager, on_adapter_added, "AdapterAdded")
        except:
            self.Manager = None

        self.__discovery_time = 0
        self.__adapter_path = None
        self.Adapter = None
        self.discovering = False

        data = []
        data = data + tabledata

        data = data + [
            ["device", object],
            ["dbus_path", str]
        ]

        GenericList.__init__(self, data)
        self.adapter_signals = SignalTracker()
        self.device_signals = SignalTracker()

        self.SetAdapter(adapter)

        self.signals.Handle(self.selection, "changed", self.on_selection_changed)
示例#3
0
 def destroy(self):
     dprint("destroying")
     #self.clear()
     if len(self.liststore):
         for i in self.liststore:
             iter = i.iter
             device = self.get(iter, "device")["device"]
         #device.Destroy()
     GenericList.destroy(self)
示例#4
0
    def __init__(self, adapter=None, tabledata=None):
        Gtk.TreeView.__init__(self)
        self.set_name("DeviceList")

        if not tabledata:
            tabledata = []

        def on_adapter_removed(_manager, path):
            self.emit("adapter-removed", path)
            if path == self.__adapter_path:
                self.clear()
                self.Adapter = None
                self.SetAdapter()

        def on_adapter_added(_manager, path):
            def on_activate():
                dprint("adapter powered", path)

                if self.Adapter is None:
                    self.SetAdapter(path)

                self.emit("adapter-added", path)

            a = Bluez.Adapter(path)
            wait_for_adapter(a, on_activate)

        #cache for fast lookup in the list
        self.address_to_row = {}
        self.path_to_row = {}

        self.monitored_devices = []

        self.manager = Bluez.Manager()
        self.manager.connect_signal('adapter-removed', on_adapter_removed)
        self.manager.connect_signal('adapter-added', on_adapter_added)

        self.__discovery_time = 0
        self.__adapter_path = None
        self.Adapter = None
        self.discovering = False

        data = []
        data = data + tabledata

        data = data + [
            ["device", object],
            ["dbus_path", str]
        ]

        GenericList.__init__(self, data)

        self.SetAdapter(adapter)

        self.selection.connect('changed', self.on_selection_changed)
示例#5
0
 def destroy(self):
     dprint("destroying")
     self.adapter_signals.DisconnectAll()
     self.device_signals.DisconnectAll()
     self.signals.DisconnectAll()
     self.device_signals = None
     #self.clear()
     if len(self.liststore):
         for i in self.liststore:
             iter = i.iter
             device = self.get(iter, "device")["device"]
         #device.Destroy()
     GenericList.destroy(self)
示例#6
0
	def destroy(self):
		dprint("destroying")
		self.adapter_signals.DisconnectAll()
		self.device_signals.DisconnectAll()
		self.signals.DisconnectAll()
		self.device_signals = None
		#self.clear()
		if len(self.liststore):
			for i in self.liststore:
				iter = i.iter
				device = self.get(iter, "device")["device"]
				#device.Destroy()
		GenericList.destroy(self)
示例#7
0
    def __init__(self, adapter=None, tabledata=None):
        Gtk.TreeView.__init__(self)
        self.set_name("DeviceList")

        if not tabledata:
            tabledata = []

        def on_adapter_removed(_manager, path):
            self.emit("adapter-removed", path)
            if path == self.__adapter_path:
                self.clear()
                self.Adapter = None
                self.SetAdapter()

        def on_adapter_added(_manager, path):
            def on_activate():
                dprint("adapter powered", path)

                if self.Adapter is None:
                    self.SetAdapter(path)

                self.emit("adapter-added", path)

            a = Bluez.Adapter(path)
            wait_for_adapter(a, on_activate)

        #cache for fast lookup in the list
        self.address_to_row = {}
        self.path_to_row = {}

        self.monitored_devices = []

        self.manager = Bluez.Manager()
        self.manager.connect_signal('adapter-removed', on_adapter_removed)
        self.manager.connect_signal('adapter-added', on_adapter_added)

        self.__discovery_time = 0
        self.__adapter_path = None
        self.Adapter = None
        self.discovering = False

        data = []
        data = data + tabledata

        data = data + [["device", object], ["dbus_path", str]]

        GenericList.__init__(self, data)

        self.SetAdapter(adapter)

        self.selection.connect('changed', self.on_selection_changed)
示例#8
0
    def __init__(self):
        super().__init__(
            title=_("Local Services"),
            name="BluemanServices",
            icon_name="blueman",
            border_width=5

        )

        grid = Gtk.Grid(orientation=Gtk.Orientation.VERTICAL, visible=True, row_spacing=10)
        self.add(grid)

        self.box = Gtk.Box(Gtk.Orientation.HORIZONTAL, vexpand=True, visible=True)
        grid.add(self.box)

        button_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, halign=Gtk.Align.END, visible=True)
        grid.add(button_box)

        self.b_apply = Gtk.Button("_Apply", receives_default=True, use_underline=True, sensitive=False, visible=True,
                                  width_request=80)
        button_box.add(self.b_apply)

        self.viewport = Gtk.Viewport(visible=True, width_request=120)

        self.box.add(self.viewport)

        self.connect("delete-event", Gtk.main_quit)

        self.Config = Config("org.blueman.general")

        check_single_instance("blueman-services", lambda time: self.present_with_time(time))

        data = [
            {"id": "icon_name", "type": str, "renderer": Gtk.CellRendererPixbuf(stock_size=Gtk.IconSize.DND),
             "render_attrs": {"icon_name": 0}},
            {"id": "caption", "type": str, "renderer": Gtk.CellRendererText(), "render_attrs": {"markup": 1},
             "view_props": {"expand": True}},
            {"id": "id", "type": str},
        ]

        self.List = ls = GenericList(data, headers_visible=False, visible=True)

        ls.selection.connect("changed", self.on_selection_changed)

        self.viewport.add(ls)

        self.load_plugins()

        ls.selection.select_path(self.Config["services-last-item"])

        self.b_apply.connect("clicked", self.on_apply_clicked)

        self.show()
示例#9
0
    def do_activate(self) -> None:
        if not self.window:
            self.window = Gtk.ApplicationWindow(application=self, title=_("Local Services"), icon_name="blueman",
                                                border_width=5)

            grid = Gtk.Grid(orientation=Gtk.Orientation.VERTICAL, visible=True, row_spacing=10)
            self.window.add(grid)

            self.box = Gtk.Box(vexpand=True, visible=True)
            grid.add(self.box)

            button_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, halign=Gtk.Align.END, visible=True)
            grid.add(button_box)

            self.b_apply = Gtk.Button(label="_Apply", receives_default=True, use_underline=True,
                                      sensitive=False, visible=True, width_request=80)
            button_box.add(self.b_apply)

            self.viewport = Gtk.Viewport(visible=True, width_request=120)

            self.box.add(self.viewport)

            self.Config = Config("org.blueman.general")

            data: List[ListDataDict] = [
                {"id": "icon_name", "type": str, "renderer": Gtk.CellRendererPixbuf(stock_size=Gtk.IconSize.DND),
                 "render_attrs": {"icon_name": 0}},
                {"id": "caption", "type": str, "renderer": Gtk.CellRendererText(), "render_attrs": {"markup": 1},
                 "view_props": {"expand": True}},
                {"id": "id", "type": str},
            ]

            self.List = ls = GenericList(data, headers_visible=False, visible=True)

            ls.selection.connect("changed", self.on_selection_changed)

            self.viewport.add(ls)

            self.load_plugins()

            ls.selection.select_path(self.Config["services-last-item"])

            self.b_apply.connect("clicked", self.on_apply_clicked)

        self.window.present_with_time(Gtk.get_current_event_time())
示例#10
0
    def __init__(self, applet):
        Gtk.Dialog.__init__(self, buttons=("_Close", Gtk.ResponseType.CLOSE))

        self.set_name("PluginDialog")
        self.applet = applet

        self.Builder = Gtk.Builder()
        self.Builder.set_translation_domain("blueman")
        bind_textdomain_codeset("blueman", "UTF-8")
        self.Builder.add_from_file(UI_PATH + "/applet-plugins-widget.ui")

        self.set_title(_("Plugins"))
        self.props.icon_name = "blueman"

        self.description = self.Builder.get_object("description")
        self.description.props.wrap = True

        self.icon = self.Builder.get_object("icon")
        self.author_txt = self.Builder.get_object("author_txt")
        self.depends_hdr = self.Builder.get_object("depends_hdr")
        self.depends_txt = self.Builder.get_object("depends_txt")
        self.conflicts_hdr = self.Builder.get_object("conflicts_hdr")
        self.conflicts_txt = self.Builder.get_object("conflicts_txt")
        self.plugin_name = self.Builder.get_object("name")

        self.main_container = self.Builder.get_object("main_container")
        self.content_grid = self.Builder.get_object("content")

        self.b_prefs = self.Builder.get_object("b_prefs")
        self.b_prefs.connect("toggled", self.on_prefs_toggled)

        widget = self.Builder.get_object("all")

        ref = weakref.ref(self)

        self.vbox.pack_start(widget, True, True, 0)

        cr = Gtk.CellRendererToggle()
        cr.connect("toggled", lambda *args: ref() and ref().on_toggled(*args))

        data = [
            ["active", bool, cr, {"active": 0, "activatable": 1, "visible": 1}, None],
            ["activatable", bool],
            ["icon", str, Gtk.CellRendererPixbuf(), {"icon-name": 2}, None],
            # device caption
            ["desc", str, Gtk.CellRendererText(), {"markup": 3}, None, {"expand": True}],
            ["name", str]
        ]

        self.list = GenericList(data)
        # self.sorted = Gtk.TreeModelSort(self.list.liststore)
        self.list.liststore.set_sort_column_id(3, Gtk.SortType.ASCENDING)
        self.list.liststore.set_sort_func(3, self.list_compare_func)

        self.list.selection.connect("changed", lambda *args: ref() and ref().on_selection_changed(*args))

        self.list.props.headers_visible = False
        self.list.show()

        self.props.border_width = 6
        self.resize(490, 380)

        self.Builder.get_object("viewport").add(self.list)

        self.populate()

        self.sig_a = self.applet.Plugins.connect("plugin-loaded", self.plugin_state_changed, True)
        self.sig_b = self.applet.Plugins.connect("plugin-unloaded", self.plugin_state_changed, False)
        self.connect("response", self.on_response)

        self.list.set_cursor(0)
示例#11
0
 def set(self, iterid: Gtk.TreeIter,
         **kwargs: object) -> None:  # type: ignore
     GenericList.set(self, iterid, **kwargs)
     self.do_cache(iterid, kwargs)
示例#12
0
class PluginDialog(Gtk.Dialog):
    def __init__(self, applet):
        Gtk.Dialog.__init__(self, buttons=("_Close", Gtk.ResponseType.CLOSE))

        self.set_name("PluginDialog")
        self.applet = applet

        self.Builder = Gtk.Builder()
        self.Builder.set_translation_domain("blueman")
        bind_textdomain_codeset("blueman", "UTF-8")
        self.Builder.add_from_file(UI_PATH + "/applet-plugins-widget.ui")

        self.set_title(_("Plugins"))
        self.props.icon_name = "blueman"

        self.description = self.Builder.get_object("description")
        self.description.props.wrap = True

        self.icon = self.Builder.get_object("icon")
        self.author_txt = self.Builder.get_object("author_txt")
        self.depends_hdr = self.Builder.get_object("depends_hdr")
        self.depends_txt = self.Builder.get_object("depends_txt")
        self.conflicts_hdr = self.Builder.get_object("conflicts_hdr")
        self.conflicts_txt = self.Builder.get_object("conflicts_txt")
        self.plugin_name = self.Builder.get_object("name")

        self.main_container = self.Builder.get_object("main_container")
        self.content_grid = self.Builder.get_object("content")

        self.b_prefs = self.Builder.get_object("b_prefs")
        self.b_prefs.connect("toggled", self.on_prefs_toggled)

        widget = self.Builder.get_object("all")

        ref = weakref.ref(self)

        self.vbox.pack_start(widget, True, True, 0)

        cr = Gtk.CellRendererToggle()
        cr.connect("toggled", lambda *args: ref() and ref().on_toggled(*args))

        data = [
            ["active", bool, cr, {"active": 0, "activatable": 1, "visible": 1}, None],
            ["activatable", bool],
            ["icon", str, Gtk.CellRendererPixbuf(), {"icon-name": 2}, None],
            # device caption
            ["desc", str, Gtk.CellRendererText(), {"markup": 3}, None, {"expand": True}],
            ["name", str]
        ]

        self.list = GenericList(data)
        # self.sorted = Gtk.TreeModelSort(self.list.liststore)
        self.list.liststore.set_sort_column_id(3, Gtk.SortType.ASCENDING)
        self.list.liststore.set_sort_func(3, self.list_compare_func)

        self.list.selection.connect("changed", lambda *args: ref() and ref().on_selection_changed(*args))

        self.list.props.headers_visible = False
        self.list.show()

        self.props.border_width = 6
        self.resize(490, 380)

        self.Builder.get_object("viewport").add(self.list)

        self.populate()

        self.sig_a = self.applet.Plugins.connect("plugin-loaded", self.plugin_state_changed, True)
        self.sig_b = self.applet.Plugins.connect("plugin-unloaded", self.plugin_state_changed, False)
        self.connect("response", self.on_response)

        self.list.set_cursor(0)

    def list_compare_func(self, treemodel, iter1, iter2, user_data):
        a = self.list.get(iter1, "activatable", "name")
        b = self.list.get(iter2, "activatable", "name")

        if (a["activatable"] and b["activatable"]) or (not a["activatable"] and not b["activatable"]):
            if a["name"] == b["name"]:
                return 0
            if a["name"] < b["name"]:
                return -1
            else:
                return 1

        else:
            if a["activatable"] and not b["activatable"]:
                return -1
            elif not a["activatable"] and b["activatable"]:
                return 1


    def on_response(self, dialog, resp):
        self.applet.Plugins.disconnect(self.sig_a)
        self.applet.Plugins.disconnect(self.sig_b)

    def on_selection_changed(self, selection):
        model, iter = selection.get_selected()

        name = self.list.get(iter, "name")["name"]
        cls = self.applet.Plugins.GetClasses()[name]
        self.plugin_name.props.label = "<b>" + name + "</b>"
        self.icon.props.icon_name = cls.__icon__
        self.author_txt.props.label = cls.__author__ or _("Unspecified")
        self.description.props.label = cls.__description__ or _("Unspecified")

        if cls.__depends__ != []:
            self.depends_hdr.props.visible = True
            self.depends_txt.props.visible = True
            self.depends_txt.props.label = ", ".join(cls.__depends__)
        else:
            self.depends_hdr.props.visible = False
            self.depends_txt.props.visible = False

        if cls.__conflicts__ != []:
            self.conflicts_hdr.props.visible = True
            self.conflicts_txt.props.visible = True
            self.conflicts_txt.props.label = ", ".join(cls.__conflicts__)
        else:
            self.conflicts_hdr.props.visible = False
            self.conflicts_txt.props.visible = False

        if cls.is_configurable() and name in self.applet.Plugins.GetLoaded():
            self.b_prefs.props.sensitive = True
        else:
            self.b_prefs.props.sensitive = False

        self.update_config_widget(cls)

    def on_prefs_toggled(self, button):
        model, iter = self.list.selection.get_selected()
        name = self.list.get(iter, "name")["name"]
        cls = self.applet.Plugins.GetClasses()[name]

        self.update_config_widget(cls)

    def update_config_widget(self, cls):
        if self.b_prefs.props.active:
            if not cls.is_configurable():
                self.b_prefs.props.active = False
                return

            if not cls.__instance__:
                self.b_prefs.props.active = False
            else:
                c = self.main_container.get_child()
                self.main_container.remove(c)
                if isinstance(c, SettingsWidget):
                    c.destroy()

                self.main_container.add(SettingsWidget(cls.__instance__))

        else:
            c = self.main_container.get_child()
            self.main_container.remove(c)
            if isinstance(c, SettingsWidget):
                c.destroy()
            self.main_container.add(self.content_grid)

    def populate(self):
        classes = self.applet.Plugins.GetClasses()
        loaded = self.applet.Plugins.GetLoaded()
        for name, cls in classes.items():
            if cls.is_configurable():
                desc = "<span weight=\"bold\">%s</span>" % name
            else:
                desc = name
            self.list.append(active=(name in loaded), icon=cls.__icon__, activatable=(cls.__unloadable__), name=name,
                             desc=desc)

    def plugin_state_changed(self, plugins, name, loaded):
        row = self.list.get_conditional(name=name)
        self.list.set(row[0], active=loaded)

        cls = self.applet.Plugins.GetClasses()[name]
        if not loaded:
            self.update_config_widget(cls)
            self.b_prefs.props.sensitive = False
        elif cls.is_configurable():
            self.b_prefs.props.sensitive = True

    def on_toggled(self, cellrenderer, path):
        name = self.list.get(path, "name")["name"]

        deps = self.applet.Plugins.GetDependencies()[name]
        loaded = self.applet.Plugins.GetLoaded()
        to_unload = []
        for dep in deps:
            if dep in loaded:
                to_unload.append(dep)

        if to_unload != []:
            dialog = Gtk.MessageDialog(self, type=Gtk.MessageType.QUESTION, buttons=Gtk.ButtonsType.YES_NO)
            dialog.props.secondary_use_markup = True
            dialog.props.icon_name = "blueman"
            dialog.props.text = _("Dependency issue")
            dialog.props.secondary_text = _(
                "Plugin <b>\"%(0)s\"</b> depends on <b>%(1)s</b>. Unloading <b>%(1)s</b> will also unload <b>\"%(0)s\"</b>.\nProceed?") % {
                                          "0": ", ".join(to_unload), "1": name}

            resp = dialog.run()
            if resp != Gtk.ResponseType.YES:
                dialog.destroy()
                return

            dialog.destroy()

        conflicts = self.applet.Plugins.GetConflicts()[name]
        to_unload = []
        for conf in conflicts:
            if conf in loaded:
                to_unload.append(conf)

        if to_unload != []:
            dialog = Gtk.MessageDialog(self, type=Gtk.MessageType.QUESTION, buttons=Gtk.ButtonsType.YES_NO)
            dialog.props.secondary_use_markup = True
            dialog.props.icon_name = "blueman"
            dialog.props.text = _("Dependency issue")
            dialog.props.secondary_text = _(
                "Plugin <b>%(0)s</b> conflicts with <b>%(1)s</b>. Loading <b>%(1)s</b> will unload <b>%(0)s</b>.\nProceed?") % {
                                          "0": ", ".join(to_unload), "1": name}

            resp = dialog.run()
            if resp != Gtk.ResponseType.YES:
                dialog.destroy()
                return

            dialog.destroy()

            for p in to_unload:
                self.applet.Plugins.SetConfig(p, False)

        loaded = name in self.applet.Plugins.GetLoaded()
        cls = self.applet.Plugins.SetConfig(name, not loaded)
示例#13
0
class PluginDialog(Gtk.Window):
    def __init__(self, applet):
        super().__init__(
            title=_("Plugins"),
            icon_name="blueman",
            name="PluginDialog",
            border_width=6,
            default_width=490,
            default_height=380,
            resizable=False,
            visible=False
        )

        self.applet = applet

        self.Builder = Gtk.Builder(translation_domain="blueman")
        bind_textdomain_codeset("blueman", "UTF-8")
        self.Builder.add_from_file(UI_PATH + "/applet-plugins-widget.ui")

        self.description = self.Builder.get_object("description")

        self.icon = self.Builder.get_object("icon")
        self.author_txt = self.Builder.get_object("author_txt")
        self.depends_hdr = self.Builder.get_object("depends_hdr")
        self.depends_txt = self.Builder.get_object("depends_txt")
        self.conflicts_hdr = self.Builder.get_object("conflicts_hdr")
        self.conflicts_txt = self.Builder.get_object("conflicts_txt")
        self.plugin_name = self.Builder.get_object("name")

        self.main_container = self.Builder.get_object("main_container")
        self.content_grid = self.Builder.get_object("content")

        self.b_prefs = self.Builder.get_object("b_prefs")
        self.b_prefs.connect("toggled", self.on_prefs_toggled)

        ref = weakref.ref(self)

        self.add(self.Builder.get_object("all"))

        cr = Gtk.CellRendererToggle()
        cr.connect("toggled", lambda *args: ref() and ref().on_toggled(*args))

        data = [
            {"id": "active", "type": bool, "renderer": cr, "render_attrs": {"active": 0, "activatable": 1,
                                                                            "visible": 1}},
            {"id": "activatable", "type": bool},
            {"id": "icon", "type": str, "renderer": Gtk.CellRendererPixbuf(), "render_attrs": {"icon-name": 2}},
            # device caption
            {"id": "desc", "type": str, "renderer": Gtk.CellRendererText(), "render_attrs": {"markup": 3},
             "view_props": {"expand": True}},
            {"id": "name", "type": str},
        ]

        self.list = GenericList(data, headers_visible=False, visible=True)
        self.list.liststore.set_sort_column_id(3, Gtk.SortType.ASCENDING)
        self.list.liststore.set_sort_func(3, self.list_compare_func)

        self.list.selection.connect("changed", lambda *args: ref() and ref().on_selection_changed(*args))

        plugin_list = self.Builder.get_object("plugin_list")
        plugin_info = self.Builder.get_object("main_scrolled_window")
        plugin_list.add(self.list)

        # Disable overlay scrolling
        if Gtk.get_minor_version() >= 16:
            plugin_list.props.overlay_scrolling = False
            plugin_info.props.overlay_scrolling = False

        self.populate()

        self.sig_a = self.applet.Plugins.connect("plugin-loaded", self.plugin_state_changed, True)
        self.sig_b = self.applet.Plugins.connect("plugin-unloaded", self.plugin_state_changed, False)
        self.connect("delete-event", self._on_close)

        self.list.set_cursor(0)

    def list_compare_func(self, treemodel, iter1, iter2, user_data):
        a = self.list.get(iter1, "activatable", "name")
        b = self.list.get(iter2, "activatable", "name")

        if (a["activatable"] and b["activatable"]) or (not a["activatable"] and not b["activatable"]):
            if a["name"] == b["name"]:
                return 0
            if a["name"] < b["name"]:
                return -1
            else:
                return 1

        else:
            if a["activatable"] and not b["activatable"]:
                return -1
            elif not a["activatable"] and b["activatable"]:
                return 1

    def _on_close(self, *args, **kwargs):
        self.applet.Plugins.disconnect(self.sig_a)
        self.applet.Plugins.disconnect(self.sig_b)

    def on_selection_changed(self, selection):
        model, tree_iter = selection.get_selected()

        name = self.list.get(tree_iter, "name")["name"]
        cls = self.applet.Plugins.get_classes()[name]
        self.plugin_name.props.label = "<b>" + name + "</b>"
        self.icon.props.icon_name = cls.__icon__
        self.author_txt.props.label = cls.__author__ or _("Unspecified")
        self.description.props.label = cls.__description__ or _("Unspecified")

        if cls.__depends__:
            self.depends_hdr.props.visible = True
            self.depends_txt.props.visible = True
            self.depends_txt.props.label = ", ".join(cls.__depends__)
        else:
            self.depends_hdr.props.visible = False
            self.depends_txt.props.visible = False

        if cls.__conflicts__:
            self.conflicts_hdr.props.visible = True
            self.conflicts_txt.props.visible = True
            self.conflicts_txt.props.label = ", ".join(cls.__conflicts__)
        else:
            self.conflicts_hdr.props.visible = False
            self.conflicts_txt.props.visible = False

        if cls.is_configurable() and name in self.applet.Plugins.get_loaded():
            self.b_prefs.props.sensitive = True
        else:
            self.b_prefs.props.sensitive = False

        self.update_config_widget(cls)

    def on_prefs_toggled(self, button):
        model, tree_iter = self.list.selection.get_selected()
        name = self.list.get(tree_iter, "name")["name"]
        cls = self.applet.Plugins.get_classes()[name]

        self.update_config_widget(cls)

    def update_config_widget(self, cls):
        if self.b_prefs.props.active:
            if not cls.is_configurable():
                self.b_prefs.props.active = False
                return

            if not cls.__instance__:
                self.b_prefs.props.active = False
            else:
                c = self.main_container.get_child()
                self.main_container.remove(c)
                if isinstance(c, SettingsWidget):
                    c.destroy()

                self.main_container.add(SettingsWidget(cls.__instance__))

        else:
            c = self.main_container.get_child()
            self.main_container.remove(c)
            if isinstance(c, SettingsWidget):
                c.destroy()
            self.main_container.add(self.content_grid)

    def populate(self):
        classes = self.applet.Plugins.get_classes()
        loaded = self.applet.Plugins.get_loaded()
        for name, cls in classes.items():
            if cls.is_configurable():
                desc = "<span weight=\"bold\">%s</span>" % name
            else:
                desc = name
            self.list.append(active=(name in loaded), icon=cls.__icon__, activatable=cls.__unloadable__, name=name,
                             desc=desc)

    def plugin_state_changed(self, plugins, name, loaded):
        row = self.list.get_conditional(name=name)
        self.list.set(row[0], active=loaded)

        cls = self.applet.Plugins.get_classes()[name]
        if not loaded:
            self.update_config_widget(cls)
            self.b_prefs.props.sensitive = False
        elif cls.is_configurable():
            self.b_prefs.props.sensitive = True

    def on_toggled(self, cellrenderer, path):
        name = self.list.get(path, "name")["name"]

        deps = self.applet.Plugins.get_dependencies()[name]
        loaded = self.applet.Plugins.get_loaded()
        to_unload = []
        for dep in deps:
            if dep in loaded:
                to_unload.append(dep)

        if to_unload:
            dialog = Gtk.MessageDialog(self, type=Gtk.MessageType.QUESTION, buttons=Gtk.ButtonsType.YES_NO)
            dialog.props.secondary_use_markup = True
            dialog.props.icon_name = "blueman"
            dialog.props.text = _("Dependency issue")
            dialog.props.secondary_text = \
                _("Plugin <b>\"%(0)s\"</b> depends on <b>%(1)s</b>. Unloading <b>%(1)s</b> will also unload <b>"
                  "\"%(0)s\"</b>.\nProceed?") % {"0": ", ".join(to_unload), "1": name}

            resp = dialog.run()
            if resp != Gtk.ResponseType.YES:
                dialog.destroy()
                return

            dialog.destroy()

        conflicts = self.applet.Plugins.get_conflicts()[name]
        to_unload = []
        for conf in conflicts:
            if conf in loaded:
                to_unload.append(conf)

        if to_unload:
            dialog = Gtk.MessageDialog(self, type=Gtk.MessageType.QUESTION, buttons=Gtk.ButtonsType.YES_NO)
            dialog.props.secondary_use_markup = True
            dialog.props.icon_name = "blueman"
            dialog.props.text = _("Dependency issue")
            dialog.props.secondary_text = \
                _("Plugin <b>%(0)s</b> conflicts with <b>%(1)s</b>. Loading <b>%(1)s</b> will unload <b>%(0)s</b>."
                  "\nProceed?") % {"0": ", ".join(to_unload), "1": name}

            resp = dialog.run()
            if resp != Gtk.ResponseType.YES:
                dialog.destroy()
                return

            dialog.destroy()

            for p in to_unload:
                self.applet.Plugins.set_config(p, False)

        loaded = name in self.applet.Plugins.get_loaded()
        self.applet.Plugins.set_config(name, not loaded)
示例#14
0
    def __init__(self):
        super(BluemanServices, self).__init__(title=_("Local Services"))
        self.resize(520, 420)
        self.set_name("BluemanServices")
        self.set_position(Gtk.WindowPosition.CENTER)
        self.props.border_width = 5
        self.props.icon_name = "blueman"

        self.b_apply = self.add_button("_Apply", Gtk.ResponseType.APPLY)
        self.b_apply.props.receives_default = True
        self.b_apply.props.sensitive = False
        self.b_apply.props.use_underline = True

        self.b_close = self.add_button("_Close", Gtk.ResponseType.CLOSE)
        self.b_close.props.use_underline = True

        self.content_area = self.get_content_area()

        self.box = Gtk.Box(Gtk.Orientation.HORIZONTAL)
        self.box.props.vexpand = True
        self.box.props.visible = True

        self.viewport = Gtk.Viewport()
        self.viewport.props.visible = True
        self.viewport.props.width_request = 120

        self.box.add(self.viewport)
        self.content_area.add(self.box)

        self.connect("delete-event", Gtk.main_quit)

        self.Config = Config("org.blueman.general")

        check_single_instance("blueman-services", lambda time: self.Dialog.present_with_time(time))

        data = [
            {"id": "icon_name", "type": str, "renderer": Gtk.CellRendererPixbuf(stock_size=Gtk.IconSize.DND),
             "render_attrs": {"icon_name": 0}},
            {"id": "caption", "type": str, "renderer": Gtk.CellRendererText(), "render_attrs": {"markup": 1},
             "view_props": {"expand": True}},
            {"id": "id", "type": str},
        ]

        ls = GenericList(data)
        ls.props.headers_visible = False

        ls.selection.connect("changed", self.on_selection_changed)
        self.List = ls

        self.viewport.add(ls)
        ls.show()

        self.load_plugins()

        try:
            ls.selection.select_path(self.Config["services-last-item"])
        except:
            ls.selection.select_path(0)

        self.b_apply.connect("clicked", self.on_apply_clicked)
        self.b_close.connect("clicked", Gtk.main_quit)

        self.show()
示例#15
0
 def append(self, **columns):
     iter = GenericList.append(self, **columns)
     self.do_cache(iter, columns)
示例#16
0
 def prepend(self, **columns):
     tree_iter = GenericList.prepend(self, **columns)
     self.do_cache(tree_iter, columns)
示例#17
0
class PluginDialog(Gtk.Window):
    def __init__(self, applet):
        super().__init__(title=_("Plugins"),
                         icon_name="blueman",
                         name="PluginDialog",
                         border_width=6,
                         default_width=490,
                         default_height=380,
                         resizable=False,
                         visible=False)

        self.applet = applet

        self.Builder = Gtk.Builder(translation_domain="blueman")
        self.Builder.add_from_file(UI_PATH + "/applet-plugins-widget.ui")

        self.description = self.Builder.get_object("description")

        self.icon = self.Builder.get_object("icon")
        self.author_txt = self.Builder.get_object("author_txt")
        self.depends_hdr = self.Builder.get_object("depends_hdr")
        self.depends_txt = self.Builder.get_object("depends_txt")
        self.conflicts_hdr = self.Builder.get_object("conflicts_hdr")
        self.conflicts_txt = self.Builder.get_object("conflicts_txt")
        self.plugin_name = self.Builder.get_object("name")

        self.main_container = self.Builder.get_object("main_container")
        self.content_grid = self.Builder.get_object("content")

        self.b_prefs = self.Builder.get_object("b_prefs")
        self.b_prefs.connect("toggled", self.on_prefs_toggled)

        self.add(self.Builder.get_object("all"))

        cr = Gtk.CellRendererToggle()
        cr.connect("toggled", self.on_toggled)

        data = [
            {
                "id": "active",
                "type": bool,
                "renderer": cr,
                "render_attrs": {
                    "active": 0,
                    "activatable": 1,
                    "visible": 1
                }
            },
            {
                "id": "activatable",
                "type": bool
            },
            {
                "id": "icon",
                "type": str,
                "renderer": Gtk.CellRendererPixbuf(),
                "render_attrs": {
                    "icon-name": 2
                }
            },
            # device caption
            {
                "id": "desc",
                "type": str,
                "renderer": Gtk.CellRendererText(),
                "render_attrs": {
                    "markup": 3
                },
                "view_props": {
                    "expand": True
                }
            },
            {
                "id": "name",
                "type": str
            },
        ]

        self.list = GenericList(data, headers_visible=False, visible=True)
        self.list.liststore.set_sort_column_id(3, Gtk.SortType.ASCENDING)
        self.list.liststore.set_sort_func(3, self.list_compare_func)

        self.list.selection.connect("changed", self.on_selection_changed)

        plugin_list = self.Builder.get_object("plugin_list")
        plugin_info = self.Builder.get_object("main_scrolled_window")
        plugin_list.add(self.list)

        # Disable overlay scrolling
        if Gtk.get_minor_version() >= 16:
            plugin_list.props.overlay_scrolling = False
            plugin_info.props.overlay_scrolling = False

        self.populate()

        self.sig_a: int = self.applet.Plugins.connect(
            "plugin-loaded", self.plugin_state_changed, True)
        self.sig_b: int = self.applet.Plugins.connect(
            "plugin-unloaded", self.plugin_state_changed, False)
        self.connect("delete-event", self._on_close)

        self.list.set_cursor(0)

    def list_compare_func(self, treemodel, iter1, iter2, user_data):
        a = self.list.get(iter1, "activatable", "name")
        b = self.list.get(iter2, "activatable", "name")

        if (a["activatable"]
                and b["activatable"]) or (not a["activatable"]
                                          and not b["activatable"]):
            if a["name"] == b["name"]:
                return 0
            if a["name"] < b["name"]:
                return -1
            else:
                return 1

        else:
            if a["activatable"] and not b["activatable"]:
                return -1
            elif not a["activatable"] and b["activatable"]:
                return 1

    def _on_close(self, *args, **kwargs):
        self.applet.Plugins.disconnect(self.sig_a)
        self.applet.Plugins.disconnect(self.sig_b)

    def on_selection_changed(self, selection):
        model, tree_iter = selection.get_selected()

        name = self.list.get(tree_iter, "name")["name"]
        cls = self.applet.Plugins.get_classes()[name]
        self.plugin_name.props.label = "<b>" + name + "</b>"
        self.icon.props.icon_name = cls.__icon__
        self.author_txt.props.label = cls.__author__
        self.description.props.label = cls.__description__

        if cls.__depends__:
            self.depends_hdr.props.visible = True
            self.depends_txt.props.visible = True
            self.depends_txt.props.label = ", ".join(cls.__depends__)
        else:
            self.depends_hdr.props.visible = False
            self.depends_txt.props.visible = False

        if cls.__conflicts__:
            self.conflicts_hdr.props.visible = True
            self.conflicts_txt.props.visible = True
            self.conflicts_txt.props.label = ", ".join(cls.__conflicts__)
        else:
            self.conflicts_hdr.props.visible = False
            self.conflicts_txt.props.visible = False

        if cls.is_configurable() and name in self.applet.Plugins.get_loaded():
            self.b_prefs.props.sensitive = True
        else:
            self.b_prefs.props.sensitive = False

        self.update_config_widget(cls)

    def on_prefs_toggled(self, button):
        model, tree_iter = self.list.selection.get_selected()
        name = self.list.get(tree_iter, "name")["name"]
        cls = self.applet.Plugins.get_classes()[name]

        self.update_config_widget(cls)

    def update_config_widget(self, cls):
        if self.b_prefs.props.active:
            if not cls.is_configurable():
                self.b_prefs.props.active = False
                return

            if not cls.__instance__:
                self.b_prefs.props.active = False
            else:
                c = self.main_container.get_child()
                self.main_container.remove(c)
                if isinstance(c, SettingsWidget):
                    c.destroy()

                self.main_container.add(SettingsWidget(cls.__instance__))

        else:
            c = self.main_container.get_child()
            self.main_container.remove(c)
            if isinstance(c, SettingsWidget):
                c.destroy()
            self.main_container.add(self.content_grid)

    def populate(self):
        classes = self.applet.Plugins.get_classes()
        loaded = self.applet.Plugins.get_loaded()
        for name, cls in classes.items():
            if cls.is_configurable():
                desc = f"<span weight=\"bold\">{name}</span>"
            else:
                desc = name
            self.list.append(active=(name in loaded),
                             icon=cls.__icon__,
                             activatable=cls.__unloadable__,
                             name=name,
                             desc=desc)

    def plugin_state_changed(self, plugins, name, loaded):
        row = self.list.get_conditional(name=name)
        self.list.set(row[0], active=loaded)

        cls = self.applet.Plugins.get_classes()[name]
        if not loaded:
            self.update_config_widget(cls)
            self.b_prefs.props.sensitive = False
        elif cls.is_configurable():
            self.b_prefs.props.sensitive = True

    def on_toggled(self, cellrenderer, path):
        name = self.list.get(path, "name")["name"]

        deps = self.applet.Plugins.get_dependencies()[name]
        loaded = self.applet.Plugins.get_loaded()
        to_unload = []
        for dep in deps:
            if dep in loaded:
                to_unload.append(dep)

        if to_unload:
            dialog = Gtk.MessageDialog(self,
                                       type=Gtk.MessageType.QUESTION,
                                       buttons=Gtk.ButtonsType.YES_NO)
            dialog.props.secondary_use_markup = True
            dialog.props.icon_name = "blueman"
            dialog.props.text = _("Dependency issue")
            dialog.props.secondary_text = \
                _("Plugin <b>\"%(0)s\"</b> depends on <b>%(1)s</b>. Unloading <b>%(1)s</b> will also unload <b>"
                  "\"%(0)s\"</b>.\nProceed?") % {"0": ", ".join(to_unload), "1": name}

            resp = dialog.run()
            if resp != Gtk.ResponseType.YES:
                dialog.destroy()
                return

            dialog.destroy()

        conflicts = self.applet.Plugins.get_conflicts()[name]
        to_unload = []
        for conf in conflicts:
            if conf in loaded:
                to_unload.append(conf)

        if to_unload:
            dialog = Gtk.MessageDialog(self,
                                       type=Gtk.MessageType.QUESTION,
                                       buttons=Gtk.ButtonsType.YES_NO)
            dialog.props.secondary_use_markup = True
            dialog.props.icon_name = "blueman"
            dialog.props.text = _("Dependency issue")
            dialog.props.secondary_text = \
                _("Plugin <b>%(0)s</b> conflicts with <b>%(1)s</b>. Loading <b>%(1)s</b> will unload <b>%(0)s</b>."
                  "\nProceed?") % {"0": ", ".join(to_unload), "1": name}

            resp = dialog.run()
            if resp != Gtk.ResponseType.YES:
                dialog.destroy()
                return

            dialog.destroy()

            for p in to_unload:
                self.applet.Plugins.set_config(p, False)

        loaded = name in self.applet.Plugins.get_loaded()
        self.applet.Plugins.set_config(name, not loaded)
示例#18
0
class PluginDialog(Gtk.Dialog):
    def __init__(self, applet):
        super(PluginDialog, self).__init__(buttons=("_Close", Gtk.ResponseType.CLOSE))

        self.set_name("PluginDialog")
        self.applet = applet

        self.Builder = Gtk.Builder()
        self.Builder.set_translation_domain("blueman")
        bind_textdomain_codeset("blueman", "UTF-8")
        self.Builder.add_from_file(UI_PATH + "/applet-plugins-widget.ui")

        self.set_title(_("Plugins"))
        self.props.icon_name = "blueman"

        self.description = self.Builder.get_object("description")
        self.description.props.wrap = True

        self.icon = self.Builder.get_object("icon")
        self.author_txt = self.Builder.get_object("author_txt")
        self.depends_hdr = self.Builder.get_object("depends_hdr")
        self.depends_txt = self.Builder.get_object("depends_txt")
        self.conflicts_hdr = self.Builder.get_object("conflicts_hdr")
        self.conflicts_txt = self.Builder.get_object("conflicts_txt")
        self.plugin_name = self.Builder.get_object("name")

        self.main_container = self.Builder.get_object("main_container")
        self.content_grid = self.Builder.get_object("content")

        self.b_prefs = self.Builder.get_object("b_prefs")
        self.b_prefs.connect("toggled", self.on_prefs_toggled)

        widget = self.Builder.get_object("all")

        ref = weakref.ref(self)

        self.vbox.pack_start(widget, True, True, 0)

        cr = Gtk.CellRendererToggle()
        cr.connect("toggled", lambda *args: ref() and ref().on_toggled(*args))

        data = [
            ["active", bool, cr, {"active": 0, "activatable": 1, "visible": 1}, None],
            ["activatable", bool],
            ["icon", str, Gtk.CellRendererPixbuf(), {"icon-name": 2}, None],
            # device caption
            ["desc", str, Gtk.CellRendererText(), {"markup": 3}, None, {"expand": True}],
            ["name", str]
        ]

        self.list = GenericList(data)
        # self.sorted = Gtk.TreeModelSort(self.list.liststore)
        self.list.liststore.set_sort_column_id(3, Gtk.SortType.ASCENDING)
        self.list.liststore.set_sort_func(3, self.list_compare_func)

        self.list.selection.connect("changed", lambda *args: ref() and ref().on_selection_changed(*args))

        self.list.props.headers_visible = False
        self.list.show()

        self.props.border_width = 6
        self.resize(490, 380)

        viewport = self.Builder.get_object("viewport")
        viewport.add(self.list)

        sw = self.Builder.get_object("main_scrolled_window")

        # Disable overlay scrolling
        if Gtk.get_minor_version() >= 16:
            viewport.props.overlay_scrolling = False
            sw.props.overlay_scrolling = False

        self.populate()

        self.sig_a = self.applet.Plugins.connect("plugin-loaded", self.plugin_state_changed, True)
        self.sig_b = self.applet.Plugins.connect("plugin-unloaded", self.plugin_state_changed, False)
        self.connect("response", self.on_response)

        self.list.set_cursor(0)

    def list_compare_func(self, treemodel, iter1, iter2, user_data):
        a = self.list.get(iter1, "activatable", "name")
        b = self.list.get(iter2, "activatable", "name")

        if (a["activatable"] and b["activatable"]) or (not a["activatable"] and not b["activatable"]):
            if a["name"] == b["name"]:
                return 0
            if a["name"] < b["name"]:
                return -1
            else:
                return 1

        else:
            if a["activatable"] and not b["activatable"]:
                return -1
            elif not a["activatable"] and b["activatable"]:
                return 1

    def on_response(self, dialog, resp):
        self.applet.Plugins.disconnect(self.sig_a)
        self.applet.Plugins.disconnect(self.sig_b)

    def on_selection_changed(self, selection):
        model, tree_iter = selection.get_selected()

        name = self.list.get(tree_iter, "name")["name"]
        cls = self.applet.Plugins.GetClasses()[name]
        self.plugin_name.props.label = "<b>" + name + "</b>"
        self.icon.props.icon_name = cls.__icon__
        self.author_txt.props.label = cls.__author__ or _("Unspecified")
        self.description.props.label = cls.__description__ or _("Unspecified")

        if cls.__depends__:
            self.depends_hdr.props.visible = True
            self.depends_txt.props.visible = True
            self.depends_txt.props.label = ", ".join(cls.__depends__)
        else:
            self.depends_hdr.props.visible = False
            self.depends_txt.props.visible = False

        if cls.__conflicts__:
            self.conflicts_hdr.props.visible = True
            self.conflicts_txt.props.visible = True
            self.conflicts_txt.props.label = ", ".join(cls.__conflicts__)
        else:
            self.conflicts_hdr.props.visible = False
            self.conflicts_txt.props.visible = False

        if cls.is_configurable() and name in self.applet.Plugins.GetLoaded():
            self.b_prefs.props.sensitive = True
        else:
            self.b_prefs.props.sensitive = False

        self.update_config_widget(cls)

    def on_prefs_toggled(self, button):
        model, tree_iter = self.list.selection.get_selected()
        name = self.list.get(tree_iter, "name")["name"]
        cls = self.applet.Plugins.GetClasses()[name]

        self.update_config_widget(cls)

    def update_config_widget(self, cls):
        if self.b_prefs.props.active:
            if not cls.is_configurable():
                self.b_prefs.props.active = False
                return

            if not cls.__instance__:
                self.b_prefs.props.active = False
            else:
                c = self.main_container.get_child()
                self.main_container.remove(c)
                if isinstance(c, SettingsWidget):
                    c.destroy()

                self.main_container.add(SettingsWidget(cls.__instance__))

        else:
            c = self.main_container.get_child()
            self.main_container.remove(c)
            if isinstance(c, SettingsWidget):
                c.destroy()
            self.main_container.add(self.content_grid)

    def populate(self):
        classes = self.applet.Plugins.GetClasses()
        loaded = self.applet.Plugins.GetLoaded()
        for name, cls in classes.items():
            if cls.is_configurable():
                desc = "<span weight=\"bold\">%s</span>" % name
            else:
                desc = name
            self.list.append(active=(name in loaded), icon=cls.__icon__, activatable=(cls.__unloadable__), name=name,
                             desc=desc)

    def plugin_state_changed(self, plugins, name, loaded):
        row = self.list.get_conditional(name=name)
        self.list.set(row[0], active=loaded)

        cls = self.applet.Plugins.GetClasses()[name]
        if not loaded:
            self.update_config_widget(cls)
            self.b_prefs.props.sensitive = False
        elif cls.is_configurable():
            self.b_prefs.props.sensitive = True

    def on_toggled(self, cellrenderer, path):
        name = self.list.get(path, "name")["name"]

        deps = self.applet.Plugins.GetDependencies()[name]
        loaded = self.applet.Plugins.GetLoaded()
        to_unload = []
        for dep in deps:
            if dep in loaded:
                to_unload.append(dep)

        if to_unload:
            dialog = Gtk.MessageDialog(self, type=Gtk.MessageType.QUESTION, buttons=Gtk.ButtonsType.YES_NO)
            dialog.props.secondary_use_markup = True
            dialog.props.icon_name = "blueman"
            dialog.props.text = _("Dependency issue")
            dialog.props.secondary_text = _(
                "Plugin <b>\"%(0)s\"</b> depends on <b>%(1)s</b>. Unloading <b>%(1)s</b> will also unload <b>\"%(0)s\"</b>.\nProceed?") % {
                                          "0": ", ".join(to_unload), "1": name}

            resp = dialog.run()
            if resp != Gtk.ResponseType.YES:
                dialog.destroy()
                return

            dialog.destroy()

        conflicts = self.applet.Plugins.GetConflicts()[name]
        to_unload = []
        for conf in conflicts:
            if conf in loaded:
                to_unload.append(conf)

        if to_unload:
            dialog = Gtk.MessageDialog(self, type=Gtk.MessageType.QUESTION, buttons=Gtk.ButtonsType.YES_NO)
            dialog.props.secondary_use_markup = True
            dialog.props.icon_name = "blueman"
            dialog.props.text = _("Dependency issue")
            dialog.props.secondary_text = _(
                "Plugin <b>%(0)s</b> conflicts with <b>%(1)s</b>. Loading <b>%(1)s</b> will unload <b>%(0)s</b>.\nProceed?") % {
                                          "0": ", ".join(to_unload), "1": name}

            resp = dialog.run()
            if resp != Gtk.ResponseType.YES:
                dialog.destroy()
                return

            dialog.destroy()

            for p in to_unload:
                self.applet.Plugins.SetConfig(p, False)

        loaded = name in self.applet.Plugins.GetLoaded()
        cls = self.applet.Plugins.SetConfig(name, not loaded)
示例#19
0
    def __init__(self, applet: "BluemanApplet") -> None:
        super().__init__(title=_("Plugins"),
                         icon_name="blueman",
                         name="PluginDialog",
                         border_width=6,
                         default_width=490,
                         default_height=380,
                         resizable=False,
                         visible=False)

        self.applet = applet

        builder = Builder("applet-plugins-widget.ui")

        self.description = builder.get_widget("description", Gtk.Label)

        self.icon = builder.get_widget("icon", Gtk.Image)
        self.author_txt = builder.get_widget("author_txt", Gtk.Label)
        self.depends_hdr = builder.get_widget("depends_hdr", Gtk.Widget)
        self.depends_txt = builder.get_widget("depends_txt", Gtk.Label)
        self.conflicts_hdr = builder.get_widget("conflicts_hdr", Gtk.Widget)
        self.conflicts_txt = builder.get_widget("conflicts_txt", Gtk.Label)
        self.plugin_name = builder.get_widget("name", Gtk.Label)

        self.main_container = builder.get_widget("main_container", Gtk.Bin)
        self.content_grid = builder.get_widget("content", Gtk.Widget)

        self.b_prefs = builder.get_widget("b_prefs", Gtk.ToggleButton)
        self.b_prefs.connect("toggled", self.on_prefs_toggled)

        self.add(builder.get_widget("all", Gtk.Container))

        cr = Gtk.CellRendererToggle()
        cr.connect("toggled", self.on_toggled)

        data: List[ListDataDict] = [
            {
                "id": "active",
                "type": bool,
                "renderer": cr,
                "render_attrs": {
                    "active": 0,
                    "activatable": 1,
                    "visible": 1
                }
            },
            {
                "id": "activatable",
                "type": bool
            },
            {
                "id": "icon",
                "type": str,
                "renderer": Gtk.CellRendererPixbuf(),
                "render_attrs": {
                    "icon-name": 2
                }
            },
            # device caption
            {
                "id": "desc",
                "type": str,
                "renderer": Gtk.CellRendererText(),
                "render_attrs": {
                    "markup": 3
                },
                "view_props": {
                    "expand": True
                }
            },
            {
                "id": "name",
                "type": str
            },
        ]

        self.list = GenericList(data, headers_visible=False, visible=True)
        self.list.liststore.set_sort_column_id(3, Gtk.SortType.ASCENDING)
        self.list.liststore.set_sort_func(3, self.list_compare_func)

        self.list.selection.connect("changed", self.on_selection_changed)

        plugin_list = builder.get_widget("plugin_list", Gtk.ScrolledWindow)
        plugin_info = builder.get_widget("main_scrolled_window",
                                         Gtk.ScrolledWindow)
        plugin_list.add(self.list)

        # Disable overlay scrolling
        if Gtk.get_minor_version() >= 16:
            plugin_list.props.overlay_scrolling = False
            plugin_info.props.overlay_scrolling = False

        self.populate()

        self.sig_a: int = self.applet.Plugins.connect(
            "plugin-loaded", self.plugin_state_changed, True)
        self.sig_b: int = self.applet.Plugins.connect(
            "plugin-unloaded", self.plugin_state_changed, False)
        self.connect("delete-event", self._on_close)

        self.list.set_cursor(0)
示例#20
0
    def __init__(self):
        super(BluemanServices, self).__init__(title=_("Local Services"))
        self.resize(520, 420)
        self.set_name("BluemanServices")
        self.set_position(Gtk.WindowPosition.CENTER)
        self.props.border_width = 5
        self.props.icon_name = "blueman"

        self.b_apply = self.add_button("_Apply", Gtk.ResponseType.APPLY)
        self.b_apply.props.receives_default = True
        self.b_apply.props.sensitive = True
        self.b_apply.props.use_underline = True

        self.b_close = self.add_button("_Close", Gtk.ResponseType.CLOSE)
        self.b_close.props.use_underline = True

        self.content_area = self.get_content_area()

        self.box = Gtk.Box(Gtk.Orientation.HORIZONTAL)
        self.box.props.vexpand = True
        self.box.props.visible = True

        self.viewport = Gtk.Viewport()
        self.viewport.props.visible = True
        self.viewport.props.width_request = 120

        self.box.add(self.viewport)
        self.content_area.add(self.box)

        self.connect("delete-event", Gtk.main_quit)

        self.Config = Config("org.blueman.general")

        check_single_instance("blueman-services",
                              lambda time: self.Dialog.present_with_time(time))

        data = [
            [
                "picture", GdkPixbuf.Pixbuf,
                Gtk.CellRendererPixbuf(), {
                    "pixbuf": 0
                }, None
            ],
            [
                "caption", str,
                Gtk.CellRendererText(), {
                    "markup": 1
                }, None, {
                    "expand": True
                }
            ],
            ["id", str],
        ]

        ls = GenericList(data)
        ls.props.headers_visible = False

        ls.selection.connect("changed", self.on_selection_changed)
        self.List = ls

        self.viewport.add(ls)
        ls.show()

        self.load_plugins()

        try:
            ls.selection.select_path(self.Config["services-last-item"])
        except:
            ls.selection.select_path(0)

        self.b_apply.connect("clicked", self.on_apply_clicked)
        self.b_close.connect("clicked", Gtk.main_quit)

        self.show()
示例#21
0
 def prepend(self, **columns: object) -> None:
     tree_iter = GenericList.prepend(self, **columns)
     self.do_cache(tree_iter, columns)
示例#22
0
 def prepend(self, **columns):
     tree_iter = GenericList.prepend(self, **columns)
     self.do_cache(tree_iter, columns)
示例#23
0
	def set(self, iter, **kwargs):
		self.do_cache(iter, kwargs)
		GenericList.set(self, iter, **kwargs)
示例#24
0
 def set(self, tree_iter, **kwargs):
     GenericList.set(self, tree_iter, **kwargs)
     self.do_cache(tree_iter, kwargs)
示例#25
0
    def __init__(self, applet):
        gtk.Dialog.__init__(self,
                            buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE))

        self.applet = applet

        self.Builder = gtk.Builder()
        self.Builder.set_translation_domain("blueman")
        self.Builder.add_from_file(UI_PATH + "/applet-plugins-widget.ui")

        self.set_title(_("Plugins"))
        self.props.icon_name = "blueman"

        self.description = self.Builder.get_object("description")
        self.description.props.wrap = True

        self.icon = self.Builder.get_object("icon")
        self.author = self.Builder.get_object("author")
        self.depends_hdr = self.Builder.get_object("depends_hdr")
        self.depends_txt = self.Builder.get_object("depends_txt")
        self.conflicts_hdr = self.Builder.get_object("conflicts_hdr")
        self.conflicts_txt = self.Builder.get_object("conflicts_txt")
        self.plugin_name = self.Builder.get_object("name")

        self.main_container = self.Builder.get_object("main_container")
        self.content_vbox = self.Builder.get_object("content_vbox")

        self.b_prefs = self.Builder.get_object("b_prefs")
        self.b_prefs.connect("toggled", self.on_prefs_toggled)

        widget = self.Builder.get_object("all")

        ref = weakref.ref(self)

        self.vbox.pack_start(widget)

        cr = gtk.CellRendererToggle()
        cr.connect("toggled", lambda *args: ref() and ref().on_toggled(*args))

        data = [
            [
                "active", bool, cr, {
                    "active": 0,
                    "activatable": 1,
                    "visible": 1
                }, None
            ],
            ["activatable", bool],
            ["icon", str,
             gtk.CellRendererPixbuf(), {
                 "icon-name": 2
             }, None],

            #device caption
            [
                "desc", str,
                gtk.CellRendererText(), {
                    "markup": 3
                }, None, {
                    "expand": True
                }
            ],
            ["name", str]
        ]

        self.list = GenericList(data)
        #self.sorted = gtk.TreeModelSort(self.list.liststore)
        self.list.liststore.set_sort_column_id(3, gtk.SORT_ASCENDING)
        self.list.liststore.set_sort_func(3, self.list_compare_func)

        self.list.selection.connect(
            "changed",
            lambda *args: ref() and ref().on_selection_changed(*args))

        self.list.props.headers_visible = False
        self.list.show()

        self.props.border_width = 6
        self.resize(490, 380)

        self.Builder.get_object("viewport").add(self.list)

        self.populate()

        self.sig_a = self.applet.Plugins.connect("plugin-loaded",
                                                 self.plugin_state_changed,
                                                 True)
        self.sig_b = self.applet.Plugins.connect("plugin-unloaded",
                                                 self.plugin_state_changed,
                                                 False)
        self.connect("response", self.on_response)

        self.list.set_cursor(0)
示例#26
0
 def set(self, tree_iter, **kwargs):
     GenericList.set(self, tree_iter, **kwargs)
     self.do_cache(tree_iter, kwargs)
示例#27
0
 def prepend(self, **columns: object) -> Gtk.TreeIter:
     tree_iter = GenericList.prepend(self, **columns)
     self.do_cache(tree_iter, columns)
     return tree_iter
示例#28
0
    def __init__(self, applet):
        super().__init__(
            title=_("Plugins"),
            icon_name="blueman",
            name="PluginDialog",
            border_width=6,
            default_width=490,
            default_height=380,
            resizable=False,
            visible=False
        )

        self.applet = applet

        self.Builder = Gtk.Builder(translation_domain="blueman")
        bind_textdomain_codeset("blueman", "UTF-8")
        self.Builder.add_from_file(UI_PATH + "/applet-plugins-widget.ui")

        self.description = self.Builder.get_object("description")

        self.icon = self.Builder.get_object("icon")
        self.author_txt = self.Builder.get_object("author_txt")
        self.depends_hdr = self.Builder.get_object("depends_hdr")
        self.depends_txt = self.Builder.get_object("depends_txt")
        self.conflicts_hdr = self.Builder.get_object("conflicts_hdr")
        self.conflicts_txt = self.Builder.get_object("conflicts_txt")
        self.plugin_name = self.Builder.get_object("name")

        self.main_container = self.Builder.get_object("main_container")
        self.content_grid = self.Builder.get_object("content")

        self.b_prefs = self.Builder.get_object("b_prefs")
        self.b_prefs.connect("toggled", self.on_prefs_toggled)

        ref = weakref.ref(self)

        self.add(self.Builder.get_object("all"))

        cr = Gtk.CellRendererToggle()
        cr.connect("toggled", lambda *args: ref() and ref().on_toggled(*args))

        data = [
            {"id": "active", "type": bool, "renderer": cr, "render_attrs": {"active": 0, "activatable": 1,
                                                                            "visible": 1}},
            {"id": "activatable", "type": bool},
            {"id": "icon", "type": str, "renderer": Gtk.CellRendererPixbuf(), "render_attrs": {"icon-name": 2}},
            # device caption
            {"id": "desc", "type": str, "renderer": Gtk.CellRendererText(), "render_attrs": {"markup": 3},
             "view_props": {"expand": True}},
            {"id": "name", "type": str},
        ]

        self.list = GenericList(data, headers_visible=False, visible=True)
        self.list.liststore.set_sort_column_id(3, Gtk.SortType.ASCENDING)
        self.list.liststore.set_sort_func(3, self.list_compare_func)

        self.list.selection.connect("changed", lambda *args: ref() and ref().on_selection_changed(*args))

        plugin_list = self.Builder.get_object("plugin_list")
        plugin_info = self.Builder.get_object("main_scrolled_window")
        plugin_list.add(self.list)

        # Disable overlay scrolling
        if Gtk.get_minor_version() >= 16:
            plugin_list.props.overlay_scrolling = False
            plugin_info.props.overlay_scrolling = False

        self.populate()

        self.sig_a = self.applet.Plugins.connect("plugin-loaded", self.plugin_state_changed, True)
        self.sig_b = self.applet.Plugins.connect("plugin-unloaded", self.plugin_state_changed, False)
        self.connect("delete-event", self._on_close)

        self.list.set_cursor(0)
示例#29
0
 def set(self, iter, **kwargs):
     self.do_cache(iter, kwargs)
     GenericList.set(self, iter, **kwargs)
示例#30
0
    def __init__(self, applet):
        super(PluginDialog, self).__init__(buttons=("_Close", Gtk.ResponseType.CLOSE))

        self.set_name("PluginDialog")
        self.applet = applet

        self.Builder = Gtk.Builder()
        self.Builder.set_translation_domain("blueman")
        bind_textdomain_codeset("blueman", "UTF-8")
        self.Builder.add_from_file(UI_PATH + "/applet-plugins-widget.ui")

        self.set_title(_("Plugins"))
        self.props.icon_name = "blueman"

        self.description = self.Builder.get_object("description")
        self.description.props.wrap = True

        self.icon = self.Builder.get_object("icon")
        self.author_txt = self.Builder.get_object("author_txt")
        self.depends_hdr = self.Builder.get_object("depends_hdr")
        self.depends_txt = self.Builder.get_object("depends_txt")
        self.conflicts_hdr = self.Builder.get_object("conflicts_hdr")
        self.conflicts_txt = self.Builder.get_object("conflicts_txt")
        self.plugin_name = self.Builder.get_object("name")

        self.main_container = self.Builder.get_object("main_container")
        self.content_grid = self.Builder.get_object("content")

        self.b_prefs = self.Builder.get_object("b_prefs")
        self.b_prefs.connect("toggled", self.on_prefs_toggled)

        widget = self.Builder.get_object("all")

        ref = weakref.ref(self)

        self.vbox.pack_start(widget, True, True, 0)

        cr = Gtk.CellRendererToggle()
        cr.connect("toggled", lambda *args: ref() and ref().on_toggled(*args))

        data = [
            ["active", bool, cr, {"active": 0, "activatable": 1, "visible": 1}, None],
            ["activatable", bool],
            ["icon", str, Gtk.CellRendererPixbuf(), {"icon-name": 2}, None],
            # device caption
            ["desc", str, Gtk.CellRendererText(), {"markup": 3}, None, {"expand": True}],
            ["name", str]
        ]

        self.list = GenericList(data)
        # self.sorted = Gtk.TreeModelSort(self.list.liststore)
        self.list.liststore.set_sort_column_id(3, Gtk.SortType.ASCENDING)
        self.list.liststore.set_sort_func(3, self.list_compare_func)

        self.list.selection.connect("changed", lambda *args: ref() and ref().on_selection_changed(*args))

        self.list.props.headers_visible = False
        self.list.show()

        self.props.border_width = 6
        self.resize(490, 380)

        viewport = self.Builder.get_object("viewport")
        viewport.add(self.list)

        sw = self.Builder.get_object("main_scrolled_window")

        # Disable overlay scrolling
        if Gtk.get_minor_version() >= 16:
            viewport.props.overlay_scrolling = False
            sw.props.overlay_scrolling = False

        self.populate()

        self.sig_a = self.applet.Plugins.connect("plugin-loaded", self.plugin_state_changed, True)
        self.sig_b = self.applet.Plugins.connect("plugin-unloaded", self.plugin_state_changed, False)
        self.connect("response", self.on_response)

        self.list.set_cursor(0)
示例#31
0
	def append(self, **columns):
		iter = GenericList.append(self, **columns)
		self.do_cache(iter, columns)