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


Python Screen.refresh方法代码示例

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


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

示例1: main

# 需要导入模块: from screen import Screen [as 别名]
# 或者: from screen.Screen import refresh [as 别名]
def main():

    pygame.init()
    glutInit()

    options = { 'BG': BG, 'ANGLE_VIEW' : ANGLE_VIEW}
    screen = Screen(WIDTH, HEIGHT, options)

    screen.launch()

    n = Node(Color())
    screen.add_object(n)

    while True:
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) #Clear display

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                print("Close painting")
                sys.exit()

        screen.draw()
        screen.refresh() 
开发者ID:Gmulti,项目名称:DirectoryWatcher,代码行数:25,代码来源:painting.py

示例2: UIThread

# 需要导入模块: from screen import Screen [as 别名]
# 或者: from screen.Screen import refresh [as 别名]
class UIThread(CustomThread):
    def __init__(self, client):
        self.parent_client = client
        self.screen = None
        self.msg_queue = []
        self.msg_queue_mutex = Lock()
        self.max_viewable_msgs = 10 # will be adjusted
        self.cmd_line_nr = 13 # "
        self.cmd_line_len = 80 # "
        self.cmd_cursor_pos = 0 # @ beginning of cmd line
        self.ui_input_thread = None
        CustomThread.__init__(self, description="UIThread")

    def init(self):
        self.screen = Screen()
        self.update_dimension()
        self.ui_input_thread = UIInputThread(self, self.screen)

    def update_dimension(self):
        scr = self.screen
        self.max_viewable_msgs  = scr.height - 4 # may be changed
        self.cmd_line_nr        = scr.height - 1 # display in last line
        self.cmd_line_len       = scr.width  - 3 # because of "> " and cursor

    def run(self):
        self.init()
        self.ui_input_thread.start()
        self.render_cmdline() # render once
        while not self.shouldStop:
            self.render_msgs()
            time.sleep(0.3)

    def render_msgs(self):
        scr = self.screen
        oldx, oldy = scr.get_cursor_pos()
        self.msg_queue_mutex.acquire()
        if len(self.msg_queue) <= self.max_viewable_msgs:
            msgs = self.msg_queue[:] # slice it to make a copy
        else:
            msgs = self.msg_queue[-(self.max_viewable_msgs):]
        self.msg_queue_mutex.release()
        for i in range(self.max_viewable_msgs):
            scr.clearln(i)
        for i in range(len(msgs)):
            scr.drawstr(0, i, msgs[i])
        scr.set_cursor_pos(oldx, oldy)
        scr.refresh()

    def render_cmdline(self):
        scr = self.screen
        cmdline = self.ui_input_thread.get_buffer()
        scr.clearln(self.cmd_line_nr)
        scr.drawstr(0, self.cmd_line_nr, "> " + cmdline[-80:])
        scr.set_cursor_pos(2 + len(cmdline[-80:]), self.cmd_line_nr)
        scr.refresh()

    def handle_command(self, cmd):
        client = self.parent_client
        if len(cmd) == 0: # just pressed return
            return
        if not cmd.startswith("/"):
            client.send_msg(cmd)
            self.append_msg("<-- " + cmd)
        else: # is a command
            if cmd[1:].lower() == "stop":
                client.stop()
            if cmd[1:].lower() == "clear":
                self.clear_msg_queue()

    def clear_msg_queue(self):
        self.msg_queue_mutex.acquire()
        self.msg_queue = list()
        self.msg_queue_mutex.release()

    def append_msg(self, msg):
        self.msg_queue_mutex.acquire()
        self.msg_queue.append(msg)
        self.msg_queue_mutex.release()

    def recv_msg(self, msg):
        msg = Message.fromstring(msg, [])
        self.append_msg("--> " + msg.sender_name + ": " + msg.text)

    def print_err(self, errmsg):
        self.screen.clearln(self.max_viewable_msgs)
        self.screen.drawstr(0, self.max_viewable_msgs, "*** " + errmsg)
        self.screen.refresh()
开发者ID:madjoel,项目名称:messer,代码行数:89,代码来源:uithread.py


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