Example #1
0
 def set_navigator(self, group):
     js = f'''
         $("#pywebio-scope-groups").scrollTop(
             $("#pywebio-scope-group_{group[0]}").position().top
             + $("#pywebio-scope-groups").scrollTop() - 59
         )
     '''
     put_button(label=t(f"{group[0]}._info.name"),
                onclick=lambda: run_js(js),
                color='navigator')
Example #2
0
 def put_task(func: Function):
     with use_scope(f'overview-task_{func.command}'):
         put_column([
             put_text(
                 t(f'Task.{func.command}.name')).style("--arg-title--"),
             put_text(str(func.next_run)).style("--arg-help--"),
         ],
                    size="auto auto")
         put_button(label=t("Gui.Button.Setting"),
                    onclick=lambda: self.alas_set_group(func.command),
                    color="off")
Example #3
0
 def put(name=None, origin=None):
     put_input(name="AddAlas_name",
               label=t("Gui.AddAlas.NewName"),
               value=name or get_unused_name(),
               scope=s),
     put_select(name="AddAlas_copyfrom",
                label=t("Gui.AddAlas.CopyFrom"),
                options=['template'] + alas_instance(),
                value=origin or 'template',
                scope=s),
     put_button(label=t("Gui.AddAlas.Confirm"),
                onclick=add,
                scope=s)
Example #4
0
    def dev_utils(self) -> None:
        self.init_menu(name="Utils")
        self.set_title(t("Gui.MenuDevelop.Utils"))
        put_button(label="Raise exception", onclick=raise_exception)

        def _force_restart():
            if State.restart_event is not None:
                toast("Alas will restart in 3 seconds", duration=0, color="error")
                clearup()
                State.restart_event.set()
            else:
                toast("Reload not enabled", color="error")

        put_button(label="Force restart", onclick=_force_restart)
Example #5
0
    def dev_set_menu(self) -> None:
        self.init_menu(collapse_menu=False, name="Develop")

        put_button(
            label=t("Gui.MenuDevelop.HomePage"),
            onclick=self.show,
            color="menu",
        ).style(f"--menu-HomePage--")

        # put_button(
        #     label=t("Gui.MenuDevelop.Translate"),
        #     onclick=self.dev_translate,
        #     color="menu",
        # ).style(f"--menu-Translate--")

        put_button(
            label=t("Gui.MenuDevelop.Update"),
            onclick=self.dev_update,
            color="menu",
        ).style(f"--menu-Update--")

        put_button(
            label=t("Gui.MenuDevelop.Remote"),
            onclick=self.dev_remote,
            color="menu",
        ).style(f"--menu-Remote--")

        put_button(
            label=t("Gui.MenuDevelop.Utils"),
            onclick=self.dev_utils,
            color="menu",
        ).style(f"--menu-Utils--")
Example #6
0
    def dev_set_menu(self) -> None:
        self.init_menu(collapse_menu=False, name="Develop")

        put_button(label=t("Gui.MenuDevelop.HomePage"),
                   onclick=self.show,
                   color="menu").style(f'--menu-HomePage--')

        put_button(label=t("Gui.MenuDevelop.Translate"),
                   onclick=self.dev_translate,
                   color="menu").style(f'--menu-Translate--')

        put_button(label=t("Gui.MenuDevelop.Update"),
                   onclick=self.dev_update,
                   color="menu").style(f'--menu-Update--')
