當前位置: 首頁>>代碼示例>>Python>>正文


Python Terminal.fullscreen方法代碼示例

本文整理匯總了Python中terminal.Terminal.fullscreen方法的典型用法代碼示例。如果您正苦於以下問題:Python Terminal.fullscreen方法的具體用法?Python Terminal.fullscreen怎麽用?Python Terminal.fullscreen使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在terminal.Terminal的用法示例。


在下文中一共展示了Terminal.fullscreen方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: UI

# 需要導入模塊: from terminal import Terminal [as 別名]
# 或者: from terminal.Terminal import fullscreen [as 別名]
class UI(PyampBase):
    def __init__(self, user_config, reactor=reactor):
        super(UI, self).__init__()
        self.user_config = user_config
        self.reactor = reactor
        self.player = Player(initial_volume=user_config.persistent.volume)
        self.progress_bar = ProgressBar(
            self.user_config.appearance.progress_bar)
        self.time_check = TimeCheck()
        self.status_bar = HorizontalContainer(
            (self.progress_bar, self.time_check))
        self.terminal = Terminal()
        self.key_bindings = self._create_key_bindings()

    def _create_bindable_funcs_map(self):
        bindable_funcs = {}
        for obj in self, self.player:
            for name in dir(obj):
                func = getattr(obj, name)
                if is_bindable(func):
                    bindable_funcs[name] = func
        return bindable_funcs

    def _create_key_bindings(self):
        bindable_funcs = self._create_bindable_funcs_map()
        key_bindings = {}
        for func_name, keys in self.user_config.key_bindings:
            if isinstance(keys, basestring):
                keys = [keys]
            for key in keys:
                key = ' '.join(key.split())
                if func_name in bindable_funcs:
                    key_bindings[key] = bindable_funcs[func_name]
                else:
                    self.log.warning(
                        'Warning: {} is not a bindable pyamp function'.format(
                            func_name))
        return key_bindings

    def update(self):
        try:
            self.player.update()
        except StopIteration:
            self.quit()
        self.draw()

    def draw(self):
        #print self.terminal.clear()
        if self.player.playing:
            position = (self.player.get_position() or 0) / gst.SECOND
            duration = (self.player.get_duration() or 0) / gst.SECOND
            if duration:
                self.progress_bar.fraction = position / duration
            self.time_check.position = position
            self.time_check.duration = duration
        total_width = self.terminal.width - 2
        with self.terminal.location(0, self.terminal.height - 2):
            print self.player.tags['title'].center(self.terminal.width)
            print self.status_bar.draw(total_width, 1).center(
                self.terminal.width),
        sys.stdout.flush()

    def _handle_sigint(self, signal, frame):
        self.quit()

    def handle_input(self, char):
        action = self.key_bindings.get(char, lambda: None)
        action()

    @bindable
    @gst_log_calls
    def quit(self):
        def clean_up():
            self.player.stop()
            self.reactor.stop()
        if self.player.playing:
            fade_out_time = 1
            self.player.fade_out(fade_out_time)
            reactor.callLater(fade_out_time + 0.1, clean_up)
        else:
            clean_up()

    def run(self):
        with self.terminal.fullscreen():
            with self.terminal.hidden_cursor():
                with self.terminal.unbuffered_input():
                    signal.signal(signal.SIGINT, self._handle_sigint)
                    signal.signal(signal.SIGTSTP, self.terminal.handle_sigtstp)
                    self.looping_call = task.LoopingCall(self.update)
                    self.looping_call.start(1 / 20)
                    stdio.StandardIO(InputReader(self))
                    self.reactor.run()
開發者ID:William-Weaver,項目名稱:pyamp,代碼行數:94,代碼來源:pyamp.py


注:本文中的terminal.Terminal.fullscreen方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。