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


Python Scene.initialize方法代码示例

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


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

示例1: App

# 需要导入模块: from Scene import Scene [as 别名]
# 或者: from Scene.Scene import initialize [as 别名]
class App(object):

    def __init__(self):
        self.render_asap = False;
        self.app_should_exit = False
        self.root = Tk()
        self.scene = None
        self.lastUpdateMoment = 0
        self.renderingTechniq = RENDER_ON_MAINLOOP
        
    def setAppExit(self):
        self.app_should_exit = TRUE

    def initialize(self):
        speller = GazeSpeller()
        tracker = self._ckeckAvailableTracker()
        canvas = self._initializeCanvas()
        
        if isinstance(tracker,MouseTracker):
            canvas.bind('<Motion>',tracker.onMotion) # use this to let the tracker get updates from the mouse event without actual get knowledge of the GUIs
            # it's named "inversion of control"

        self.scene = Scene(canvas, tracker, speller)
        self.scene.initialize(1)
    
    def startRendering(self):
        if self.renderingTechniq == RENDER_ON_MAINLOOP:
            self.runOnTkInterMainLoop()
        if self.renderingTechniq == RENDER_ON_TIMER_TICK:
            self.runOnExpectedFixedFramerate()
        
        sys.exit(0)
    
    def _ckeckAvailableTracker(self):
        #TODO check if tracker available if not use mouse
        return MouseTracker(self.root)

    def _initializeCanvas(self):
        self.root.attributes("-fullscreen", True)
        self.root.protocol("WM_DELETE_WINDOW", self.setAppExit)
        canvas = Canvas(self.root)
        canvas.pack(fill=BOTH, expand=YES)
        return canvas
    
    def _processRenderLoop(self, deltaTime, CallTkUpdates = False):
        self.scene.update(deltaTime)
        self.scene.render()
        if CallTkUpdates:
            self.root.update_idletasks() # render / drawing
            self.root.update() # perform processing of key events etc
    
    def _estimateFrameTime(self):
        currentMoment = time()
        deltaTime = currentMoment - self.lastUpdateMoment
        self.lastUpdateMoment = currentMoment
        return deltaTime

    # example rendering A
    def runOnExpectedFixedFramerate(self):
        self.lastUpdateMoment = time()
        while not self.app_should_exit:
            deltaTime = self._estimateFrameTime()
            self._processRenderLoop(deltaTime, CallTkUpdates = True)
            if not self.render_asap:
                sleep(self.scene.getExpectedUpdateTime())

    #example rendering B
    def runOnTkInterMainLoop(self):
        self._callUpdatingOnAfterCall();
        self.root.mainloop()
        
    def _callUpdatingOnAfterCall(self):
        deltaTime = self._estimateFrameTime()
        self._processRenderLoop(deltaTime)
        # uses a scheduler from tkinter GUI Mainloop - test
        # self.scene.getExpectedUpdateTime()
        self.root.after(1, self._callUpdatingOnAfterCall)
开发者ID:xfleckx,项目名称:pyAppDesignStudys,代码行数:79,代码来源:GS_Explained.py


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