当前位置: 首页>>代码示例>>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;未经允许,请勿转载。