Example #7
0
 def u(state):
     if state == -1:
         return
     clear('updater_loading')
     clear('updater_state')
     clear('updater_btn')
     if state == 0:
         put_loading('border', 'secondary',
                     'updater_loading').style("--loading-border-fill--")
         put_text(t('Gui.Update.UpToDate'), scope='updater_state')
         put_button(t('Gui.Button.CheckUpdate'),
                    onclick=updater.check_update,
                    color='info',
                    scope='updater_btn')
         update_table()
     elif state == 1:
         put_loading('grow', 'success',
                     'updater_loading').style("--loading-grow--")
         put_text(t('Gui.Update.HaveUpdate'), scope='updater_state')
         put_button(t('Gui.Button.ClickToUpdate'),
                    onclick=updater.run_update,
                    color='success',
                    scope='updater_btn')
         update_table()
     elif state == 'checking':
         put_loading('border', 'primary',
                     'updater_loading').style("--loading-border--")
         put_text(t('Gui.Update.UpdateChecking'), scope='updater_state')
     elif state == 'failed':
         put_loading('grow', 'danger',
                     'updater_loading').style("--loading-grow--")
         put_text(t('Gui.Update.UpdateFailed'), scope='updater_state')
         put_button(t('Gui.Button.RetryUpdate'),
                    onclick=updater.run_update,
                    color='primary',
                    scope='updater_btn')
     elif state == 'start':
         put_loading('border', 'primary',
                     'updater_loading').style("--loading-border--")
         put_text(t('Gui.Update.UpdateStart'), scope='updater_state')
         put_button(t('Gui.Button.CancelUpdate'),
                    onclick=updater.cancel,
                    color='danger',
                    scope='updater_btn')
     elif state == 'wait':
         put_loading('border', 'primary',
                     'updater_loading').style("--loading-border--")
         put_text(t('Gui.Update.UpdateWait'), scope='updater_state')
         put_button(t('Gui.Button.CancelUpdate'),
                    onclick=updater.cancel,
                    color='danger',
                    scope='updater_btn')
     elif state == 'run update':
         put_loading('border', 'primary',
                     'updater_loading').style("--loading-border--")
         put_text(t('Gui.Update.UpdateRun'), scope='updater_state')
         put_button(t('Gui.Button.CancelUpdate'),
                    onclick=updater.cancel,
                    color='danger',
                    scope='updater_btn',
                    disabled=True)
     elif state == 'reload':
         put_loading('grow', 'success',
                     'updater_loading').style("--loading-grow--")
         put_text(t('Gui.Update.UpdateSuccess'), scope='updater_state')
         update_table()
     elif state == 'finish':
         put_loading('grow', 'success',
                     'updater_loading').style("--loading-grow--")
         put_text(t('Gui.Update.UpdateFinish'), scope='updater_state')
         update_table()
     elif state == 'cancel':
         put_loading('border', 'danger',
                     'updater_loading').style("--loading-border--")
         put_text(t('Gui.Update.UpdateCancel'), scope='updater_state')
         put_button(t('Gui.Button.CancelUpdate'),
                    onclick=updater.cancel,
                    color='danger',
                    scope='updater_btn',
                    disabled=True)
     else:
         put_text("Something went wrong, please contact develops",
                  scope='updater_state')
         put_text(f"state: {state}", scope='updater_state')
Example #8
0
    def alas_daemon_overview(self, task: str) -> None:
        self.init_menu(name=task)
        self.set_title(t(f'Task.{task}.name'))

        if self.is_mobile:
            put_scope('daemon-overview', [
                put_scope('scheduler-bar'),
                put_scope('groups'),
                put_scope('log-bar'),
                self.alas_logs.output()
            ])
        else:
            put_scope('daemon-overview', [
                put_none(),
                put_scope('_daemon', [
                    put_scope(
                        '_daemon_upper',
                        [put_scope('scheduler-bar'),
                         put_scope('log-bar')]),
                    put_scope('groups'),
                    self.alas_logs.output()
                ]),
                put_none(),
            ])

        with use_scope('scheduler-bar'):
            put_text(t("Gui.Overview.Scheduler")).style(
                "font-size: 1.25rem; margin: auto .5rem auto;")
            put_scope('scheduler_btn')

        switch_scheduler = BinarySwitchButton(
            label_on=t("Gui.Button.Stop"),
            label_off=t("Gui.Button.Start"),
            onclick_on=lambda: self.alas.stop(),
            onclick_off=lambda: self.alas.start(task),
            get_state=lambda: self.alas.alive,
            color_on='on',
            color_off='off',
            scope='scheduler_btn')

        with use_scope('log-bar'):
            put_text(t("Gui.Overview.Log")).style(
                "font-size: 1.25rem; margin: auto .5rem auto;")
            put_scope('log-bar-btns', [
                put_button(
                    label=t("Gui.Button.ClearLog"),
                    onclick=self.alas_logs.reset,
                    color='off',
                ),
                put_scope('log_scroll_btn')
            ])

        switch_log_scroll = BinarySwitchButton(
            label_on=t("Gui.Button.ScrollON"),
            label_off=t("Gui.Button.ScrollOFF"),
            onclick_on=lambda: self.alas_logs.set_scroll(False),
            onclick_off=lambda: self.alas_logs.set_scroll(True),
            get_state=lambda: self.alas_logs.keep_bottom,
            color_on='on',
            color_off='off',
            scope='log_scroll_btn')

        config = Setting.config_updater.update_config(self.alas_name)
        for group, arg_dict in deep_iter(self.ALAS_ARGS[task], depth=1):
            self.set_group(group, arg_dict, config, task)

        self.task_handler.add(switch_scheduler.g(), 1, True)
        self.task_handler.add(switch_log_scroll.g(), 1, True)
        self.task_handler.add(self.alas_put_log(), 0.2, True)
