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


Python Robot.disconnect方法代码示例

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


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

示例1: Gui

# 需要导入模块: from Robot import Robot [as 别名]
# 或者: from Robot.Robot import disconnect [as 别名]

#.........这里部分代码省略.........
        self.config_widget("btn_backward", {"command": lambda: self.robot.teleport("Backward")})
        self.config_widget("btn_left", {"command": lambda: self.robot.teleport("Left")})
        self.config_widget("btn_right", {"command": lambda: self.robot.teleport("Right")})
        self.config_widget("btn_follow", {"command": lambda: self.robot.follow_black_line(self.speed.get(), self.darkness.get())})

        self.chat_message = tkinter.StringVar()
        self.config_widget("chat_with_robot_entry", {"textvariable": self.chat_message})
        self.frame.children["chat_with_robot_entry"].bind("<Key-Return>", lambda event: self.robot.chat_with_robot(self.chat_message))
        self.config_widget("btn_chat_with_robot_entry", {"command": lambda: self.robot.chat_with_robot(self.chat_message)})
        
        self.config_widget("btn_follow_other_robot", {"command": lambda: self.robot.follow_other_robot(self.speed.get(), self.bytecode.get())})
        self.config_widget("btn_take_other_robot", {"command": lambda: self.robot.take_other_robot(self.speed.get(), self.bytecode.get())})

        self.config_widget("btn_map_GUI", {"command": lambda: self.map_gui_to_robot()})

        self.config_widget("btn_sing_and_dance", {"command": lambda: self.robot.sing_and_dance()})

        self.log_frame = ttk.Frame(self.root)
        self.log_frame.grid()
        self.log_text = tkinter.Text(self.log_frame, width=150, height=20, wrap=tkinter.CHAR)  # state=tkinter.DISABLED)
        # self.log_text.insert(tkinter.INSERT, "DEBUG")
        self.log_text.grid()

        robotLogger.logger_list["GuiLogger"].gui = self

        info_time = Timer(2, lambda: self.robot.team_info())
        info_time.start()
        self.root.mainloop()

    def map_gui_to_robot(self):
        """
        This function calls the main function from the file 'map_GUI' to obtain the list of points
        that the user clicked and then calls the 'grid_movement' function to exectute the task.
        Feature 7-b
        Contributor: Matthew O'Brien
        """
        points = map_GUI.main()
        self.robot.grid_movement(points, self.speed.get(), self.rotation.get())

    def config_widget(self, widget_name, widget_options):
        """
        Config the widget.
        @Parameter widget_name: The widget's name.
        @Parameter widget_options: A DICTIONARY that contains options.

        E.g. self.config_widget("time_entry", {textvariable: self.time})
             is equivalent to
             time_entry["textvariable"] = self.time
        Contributor: Xiangqing Zhang
        """
        assert self.frame, "Please initialize the GUI!"
        self.frame.children[widget_name].config(**widget_options)

    def add_widget(self, widget_xml, top_frame=None):
        """
        Adds widget(s) to the frame.
        @Parameter widget_list: The widget(s) that will be added to the top_frame.
                                This widget_xml should be in XML format.
        @Parameter top_frame: Optional. The default value is self.frame

        Reference: http://docs.python.org/3.3/library/xml.etree.elementtree.html
        Contributor: Xiangqing Zhang
        """
        if not top_frame: top_frame = self.frame
        if widget_xml.tag == "root":
            self.frame = ttk.Frame(self.root, padding=(20, 30), **widget_xml.attrib)
            for each_widget in widget_xml:
                ttk_widget, row_column = self.add_widget(each_widget, self.frame)
                if not row_column:
                    ttk_widget.grid()
                else:
                    row_column = row_column.split(",")
                    rows = int(row_column[0])
                    columns = int(row_column[1])
                    ttk_widget.grid(row=rows, column=columns)
            return self.frame
        else:
            opt_list = widget_xml.attrib
            if widget_xml:
                opt_list = opt_list.copy()
                for each_widget in widget_xml:
                    opt_list[each_widget.tag] = each_widget.text
            row_column = None
            if "row_column" in opt_list:
                row_column = opt_list["row_column"]
                del opt_list["row_column"]
            try:
                gui_result = [getattr(ttk, widget_xml.tag.capitalize())(top_frame, **opt_list), row_column]
            except:
                gui_result = [getattr(tkinter, widget_xml.tag.capitalize())(top_frame, **opt_list), row_column]
            return gui_result

    def exit(self):
        """
        Disconnect the robot when interrupted or terminated.

        Contributor: Xiangqing Zhang
        """
        self.robot.stop()
        self.robot.disconnect()
开发者ID:lty1993,项目名称:csse120,代码行数:104,代码来源:gui.py


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