示例#1
0
    def on_request_menu_items(self, manager_menu: ManagerDeviceMenu, device: Device) -> List[DeviceMenuItem]:
        audio_source = False
        for uuid in device['UUIDs']:
            if ServiceUUID(uuid).short_uuid in (AUDIO_SOURCE_SVCLASS_ID, AUDIO_SINK_SVCLASS_ID):
                audio_source = True
                break

        if device['Connected'] and audio_source:

            pa = PulseAudioUtils()
            if not pa.connected:
                self.deferred.append(device)
                return []

            item = create_menuitem(_("Audio Profile"), "audio-card")
            item.props.tooltip_text = _("Select audio profile for PulseAudio")

            if not device['Address'] in self.devices:
                self.query_pa(device, item)
            else:
                self.generate_menu(device, item)

        else:
            return []

        return [DeviceMenuItem(item, DeviceMenuItem.Group.ACTIONS, 300)]
示例#2
0
 def on_request_menu_items(self, manager_menu: ManagerDeviceMenu, device: Device) -> List[DeviceMenuItem]:
     item = create_menuitem(_("_Info"), "dialog-information")
     item.props.tooltip_text = _("Show device information")
     _window = manager_menu.get_toplevel()
     assert isinstance(_window, Gtk.Window)
     window = _window  # https://github.com/python/mypy/issues/2608
     item.connect('activate', lambda x: show_info(device, window))
     return [DeviceMenuItem(item, DeviceMenuItem.Group.ACTIONS, 400)]
示例#3
0
    def on_request_menu_items(self, manager_menu: ManagerDeviceMenu,
                              device: Device) -> List[DeviceMenuItem]:
        items: List[DeviceMenuItem] = []
        appl = AppletService()

        services = get_services(device)

        connectable_services = [
            service for service in services if service.connectable
        ]
        for service in connectable_services:
            item: Gtk.MenuItem = create_menuitem(service.name, service.icon)
            if service.description:
                item.props.tooltip_text = service.description
            item.connect(
                "activate", lambda _item: manager_menu.connect_service(
                    service.device, service.uuid))
            items.append(
                DeviceMenuItem(item, DeviceMenuItem.Group.CONNECT,
                               service.priority))
            item.props.sensitive = service.available
            item.show()

        connected_services = [
            service for service in services if service.connected_instances
        ]
        for service in connected_services:
            for instance in service.connected_instances:
                surface = self._make_x_icon(service.icon, 16)
                item = create_menuitem(instance.name, surface=surface)
                item.connect(
                    "activate", lambda _item: manager_menu.disconnect_service(
                        service.device, service.uuid, instance.port))
                items.append(
                    DeviceMenuItem(item, DeviceMenuItem.Group.DISCONNECT,
                                   service.priority + 100))
                item.show()

        if services:
            config = AutoConnectConfig()
            autoconnect_services = set(config["services"])
            for service in services:
                if service.connected_instances or (
                        device.get_object_path(),
                        service.uuid) in autoconnect_services:
                    item = Gtk.CheckMenuItem(label=service.name)
                    config.bind_to_menuitem(item, device, service.uuid)
                    item.show()
                    items.append(
                        DeviceMenuItem(item, DeviceMenuItem.Group.AUTOCONNECT,
                                       service.priority))

        for action, priority in set((action, service.priority)
                                    for service in services
                                    for action in service.common_actions
                                    if any(plugin in appl.QueryPlugins()
                                           for plugin in action.plugins)):
            item = create_menuitem(action.title, action.icon)
            items.append(
                DeviceMenuItem(item, DeviceMenuItem.Group.ACTIONS,
                               priority + 200))
            item.show()
            item.connect("activate",
                         self._get_activation_handler(action.callback))

        return items