Example #9
0
    def alas_overview(self) -> None:
        self.init_menu(name="Overview")
        self.set_title(t(f'Gui.MenuAlas.Overview'))

        put_scope('overview', [put_scope('schedulers'), put_scope('logs')])

        with use_scope('schedulers'):
            put_scope('scheduler-bar', [
                put_text(t("Gui.Overview.Scheduler")).style(
                    "font-size: 1.25rem; margin: auto .5rem auto;"),
                put_scope('scheduler_btn')
            ])
            put_scope('running', [
                put_text(t("Gui.Overview.Running")),
                put_html('<hr class="hr-group">'),
                put_scope('running_tasks')
            ])
            put_scope('pending', [
                put_text(t("Gui.Overview.Pending")),
                put_html('<hr class="hr-group">'),
                put_scope('pending_tasks')
            ])
            put_scope('waiting', [
                put_text(t("Gui.Overview.Waiting")),
                put_html('<hr class="hr-group">'),
                put_scope('waiting_tasks')
            ])

        switch_scheduler = BinarySwitchButton(
            label_on=t("Gui.Button.Stop"),
            label_off=t("Gui.Button.Start"),
            onclick_on=lambda: self.alas.stop(),
            onclick_off=lambda: self.alas.start('Alas', updater.event),
            get_state=lambda: self.alas.alive,
            color_on='off',
            color_off='on',
            scope='scheduler_btn')

        with use_scope('logs'):
            put_scope('log-bar', [
                put_text(t("Gui.Overview.Log")).style(
                    "font-size: 1.25rem; margin: auto .5rem auto;"),
                put_scope('log-bar-btns', [
                    put_button(
                        label=t("Gui.Button.ClearLog"),
                        onclick=self.alas_logs.reset,
                        color='off',
                    ),
                    put_scope('log_scroll_btn')
                ])
            ])
            self.alas_logs.output()

        switch_log_scroll = BinarySwitchButton(
            label_on=t("Gui.Button.ScrollON"),
            label_off=t("Gui.Button.ScrollOFF"),
            onclick_on=lambda: self.alas_logs.set_scroll(False),
            onclick_off=lambda: self.alas_logs.set_scroll(True),
            get_state=lambda: self.alas_logs.keep_bottom,
            color_on='on',
            color_off='off',
            scope='log_scroll_btn')

        self.task_handler.add(switch_scheduler.g(), 1, True)
        self.task_handler.add(switch_log_scroll.g(), 1, True)
        self.task_handler.add(self.alas_update_overiew_task, 10, True)
        self.task_handler.add(self.alas_put_log(), 0.2, True)
#
# pout.put_code("""pin.select("Who's GOAT in NBA?", options=["Bryant", "Jordan", "James"])""")
# pin.select("Who's GOAT in NBA?", options=["Bryant", "Jordan", "James"])
#
# pout.put_code("""pin.radio("Are you ready to try pyWebIO?", options=["Yes", "No"])""")
# pin.radio("Are you ready to try pyWebIO?", options=["Yes", "No"])

pout.put_text("This is an awesome library.")

pout.put_table([("Col 1 Title", "Col 2 Title"),
                ("Row 1, Col 1", "Row 1, Col 2"),
                ("Row 2, Col 1", "Row 2, Col2")])

pout.put_markdown("# This is the Title")
pout.put_markdown("## This is the Subtitle")
pout.put_markdown("_Bold Text_")
pout.put_markdown("__Italic Text__")
pout.put_markdown("*__Bold & Italic__*")
pout.put_markdown("[google.com](google.com)")

pout.put_image(open("airplane.jpg", "rb").read())
pout.toast("Please Pay Attention!", duration=10)


def show_text():
    pout.toast("Button is clicked!", duration=10)


