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


Python Controller.tick方法代码示例

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


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

示例1: Simulation

# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import tick [as 别名]
class Simulation(Frame):
    def __init__(self, root, config):
        Frame.__init__(self, root)
        self.grid(column=3,row=2, sticky=N+E+S+W)
        self.stopped = True
        self.started = False
        
        self.initWidgets(root.winfo_screenwidth(),root.winfo_screenheight())
        self.initEvents()
        self.initController(config,root.winfo_screenwidth(),root.winfo_screenheight())

    def initWidgets(self,sw,sh):
        self.startBtn = Button(self,text="Start")
        self.startBtn.grid(column=1, row=1)

        self.stopBtn = Button(self,text="Stop")
        self.stopBtn.grid(column=2, row=1)
        self.stopBtn['state'] = "disabled"

        self.stepBtn = Button(self,text="Step")
        self.stepBtn.grid(column=3, row=1)

        self.canvas = Canvas(self, height=sh, width=sw)
        self.canvas.grid(row=2, column=1, columnspan=3)
        
        #r = Route(Point(100, 300, self.canvas), Point(300,500,self.canvas), [Point(300,300, self.canvas)])
        #self.vehicle = Vehicle(1,r,self.canvas)
        #self.vehicle.create()

    def startPressed(self, event):
        print("start click", threading.currentThread)
        if not self.started:
            self.toggleBtn(self.stopBtn)
            self.toggleState()
            self.started = True
            self.start()
        else:
            self.toggleState()
            if not self.stopped:
                self.start()
        
    def stopPressed(self, event):
        self.resetState()
        self.resetBtns()
        #self.ctrl.reset()

    def stepPressed(self, event):
        self.start()
        pass

    def resetBtns(self):
        self.startBtn['text']= "Start"
        self.stopBtn['state'] = "disabled"

    def resetState(self):
        self.started = False
        self.stopped = True

    def toggleBtn(self, btn):
        if btn['state'] == "disabled":
            btn['state'] = "normal"
        else:
            btn['state'] = "disabled"

    def toggleState(self):
        if not self.stopped:
            self.startBtn["text"] = "Resume"
            self.stopped = True
        else:
            self.startBtn["text"] = "Pause"
            self.stopped = False
            
    def initEvents(self):
        self.startBtn.bind("<Button-1>", self.startPressed)
        self.stopBtn.bind("<Button-1>", self.stopPressed)
        self.stepBtn.bind("<Button-1>", self.stepPressed)

    def initController(self, config, sw, sh):
        mengqiWidth,mengqiHeight = 1600,900
        self.ctrl = Controller(config, self.canvas, sw/mengqiWidth, sh/mengqiHeight)

    def start(self):
        #while loop
        while True:
            #time.sleep a tick time might be couple milliseconds
            self.ctrl.tick()
            #self.vehicle.move()
            self.canvas.update()
            time.sleep(1)
            if self.stopped:
                break
开发者ID:jiayuzhang,项目名称:ITS,代码行数:93,代码来源:Simulation.py


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