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


Python Control.setSwitch方法代码示例

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


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

示例1: Simulator

# 需要导入模块: import Control [as 别名]
# 或者: from Control import setSwitch [as 别名]
class Simulator(tk.Tk):
    def __init__(self, dt):
        self.WIDTH = 1000.0
        self.HEIGHT = 500.0
        self.time = 0.0
        self.dt = dt
                
        tk.Tk.__init__( self )
        
        self.drone = Drone(self.dt)
        #self.drone2 = Drone(self.dt)
        self.control = Control(self.drone)
        #self.control2 = Control(self.drone2)
        self.drone.setControl(self.control)
        #self.drone2.setControl(self.control2)     

        screen = tk.Frame(self)
        screen.pack()
        
        self.canvas = tk.Canvas(screen, width=self.WIDTH, height=self.HEIGHT,borderwidth=10)
        self.canvas.grid(column=1, row=1)
        
        self.infos = InfoPanel(screen, self.drone)
        self.infos.panel.grid(column=2, row=1)
        #self.infos2 = InfoPanel(screen, self.drone2)
        #self.infos2.panel.grid(column=3, row=1)
       
        # to receive commands
        screen.focus_set()  
        
        self.drone_ui = self.canvas.create_oval(40, self.HEIGHT, 50, self.HEIGHT-10, fill = "red")
        #self.drone2_ui = self.canvas.create_oval(100, self.HEIGHT, 110, self.HEIGHT-10, fill = "blue")       

        def onBtnUpHand(e):
            self.control.onBtnUp()

        def onBtnDownHand(e):
            self.control.onBtnDown()
            
        def onBtnLeftHand(e):
            self.control.onBtnLeft()
            
        def onBtnRightHand(e):
            self.control.onBtnRight()

        def onBtnAHand(e):          
            if self.control.switch == 0:
                self.control.setSwitch(1)
                self.control.load(self.control.stay, self.drone.pos)
                
        def onBtnRHand(e):
            self.control.reset()
            
        def onBtnGHand(e):                        
            if self.control.switch == 0:
                self.control.setSwitch(1)
                self.control.load(self.control.goto, [Vector(0,50), Vector(30,100)])
                
        def onBtnOHand(e):
            self.control.resetControl()

        screen.bind("<Up>", onBtnUpHand)
        screen.bind("<Down>", onBtnDownHand)
        screen.bind("<Left>", onBtnLeftHand)
        screen.bind("<Right>", onBtnRightHand)
        screen.bind("<a>", onBtnAHand)
        screen.bind("<r>", onBtnRHand)
        screen.bind("<g>", onBtnGHand)
        screen.bind("<o>", onBtnOHand)

    def simLoop(self):        
        self.drone.refreshPos()
        #self.drone2.refreshHeight()
        if self.control.switch == 1:
            self.control.run()
            
        #self.control2.load(self.control2.goto, [self.drone.height])
        #self.control2.run()
            
        self.canvas.coords(self.drone_ui, self.drone.pos.coords[0]+40, self.HEIGHT-self.drone.pos.coords[1], self.drone.pos.coords[0]+50, self.HEIGHT-10-self.drone.pos.coords[1])
        #self.canvas.coords(self.drone2_ui, 100, self.HEIGHT-self.drone2.height, 110, self.HEIGHT-10-self.drone2.height)

        self.infos.texts.setUiTexts()
        #self.infos2.texts.setUiTexts()
        
        self.after(int(1000*self.dt), self.simLoop)
开发者ID:ricsirke,项目名称:Drone-Simulation,代码行数:88,代码来源:Simulator.py


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