当前位置: 首页>>代码示例>>Python>>正文


Python JoystickReader.set_mux方法代码示例

本文整理汇总了Python中cfclient.utils.input.JoystickReader.set_mux方法的典型用法代码示例。如果您正苦于以下问题:Python JoystickReader.set_mux方法的具体用法?Python JoystickReader.set_mux怎么用?Python JoystickReader.set_mux使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cfclient.utils.input.JoystickReader的用法示例。


在下文中一共展示了JoystickReader.set_mux方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MainUI

# 需要导入模块: from cfclient.utils.input import JoystickReader [as 别名]
# 或者: from cfclient.utils.input.JoystickReader import set_mux [as 别名]

#.........这里部分代码省略.........

    def _update_input(self, device="", config=""):
        self._active_config = str(config)
        self._active_device = str(device)

        Config().set("input_device", str(self._active_device))

        # update the checked state of the menu items
        for c in self._menu_mappings.actions():
            c.setEnabled(True)
            if c.text() == self._active_config:
                c.setChecked(True)
        for c in self._menu_devices.actions():
            c.setEnabled(True)
            if c.text() == self._active_device:
                c.setChecked(True)
        # update label
        if device == "" and config == "":
            self._statusbar_label.setText("No input device selected")
        elif config == "":
            self._statusbar_label.setText("Using [{}] - "
                                          "No input config selected".format
                                          (self._active_device))
        else:
            self._statusbar_label.setText("Using [{}] with config [{}]".format
                                          (self._active_device,
                                           self._active_config))

    def _mux_selected(self, checked):
        if not checked:
            return

        selected_mux_name = str(self.sender().text())
        self.joystickReader.set_mux(name=selected_mux_name)

        logger.debug("Selected mux supports {} devices".format(self.joystickReader.get_mux_supported_dev_count()))
        self._adjust_nbr_of_selected_devices()

    def _get_saved_device_mapping(self, device_name):
        """Return the saved mapping for a given device"""
        config = None
        device_config_mapping = Config().get("device_config_mapping")
        if device_name in device_config_mapping.keys():
            config = device_config_mapping[device_name]

        logging.debug("For [{}] we recommend [{}]".format(device_name, config))
        return config


    def _update_input_device_footer(self, device_name=None, mapping_name=None):
        """Update the footer in the bottom of the UI with status for the
        input device and its mapping"""
        if not device_name and not mapping_name:
            self._statusbar_label.setText("No input device selected")
        elif self._mapping_support and not mapping_name:
            self._statusbar_label.setText("Using [{}] - "
                                          "No input config selected".format(
                                            device_name))
        elif not self._mapping_support:
            self._statusbar_label.setText("Using [{}]".format(device_name))
        else:
            self._statusbar_label.setText("Using [{}] with config [{}]".format(
                                            device_name, mapping_name))

    def _adjust_nbr_of_selected_devices(self):
        nbr_of_selected = len(self._input_dev_stack)
开发者ID:Venris,项目名称:crazyflie-multilink,代码行数:70,代码来源:main.py

示例2: MainUI

# 需要导入模块: from cfclient.utils.input import JoystickReader [as 别名]
# 或者: from cfclient.utils.input.JoystickReader import set_mux [as 别名]

#.........这里部分代码省略.........
        Config().save_file()

    def _connect(self):
        if self.uiState == UIState.CONNECTED:
            self.cf.close_link()
        elif self.uiState == UIState.CONNECTING:
            self.cf.close_link()
            self.uiState = UIState.DISCONNECTED
            self._update_ui_state()
        else:
            self.cf.open_link(self._selected_interface)

    def _scan(self):
        self.uiState = UIState.SCANNING
        self._update_ui_state()
        self.scanner.scanSignal.emit(self.address.value())

    def _display_input_device_error(self, error):
        self.cf.close_link()
        QMessageBox.critical(self, "Input device error", error)

    def _mux_selected(self, checked):
        """Called when a new mux is selected. The menu item contains a
        reference to the raw mux object as well as to the associated device
        sub-nodes"""
        if not checked:
            (mux, sub_nodes) = self.sender().data()
            for s in sub_nodes:
                s.setEnabled(False)
        else:
            (mux, sub_nodes) = self.sender().data()
            for s in sub_nodes:
                s.setEnabled(True)
            self.joystickReader.set_mux(mux=mux)

            # Go though the tree and select devices/mapping that was
            # selected before it was disabled.
            for role_node in sub_nodes:
                for dev_node in role_node.children():
                    if type(dev_node) is QAction and dev_node.isChecked():
                        dev_node.toggled.emit(True)

            self._update_input_device_footer()

    def _get_dev_status(self, device):
        msg = "{}".format(device.name)
        if device.supports_mapping:
            map_name = "N/A"
            if device.input_map:
                map_name = device.input_map_name
            msg += " ({})".format(map_name)
        return msg

    def _update_input_device_footer(self):
        """Update the footer in the bottom of the UI with status for the
        input device and its mapping"""

        msg = ""

        if len(self.joystickReader.available_devices()) > 0:
            mux = self.joystickReader._selected_mux
            msg = "Using {} mux with ".format(mux.name)
            for key in list(mux._devs.keys())[:-1]:
                if mux._devs[key]:
                    msg += "{}, ".format(self._get_dev_status(mux._devs[key]))
                else:
开发者ID:bsmr-Bitcraze,项目名称:crazyflie-clients-python,代码行数:70,代码来源:main.py


注:本文中的cfclient.utils.input.JoystickReader.set_mux方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。