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


Python Controller.disconnect方法代码示例

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


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

示例1: RoverWindow

# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import disconnect [as 别名]
class RoverWindow():

    def __init__(self):
        '''
        Initialize class attributes.
        '''
        self.control = Controller()
        self.control_thread = ControllerThread()
        self.root = Tk()
        self.root.title("Robot Control Interface")
        self.mainframe = None
        self.combo_joystick = None
        self.combo_bluetooth = None
        self.__configure_frame()
        self.root.mainloop()

    def __configure_frame(self):
        '''
        '''
        self.mainframe = Frame(self.root, padding="3 3 12 12")
        self.mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
        self.mainframe.columnconfigure(0, weight=1)
        self.mainframe.rowconfigure(0, weight=1)
        self.message = StringVar()
        Label(self.mainframe, textvariable=self.message).grid(column=2, row=2, sticky=W)
        self.disconnect_button = Button(self.mainframe, text="Disconnect", command=self.disconnect, state=DISABLED)
        self.speed = StringVar()
        Label(self.mainframe, textvariable=self.speed).grid(column=2, row=4, sticky=W)
        self.disconnect_button.grid(column=3, row=3, sticky=E)
        self.root.bind('<Return>', self.disconnect)
        self.joystick_section()
        self.bluetooth_section()
        for child in self.mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)
        self.combo_joystick.current(0)
        self.combo_bluetooth.current(0)

    def joystick_section(self):
        '''
        '''
        Label(self.mainframe, text="Joystick").grid(column=1, row=1, sticky=W)
        value = StringVar()
        self.combo_joystick = Combobox(self.mainframe, textvariable=value)
        self.combo_joystick.grid(column=2, row=1, sticky=(W, E))
        self.combo_joystick["values"] = self.control.get_joystick_list()
        self.combo_joystick.bind("<<ComboboxSelected>>")

    def bluetooth_section(self):
        '''
        '''
        Label(self.mainframe, text="Bluetooth").grid(column=1, row=3, sticky=W)
        value = StringVar()
        self.combo_bluetooth = Combobox(self.mainframe, textvariable=value)
        self.combo_bluetooth.grid(column=2, row=3, sticky=W)
        self.combo_bluetooth["values"] = self.control.get_bluetooth_list()
        self.combo_bluetooth.bind("<<ComboboxSelected>>")
        self.button_bluetooth = Button(self.mainframe, text="Connect", command=self.connect)
        self.button_bluetooth.grid(column=3, row=1, sticky=E)
        self.root.bind('<Return>', self.connect)

    def speed_update(self):
        '''
        '''
        self.speed.set("300 Km/h")

    def connect(self):
        '''
        '''
        print "Joystick: %s" % self.combo_joystick.get()
        print "Bluetooth: %s" % self.combo_bluetooth.get()
        self.control.connect(self.combo_joystick.get(), self.combo_bluetooth.get())
        self.message.set("Set speed and move the Rover")
        self.button_bluetooth["state"] = "disabled"
        self.disconnect_button["state"] = "enabled"
        self.speed_update()
        self.control_thread.start()

    def disconnect(self):
        '''
        '''
        self.control_thread.stop_communication()
        time.sleep(1)
        counter = 0
        while self.control_thread.isAlive() and counter < 16:
            print "Waiting to release the thread."
            counter = counter + 1
            time.sleep(1)
        self.control.disconnect()
        self.message.set("")
        self.combo_joystick.current(0)
        self.combo_bluetooth.current(0)
        self.disconnect_button["state"] = "disabled"
开发者ID:mparra-mpz,项目名称:CURIOSITY,代码行数:93,代码来源:RoverWindow.py

示例2: Rover

# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import disconnect [as 别名]
class Rover(QDeclarativeView):
   
    def __init__(self, parent=None):
        '''
        Initialize the attributes class.
        '''
        super(Rover, self).__init__(parent)
        self.setWindowTitle("Robotic Control Interface")
        self.set_default_values()
        self.setSource(QUrl.fromLocalFile("Rover.qml"))
        self.setResizeMode(QDeclarativeView.SizeRootObjectToView)
        self.ro = self.rootObject()
        
        self.control = Controller()
        self.control_thread = ControllerThread()
        self.control_start = False
        
    def set_default_values(self):
        '''
        Set the default values to start the GUI.
        '''
        self.joystick = ""
        self.bluetooth = ""
        self.power = 0.0
        self.angle = 0.0
        self.rc = self.rootContext()
        self.rc.setContextProperty("joystick", self.joystick)
        self.rc.setContextProperty("bluetooth", self.bluetooth)
        self.rc.setContextProperty("power", self.power)
        self.rc.setContextProperty("angle", self.angle)
        
    def set_connection(self):
        '''
        Display the devices selected for the communication.
        '''
        joystick_list = self.control.get_joystick_list()
        for element in joystick_list:
            if "DragonRise" in element:
                self.joystick = element
                break
        self.rc.setContextProperty("joystick", self.joystick)
        
        bluetooth_list = self.control.get_bluetooth_list()
        for element in bluetooth_list:
            if "CURIOSITY" in element:
                self.bluetooth = element
                break
        self.rc.setContextProperty("bluetooth", self.bluetooth)
        
    def set_event_signal(self):
        '''
        Define the GUI interactions with the system.
        '''
        self.ro.connection.connect(self.__connect_hw)
        self.ro.disconnection.connect(self.__disconnect_hw)
        
    def __connect_hw(self):
        '''
        Connect to the CONTROL software.
        '''
        if not self.control_start:
            self.control_start = True
            self.control.connect(self.joystick, self.bluetooth)
            self.control_thread.start()
        
    def __disconnect_hw(self):
        '''
        Disconnect from the CONTROL software.
        '''
        self.control_thread.stop_communication()
        time.sleep(1)            
        self.control.disconnect()
        time.sleep(1)
        sys.exit(0)

    def update(self, observer):
        '''
        Method to update values in the GUI.
        '''
        self.power = observer.power
        self.rc.setContextProperty("power", self.power)
        self.angle = observer.angle
        self.rc.setContextProperty("angle", self.angle)
开发者ID:mparra-mpz,项目名称:CURIOSITY,代码行数:85,代码来源:Rover.py


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