pout.put_button("I'm Ready!", onclick=show_text)
pout.toast("test")
Example #11
0
 def u(state):
     if state == -1:
         return
     clear("updater_loading")
     clear("updater_state")
     clear("updater_btn")
     if state == 0:
         put_loading("border", "secondary",
                     "updater_loading").style("--loading-border-fill--")
         put_text(t("Gui.Update.UpToDate"), scope="updater_state")
         put_button(
             t("Gui.Button.CheckUpdate"),
             onclick=updater.check_update,
             color="info",
             scope="updater_btn",
         )
         update_table()
     elif state == 1:
         put_loading("grow", "success",
                     "updater_loading").style("--loading-grow--")
         put_text(t("Gui.Update.HaveUpdate"), scope="updater_state")
         put_button(
             t("Gui.Button.ClickToUpdate"),
             onclick=updater.run_update,
             color="success",
             scope="updater_btn",
         )
         update_table()
     elif state == "checking":
         put_loading("border", "primary",
                     "updater_loading").style("--loading-border--")
         put_text(t("Gui.Update.UpdateChecking"), scope="updater_state")
     elif state == "failed":
         put_loading("grow", "danger",
                     "updater_loading").style("--loading-grow--")
         put_text(t("Gui.Update.UpdateFailed"), scope="updater_state")
         put_button(
             t("Gui.Button.RetryUpdate"),
             onclick=updater.run_update,
             color="primary",
             scope="updater_btn",
         )
     elif state == "start":
         put_loading("border", "primary",
                     "updater_loading").style("--loading-border--")
         put_text(t("Gui.Update.UpdateStart"), scope="updater_state")
         put_button(
             t("Gui.Button.CancelUpdate"),
             onclick=updater.cancel,
             color="danger",
             scope="updater_btn",
         )
     elif state == "wait":
         put_loading("border", "primary",
                     "updater_loading").style("--loading-border--")
         put_text(t("Gui.Update.UpdateWait"), scope="updater_state")
         put_button(
             t("Gui.Button.CancelUpdate"),
             onclick=updater.cancel,
             color="danger",
             scope="updater_btn",
         )
     elif state == "run update":
         put_loading("border", "primary",
                     "updater_loading").style("--loading-border--")
         put_text(t("Gui.Update.UpdateRun"), scope="updater_state")
         put_button(
             t("Gui.Button.CancelUpdate"),
             onclick=updater.cancel,
             color="danger",
             scope="updater_btn",
             disabled=True,
         )
     elif state == "reload":
         put_loading("grow", "success",
                     "updater_loading").style("--loading-grow--")
         put_text(t("Gui.Update.UpdateSuccess"), scope="updater_state")
         update_table()
     elif state == "finish":
         put_loading("grow", "success",
                     "updater_loading").style("--loading-grow--")
         put_text(t("Gui.Update.UpdateFinish"), scope="updater_state")
         update_table()
     elif state == "cancel":
         put_loading("border", "danger",
                     "updater_loading").style("--loading-border--")
         put_text(t("Gui.Update.UpdateCancel"), scope="updater_state")
         put_button(
             t("Gui.Button.CancelUpdate"),
             onclick=updater.cancel,
             color="danger",
             scope="updater_btn",
             disabled=True,
         )
     else:
         put_text(
             "Something went wrong, please contact develops",
             scope="updater_state",
         )
         put_text(f"state: {state}", scope="updater_state")
