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


Python Timer.set_delay方法代码示例

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


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

示例1: Preview

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import set_delay [as 别名]
class Preview(threading.Thread): 
    '''
    Preview is a thread object that act as a pygame display control
    PyGame issue on Windows (and possibly other OS than Linux):
        In Windows OS, pygame just collects events in a main therad.
        Then, the application must instatiate the Preview 
        and maint it's controler
    '''

    NONE = -1
    STARTING = 0
    RUNNING = 1
    STOPPING = 2
    KILLED = 3
    
    preview_control = None
    
    def __init__(self, title = "Grid visualizer", 
                 width = PreviewDefaults.width, 
                 height = PreviewDefaults.height,
                 lines = 2, columns = 2, fps_limit = 0,
                 painter_class = Painter):
        # state control
        self.state = Preview.STARTING
        self.default_painter_class = painter_class
        # thread control
        self.threading = True
        # Window app control
        self.width = width
        self.height = height
        self.bgcolor = Color.BLACK
        self.display = pygame.display.set_mode((width + 
                                                VerticalScroll.BUTTOM_SIZE, 
                                                height), 
                                               pygame.HWSURFACE | 
                                               pygame.DOUBLEBUF)
        pygame.display.set_caption(title)
        # diagram selector
        lines = max([1, int(lines)])
        columns = max([1, int(columns)])
        self.grid = Grid(self.display, lines, columns)
        self.mouse_drag = False
        self.key_pressed = None
        # timer control (to pause, FPS, keyboard)
        self.fps_limit = fps_limit
        self.frame_timer = Timer(0)
        if self.fps_limit > 0:
            self.frame_timer.set_delay(1.0 / self.fps_limit)
        self.key_repeat_delay = 1.0 / 2.0
        self.key_repeat_rate  = 1.0 / 10.0
        self.keyboard_timer = Timer(0)
        # count number of painters/objects
        self.count_painters = 0
        # map object to painter
        self.views = dict()
        # multi-thread control
        self.lock = threading.Lock()
    
    def panel_dimensions(self):
        '''
        Get panel dimensions
        '''
        return self.grid.panel_width, self.grid.panel_height

    def set_title(self, title):
        '''
        Change app window caption
        '''
        pygame.display.set_caption(title)
    
    def add_view(self, view, label='', painter_class = None):
        '''
        Include a diagram in previewer
        '''
        assert view is not None
        with self.lock:
            # prevent drawing duplication of same object 
            if view in self.views:
                return False
            # create a painter to object
            if painter_class is None:
                painter = self.default_painter_class(self.count_painters, 
                                                     view, label)
            else:
                painter = painter_class(self.count_painters, view, label)
            self.count_painters += 1
            # make control 
            self.grid.add_painter(painter)
            self.views[view] = painter
            return view
        
    def del_view(self, view):
        assert view is not None
        with self.lock:
            if view in self.views:
                painter = self.views[view]
                self.grid.del_painter(painter)
                del self.views[view]

    def pause(self, delay = 0.0):
#.........这里部分代码省略.........
开发者ID:farbasmiah,项目名称:scenario4,代码行数:103,代码来源:preview.py


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