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


Python JoystickReader.startInput方法代码示例

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


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

示例1: MainUI

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

#.........这里部分代码省略.........
        QMessageBox.critical(self,warningCaption, msg)
        self.setUIState(UIState.DISCONNECTED, linkURI)

    def closeEvent(self, event):
        self.hide()
        self.cf.close_link()
        Config().save_file()

    def connectButtonClicked(self):
        if (self.uiState == UIState.CONNECTED):
            self.cf.close_link()
        elif (self.uiState == UIState.CONNECTING):
            self.cf.close_link()
            self.setUIState(UIState.DISCONNECTED)
        else:
            self.connectDialogue.show()

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

    def _inputdevice_selected(self, checked):
        if (not checked):
            return
        self.joystickReader.stopInput()
        sender = self.sender()
        self._current_input_device = sender.text()
        device_config_mapping = Config().get("device_config_mapping")
        if (self._current_input_device in device_config_mapping.keys()):
            self._current_input_config = device_config_mapping[
                str(self._current_input_device)]
        else:
            self._current_input_config = self._menu_mappings.actions()[0].text()
        Config().set("input_device", str(self._current_input_device))
        
        for c in self._menu_mappings.actions():
            if (c.text() == self._current_input_config):
                c.setChecked(True)

        self.joystickReader.startInput(str(sender.text()),
                                       self._current_input_config)
        self._statusbar_label.setText("Using [%s] with config [%s]" % (
                                      self._current_input_device,
                                      self._current_input_config))

    def _inputconfig_selected(self, checked):
        if (not checked):
            return
        sender = self.sender()
        self._current_input_config = sender.text()
        Config().get("device_config_mapping")[str(self._current_input_device)] = str(self._current_input_config)
        self.joystickReader.startInput(str(self._current_input_device),
                                       self._current_input_config)
        self._statusbar_label.setText("Using [%s] with config [%s]" % (
                                      self._current_input_device,
                                      self._current_input_config))

    def device_discovery(self, devs):
        group = QActionGroup(self._menu_devices, exclusive=True)
        
        for d in devs:
            node = QAction(d["name"], self._menu_devices, checkable=True)
            node.toggled.connect(self._inputdevice_selected)
            group.addAction(node)
            self._menu_devices.addAction(node)
            if (d["name"] == Config().get("input_device")):
                self._current_input_device = d["name"]
        if (len(self._current_input_device) == 0):
            self._current_input_device = self._menu_devices.actions()[0].text()

        device_config_mapping = Config().get("device_config_mapping")
        if (device_config_mapping):
            if (self._current_input_device in device_config_mapping.keys()):
                self._current_input_config = device_config_mapping[
                    str(self._current_input_device)]
            else:
                self._current_input_config = self._menu_mappings.actions()[0].text()
        else:
            self._current_input_config = self._menu_mappings.actions()[0].text()

        # Now we know what device to use and what mapping, trigger the events to
        # change the menus and start the input
        for c in self._menu_mappings.actions():
            c.setEnabled(True)
            if (c.text() == self._current_input_config):
                c.setChecked(True)
        
        for c in self._menu_devices.actions():
            if (c.text() == self._current_input_device):
                c.setChecked(True)

    def quickConnect(self):
        try:
            self.cf.open_link(Config().get("link_uri"))
        except KeyError:
            self.cf.open_link("")    

    def closeAppRequest(self):
        self.close()
        app.exit(0);
开发者ID:djvolz,项目名称:Self-Navigating-Crazyflie-Quadcopter,代码行数:104,代码来源:main.py


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