Example #12
0
    def alas_daemon_overview(self, task: str) -> None:
        self.init_menu(name=task)
        self.set_title(t(f"Task.{task}.name"))

        log = RichLog("log")

        if self.is_mobile:
            put_scope(
                "daemon-overview",
                [
                    put_scope("scheduler-bar"),
                    put_scope("groups"),
                    put_scope("log-bar"),
                    put_scope("log", [put_html("")]),
                ],
            )
        else:
            put_scope(
                "daemon-overview",
                [
                    put_none(),
                    put_scope(
                        "_daemon",
                        [
                            put_scope(
                                "_daemon_upper",
                                [
                                    put_scope("scheduler-bar"),
                                    put_scope("log-bar")
                                ],
                            ),
                            put_scope("groups"),
                            put_scope("log", [put_html("")]),
                        ],
                    ),
                    put_none(),
                ],
            )

        log.console.width = log.get_width()

        with use_scope("scheduler-bar"):
            put_text(t("Gui.Overview.Scheduler")).style(
                "font-size: 1.25rem; margin: auto .5rem auto;")
            put_scope("scheduler_btn")

        switch_scheduler = BinarySwitchButton(
            label_on=t("Gui.Button.Stop"),
            label_off=t("Gui.Button.Start"),
            onclick_on=lambda: self.alas.stop(),
            onclick_off=lambda: self.alas.start(task),
            get_state=lambda: self.alas.alive,
            color_on="off",
            color_off="on",
            scope="scheduler_btn",
        )

        with use_scope("log-bar"):
            put_text(t("Gui.Overview.Log")).style(
                "font-size: 1.25rem; margin: auto .5rem auto;")
            put_scope(
                "log-bar-btns",
                [
                    put_button(
                        label=t("Gui.Button.ClearLog"),
                        onclick=log.reset,
                        color="off",
                    ),
                    put_scope("log_scroll_btn"),
                ],
            )

        switch_log_scroll = BinarySwitchButton(
            label_on=t("Gui.Button.ScrollON"),
            label_off=t("Gui.Button.ScrollOFF"),
            onclick_on=lambda: log.set_scroll(False),
            onclick_off=lambda: log.set_scroll(True),
            get_state=lambda: log.keep_bottom,
            color_on="on",
            color_off="off",
            scope="log_scroll_btn",
        )

        config = Setting.config_updater.update_config(self.alas_name)
        for group, arg_dict in deep_iter(self.ALAS_ARGS[task], depth=1):
            self.set_group(group, arg_dict, config, task)

        self.task_handler.add(switch_scheduler.g(), 1, True)
        self.task_handler.add(switch_log_scroll.g(), 1, True)
        self.task_handler.add(log.put_log(self.alas), 0.25, True)
Example #13
0
    def alas_overview(self) -> None:
        self.init_menu(name="Overview")
        self.set_title(t(f"Gui.MenuAlas.Overview"))

        put_scope("overview", [put_scope("schedulers"), put_scope("logs")])

        with use_scope("schedulers"):
            put_scope(
                "scheduler-bar",
                [
                    put_text(t("Gui.Overview.Scheduler")).style(
                        "font-size: 1.25rem; margin: auto .5rem auto;"),
                    put_scope("scheduler_btn"),
                ],
            )
            put_scope(
                "running",
                [
                    put_text(t("Gui.Overview.Running")),
                    put_html('<hr class="hr-group">'),
                    put_scope("running_tasks"),
                ],
            )
            put_scope(
                "pending",
                [
                    put_text(t("Gui.Overview.Pending")),
                    put_html('<hr class="hr-group">'),
                    put_scope("pending_tasks"),
                ],
            )
            put_scope(
                "waiting",
                [
                    put_text(t("Gui.Overview.Waiting")),
                    put_html('<hr class="hr-group">'),
                    put_scope("waiting_tasks"),
                ],
            )

        switch_scheduler = BinarySwitchButton(
            label_on=t("Gui.Button.Stop"),
            label_off=t("Gui.Button.Start"),
            onclick_on=lambda: self.alas.stop(),
            onclick_off=lambda: self.alas.start("Alas", updater.event),
            get_state=lambda: self.alas.alive,
            color_on="off",
            color_off="on",
            scope="scheduler_btn",
        )

        log = RichLog("log")

        with use_scope("logs"):
            put_scope(
                "log-bar",
                [
                    put_text(t("Gui.Overview.Log")).style(
                        "font-size: 1.25rem; margin: auto .5rem auto;"),
                    put_scope(
                        "log-bar-btns",
                        [
                            put_button(
                                label=t("Gui.Button.ClearLog"),
                                onclick=log.reset,
                                color="off",
                            ),
                            put_scope("log_scroll_btn"),
                        ],
                    ),
                ],
            ),
            put_scope("log", [put_html("")])

        log.console.width = log.get_width()

        switch_log_scroll = BinarySwitchButton(
            label_on=t("Gui.Button.ScrollON"),
            label_off=t("Gui.Button.ScrollOFF"),
            onclick_on=lambda: log.set_scroll(False),
            onclick_off=lambda: log.set_scroll(True),
            get_state=lambda: log.keep_bottom,
            color_on="on",
            color_off="off",
            scope="log_scroll_btn",
        )

        self.task_handler.add(switch_scheduler.g(), 1, True)
        self.task_handler.add(switch_log_scroll.g(), 1, True)
        self.task_handler.add(self.alas_update_overiew_task, 10, True)
        self.task_handler.add(log.put_log(self.alas), 0.25, True)