Пример #1
0
    def alas_set_group(self, task: str) -> None:
        """
        Set arg groups from dict
        """
        self.init_menu(name=task)
        self.set_title(t(f"Task.{task}.name"))

        put_scope("_groups", [put_none(), put_scope("groups"), put_scope("navigator")])
        config = State.config_updater.read_file(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.set_navigator(group)
Пример #2
0
    def alas_set_group(self, task: str) -> None:
        """
        Set arg groups from dict
        """
        self.init_menu(name=task)
        self.set_title(t(f'Task.{task}.name'))

        put_scope('_groups',
                  [put_none(),
                   put_scope('groups'),
                   put_scope('navigator')])
        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.set_navigator(group)
Пример #3
0
 def _show() -> None:
     put_scope('header', [
         put_html(Icon.ALAS).style("--header-icon--"),
         put_text("Alas").style("--header-text--"),
         put_scope('header_status'),
         put_scope('header_title'),
     ])
     put_scope('contents', [
         put_scope('aside'),
         put_scope('menu'),
         put_scope('content'),
     ])
Пример #4
0
 def _show() -> None:
     put_scope(
         "header",
         [
             put_html(Icon.ALAS).style("--header-icon--"),
             put_text("Alas").style("--header-text--"),
             put_scope("header_status"),
             put_scope("header_title"),
         ],
     )
     put_scope(
         "contents",
         [
             put_scope("aside"),
             put_scope("menu"),
             put_scope("content"),
         ],
     )
Пример #5
0
    def dev_update(self) -> None:
        self.init_menu(name='Update')
        self.set_title(t("Gui.MenuDevelop.Update"))

        if not Setting.reload:
            put_warning(t("Gui.Update.DisabledWarn"))

        put_row(content=[
            put_scope('updater_loading'), None,
            put_scope('updater_state')
        ],
                size='auto .25rem 1fr')

        put_scope('updater_btn')
        put_scope('updater_info')

        def update_table():
            with use_scope('updater_info', clear=True):
                local_commit = updater.get_commit(short_sha1=True)
                upstream_commit = updater.get_commit(
                    f'origin/{updater.branch}', short_sha1=True)
                put_table([[t('Gui.Update.Local'), *local_commit],
                           [t('Gui.Update.Upstream'), *upstream_commit]],
                          header=[
                              '', 'SHA1',
                              t('Gui.Update.Author'),
                              t('Gui.Update.Time'),
                              t('Gui.Update.Message')
                          ])

        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')

        updater_switch = Switch(status=u,
                                get_state=lambda: updater.state,
                                name='updater')

        update_table()
        self.task_handler.add(updater_switch.g(),
                              delay=0.5,
                              pending_delete=True)

        updater.check_update()
Пример #6
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)
Пример #7
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)
Пример #8
0
    def dev_update(self) -> None:
        self.init_menu(name="Update")
        self.set_title(t("Gui.MenuDevelop.Update"))

        if not Setting.reload:
            put_warning(t("Gui.Update.DisabledWarn"))

        put_row(
            content=[
                put_scope("updater_loading"), None,
                put_scope("updater_state")
            ],
            size="auto .25rem 1fr",
        )

        put_scope("updater_btn")
        put_scope("updater_info")

        def update_table():
            with use_scope("updater_info", clear=True):
                local_commit = updater.get_commit(short_sha1=True)
                upstream_commit = updater.get_commit(
                    f"origin/{updater.branch}", short_sha1=True)
                put_table(
                    [
                        [t("Gui.Update.Local"), *local_commit],
                        [t("Gui.Update.Upstream"), *upstream_commit],
                    ],
                    header=[
                        "",
                        "SHA1",
                        t("Gui.Update.Author"),
                        t("Gui.Update.Time"),
                        t("Gui.Update.Message"),
                    ],
                )

        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")

        updater_switch = Switch(status=u,
                                get_state=lambda: updater.state,
                                name="updater")

        update_table()
        self.task_handler.add(updater_switch.g(),
                              delay=0.5,
                              pending_delete=True)

        updater.check_update()
Пример #9
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)
Пример #10
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)
Пример #11
0
    def dev_remote(self) -> None:
        self.init_menu(name="Remote")
        self.set_title(t("Gui.MenuDevelop.Remote"))
        put_row(
            content=[put_scope("remote_loading"), None, put_scope("remote_state")],
            size="auto .25rem 1fr",
        )
        put_scope("remote_info")

        def u(state):
            if state == -1:
                return
            clear("remote_loading")
            clear("remote_state")
            clear("remote_info")
            if state in (1, 2):
                put_loading("grow", "success", "remote_loading").style(
                    "--loading-grow--"
                )
                put_text(t("Gui.Remote.Running"), scope="remote_state")
                put_text(t("Gui.Remote.EntryPoint"), scope="remote_info")
                entrypoint = RemoteAccess.get_entry_point()
                if entrypoint:
                    if State.electron:  # Prevent click into url in electron client
                        put_text(entrypoint, scope="remote_info").style(
                            "text-decoration-line: underline"
                        )
                    else:
                        put_link(name=entrypoint, url=entrypoint, scope="remote_info")
                else:
                    put_text("Loading...", scope="remote_info")
            elif state in (0, 3):
                put_loading("border", "secondary", "remote_loading").style(
                    "--loading-border-fill--"
                )
                if (
                    State.deploy_config.EnableRemoteAccess
                    and State.deploy_config.Password
                ):
                    put_text(t("Gui.Remote.NotRunning"), scope="remote_state")
                else:
                    put_text(t("Gui.Remote.NotEnable"), scope="remote_state")
                put_text(t("Gui.Remote.ConfigureHint"), scope="remote_info")
                url = "http://app.azurlane.cloud" + (
                    "" if State.deploy_config.Language.startswith("zh") else "/en.html"
                )
                put_html(
                    f'<a href="{url}" target="_blank">{url}</a>', scope="remote_info"
                )
                if state == 3:
                    put_warning(
                        t("Gui.Remote.SSHNotInstall"),
                        closable=False,
                        scope="remote_info",
                    )

        remote_switch = Switch(
            status=u, get_state=RemoteAccess.get_state, name="remote"
        )

        self.task_handler.add(remote_switch.g(), delay=1, pending_delete=True)