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


Python Panel.start方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: from panel import Panel [as 別名]
# 或者: from panel.Panel import start [as 別名]
class EventLoop:
    def __init__(self):
        self.window_manager = WindowManager()
        self.events = Queue()
        self.panel = Panel()
        self.clock = Clock()
        self.notification_monitor = NotificationMonitor()

        try:
            with open(os.path.expanduser('~/.config/mpd/credentials.conf'), 'r') as f:
                mpd_settings = json.load(f)
        except FileNotFoundError:
            self.music = Music()
        else:
            self.music = Music(**mpd_settings)
        self.music_controller = self.music.clone()

        self.system_info = SystemInfo()

    def start_thread(self, loop):
        thread = threading.Thread(
            target=loop,
            kwargs={'events': self.events}
        )
        thread.daemon = True
        thread.start()
        return thread

    def process_event(self, event):
        if isinstance(event, PanelStrip):
            self.panel.update(event)
        elif isinstance(event, UserCommand):
            try:
                command = event.command.split()
                if command[0] == 'music_pause':
                    self.music_controller.pause()
                elif command[0] == 'music_stop':
                    self.music_controller.stop()
                elif command[0] == 'music_home':
                    self.music_controller.seek(0)
                elif command[0] == 'music_next':
                    self.music_controller.next()
                elif command[0] == 'music_previous':
                    self.music_controller.previous()
                elif command[0] == 'music_volume':
                    if command[1].startswith('+') or command[1].startswith('-'):
                        is_relative = True
                    else:
                        is_relative = False
                    self.music_controller.volume(int(command[1]), is_relative)
                elif command[0] == 'notification_next':
                    self.notification_monitor.history_next(self.events)
            except:
                sys.stderr.write(
                    "failed executing command. details: \n" +
                    traceback.format_exc()
                )

    def loop(self):
        self.window_manager_thread = self.start_thread(
            self.window_manager.loop
        )
        self.clock_thread = self.start_thread(
            self.clock.loop
        )
        self.system_info_thread = self.start_thread(
            self.system_info.loop
        )
        self.music_thread = self.start_thread(
            self.music.loop
        )
        self.notification_monitor_thread = self.start_thread(
            self.notification_monitor.loop
        )

        self.panel.start()

        while True:
            self.process_event(self.events.get())
開發者ID:DexterLB,項目名稱:ui,代碼行數:81,代碼來源:info.py


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