def alas_set_menu(self) -> None: """ Set menu """ put_buttons([{ "label": t("Gui.MenuAlas.Overview"), "value": "Overview", "color": "menu" }], onclick=[self.alas_overview]).style(f'--menu-Overview--'), for key, tasks in deep_iter(self.ALAS_MENU, depth=2): # path = '.'.join(key) menu = key[1] if menu == 'Tool': _onclick = self.alas_daemon_overview else: _onclick = self.alas_set_group task_btn_list = [] for task in tasks: task_btn_list.append( put_buttons([{ "label": t(f'Task.{task}.name'), "value": task, "color": "menu" }], onclick=_onclick).style(f'--menu-{task}--')) put_collapse(title=t(f"Menu.{menu}.name"), content=task_btn_list) self.alas_overview()
def show(self) -> None: self._show() self.init_aside(name="Home") self.set_aside() self.collapse_menu() self.alas_name = "" if hasattr(self, "alas"): del self.alas self.set_status(0) def set_language(l): lang.set_language(l) self.show() def set_theme(t): self.set_theme(t) run_js("location.reload()") with use_scope("content"): put_text("Select your language / 选择语言").style("text-align: center") put_buttons( [ {"label": "简体中文", "value": "zh-CN"}, {"label": "繁體中文", "value": "zh-TW"}, {"label": "English", "value": "en-US"}, {"label": "日本語", "value": "ja-JP"}, ], onclick=lambda l: set_language(l), ).style("text-align: center") put_text("Change theme / 更改主题").style("text-align: center") put_buttons( [ {"label": "Light", "value": "default", "color": "light"}, {"label": "Dark", "value": "dark", "color": "dark"}, ], onclick=lambda t: set_theme(t), ).style("text-align: center") # show something put_markdown( """ Alas is a free open source software, if you paid for Alas from any channel, please refund. Alas 是一款免费开源软件,如果你在任何渠道付费购买了Alas,请退款。 Project repository 项目地址:`https://github.com/LmeSzinc/AzurLaneAutoScript` """ ).style("text-align: center") if lang.TRANSLATE_MODE: lang.reload() def _disable(): lang.TRANSLATE_MODE = False self.show() toast( _t("Gui.Toast.DisableTranslateMode"), duration=0, position="right", onclick=_disable, )
def guess(): pywebio.output.clear(scope=-1) global taxmin taxmin = random.randint(quyi, yuqori) put_text(f"Siz {taxmin} sonini o'yladingiz!") put_buttons(['Kattaroq', 'Togri', 'Kichikroq'], onclick=[katta, bingo, kichik]) pywebio.session.hold()
def guess(self): self.__taxminlar += 1 yuqori = self.__yuqori quyi = self.__quyi pywebio.output.clear(scope=- 1) self.__taxmin = random.randint(quyi, yuqori) put_text(f"Siz {self.__taxmin} sonini o'yladingiz!") put_buttons(['Kattaroq','Togri','Kichikroq'], onclick=[self.katta, self.bingo,self.kichik]) pywebio.session.hold()
def todolist(): tasks = [] put_html(r"""<h1 align="center"><strong>📝 To-Do List</strong></h1>""") with use_scope('tasks'): while True: task = input( type=TEXT, required=True, label='🏃 What are you going to do today?', placeholder='Add a task...', help_text='Try: "Write an article"', ) tasks.append(task) clear('tasks') put_table( tdata=[[ task, put_buttons(['Complete'], onclick=partial(complete_task, task=task, tasks=tasks)) ] for task in tasks], header=[ '🤩 Your Awesome Tasks', '✅ Have you completed your task?', ], )
def complete_task(choice: str, task: str, tasks): if choice == 'Complete': tasks.remove(task) clear('tasks') if tasks: put_table( tdata=[[ put_text(task), put_buttons(['Complete'], onclick=partial(complete_task, task=task, tasks=tasks)) ] for task in tasks], header=[ '🤩 Your Awesome Tasks', '✅ Have you completed your task?', ], scope='tasks', )
def task_1(): put_text('task_1') put_buttons(['Go task 2'], [lambda: go_app('task_2')]) hold()
def task_2(): put_text('task_2') put_buttons(['Go task 1', "233"], [lambda: go_app('task_1', False), lambda: put_text("233")]) hold()
def translate(): """ Translate Alas """ set_env(output_animation=False) run_js(r"""$('head').append('<style>footer {display: none}</style>')""") put_markdown(""" # Translate You can submit(Next) by press `Enter`. """) dict_lang = { "zh-CN": read_file(filepath_i18n('zh-CN')), "zh-TW": read_file(filepath_i18n('zh-TW')), "en-US": read_file(filepath_i18n('en-US')), "ja-JP": read_file(filepath_i18n('ja-JP')), } modified = { "zh-CN": {}, "zh-TW": {}, "en-US": {}, "ja-JP": {}, } list_path = [] # Menu.Task.name list_group = [] # Menu list_arg = [] # Task list_key = [] # name for L, _ in deep_iter(dict_lang['zh-CN'], depth=3): list_path.append('.'.join(L)) list_group.append(L[0]) list_arg.append(L[1]) list_key.append(L[2]) total = len(list_path) class V: lang = lang.LANG untranslated_only = False clear = False idx = -1 group = '' group_idx = 0 groups = list(dict_lang['zh-CN'].keys()) arg = '' arg_idx = 0 args = [] key = '' key_idx = 0 keys = [] def update_var(group=None, arg=None, key=None): if group: V.group = group V.idx = list_group.index(group) V.group_idx = V.idx V.arg = list_arg[V.idx] V.arg_idx = V.idx V.args = list(dict_lang["zh-CN"][V.group].keys()) V.key = list_key[V.idx] V.key_idx = V.idx V.keys = list(dict_lang["zh-CN"][V.group][V.arg].keys()) elif arg: V.arg = arg V.idx = list_arg.index(arg, V.group_idx) V.arg_idx = V.idx V.args = list(dict_lang["zh-CN"][V.group].keys()) V.key = list_key[V.idx] V.key_idx = V.idx V.keys = list(dict_lang["zh-CN"][V.group][V.arg].keys()) elif key: V.key = key V.idx = list_key.index(key, V.arg_idx) V.key_idx = V.idx V.keys = list(dict_lang["zh-CN"][V.group][V.arg].keys()) update_form() def next_key(): if V.idx + 1 > total: V.idx = -1 V.idx += 1 if V.untranslated_only: while True: # print(V.idx) key = deep_get(dict_lang[V.lang], list_path[V.idx]) if list_path[V.idx] == key or list_path[V.idx].split( '.')[2] == key: break else: V.idx += 1 if V.idx + 1 > total: V.idx = 0 break (V.group, V.arg, V.key) = tuple(list_path[V.idx].split('.')) V.group_idx = list_group.index(V.group) V.arg_idx = list_arg.index(V.arg, V.group_idx) V.args = list(dict_lang["zh-CN"][V.group].keys()) V.key_idx = list_key.index(V.key, V.arg_idx) V.keys = list(dict_lang["zh-CN"][V.group][V.arg].keys()) def update_form(): input_update('arg', options=V.args, value=V.arg) input_update('key', options=V.keys, value=V.key) for L in LANGUAGES: input_update(L, value=deep_get(dict_lang[L], f'{V.group}.{V.arg}.{V.key}', 'Key not found!')) old = deep_get(dict_lang[V.lang], f'{V.group}.{V.arg}.{V.key}', 'Key not found!') input_update( V.lang, value=None if V.clear else old, help_text=f'{V.group}.{V.arg}.{V.key}', placeholder=old, ) def get_inputs(): out = [] old = deep_get(dict_lang[V.lang], f'{V.group}.{V.arg}.{V.key}', 'Key not found!') out.append( input( name=V.lang, label=V.lang, value=None if V.clear else old, help_text=f'{V.group}.{V.arg}.{V.key}', placeholder=old, )) out.append( select(name='group', label='Group', options=V.groups, value=V.group, onchange=lambda g: update_var(group=g), required=True)) out.append( select(name='arg', label='Arg', options=V.args, value=V.arg, onchange=lambda a: update_var(arg=a), required=True)) out.append( select(name='key', label='Key', options=V.keys, value=V.key, onchange=lambda k: update_var(key=k), required=True)) _LANGUAGES = LANGUAGES.copy() _LANGUAGES.remove(V.lang) for L in _LANGUAGES: out.append( input(name=L, label=L, readonly=True, value=deep_get(dict_lang[L], f'{V.group}.{V.arg}.{V.key}', 'Key not found!'))) out.append( actions(name='action', buttons=[ { "label": "Next", "value": 'Next', "type": "submit", "color": "success" }, { "label": "Next without save", "value": 'Skip', "type": "submit", "color": "secondary" }, { "label": "Submit", "value": "Submit", "type": "submit", "color": "primary" }, { "label": "Quit and save", "type": "cancel", "color": "secondary" }, ])) return out def save(): for LANG in LANGUAGES: d = read_file(filepath_i18n(LANG)) for k in modified[LANG].keys(): deep_set(d, k, modified[LANG][k]) write_file(filepath_i18n(LANG), d) defer_call(save) def loop(): while True: data = input_group(inputs=get_inputs()) if data is None: save() break if data['action'] == 'Next': modified[V.lang][f'{V.group}.{V.arg}.{V.key}'] = data[ V.lang].replace("\\n", "\n") deep_set(dict_lang[V.lang], f'{V.group}.{V.arg}.{V.key}', data[V.lang].replace("\\n", "\n")) next_key() if data['action'] == 'Skip': next_key() elif data['action'] == 'Submit': modified[V.lang][f'{V.group}.{V.arg}.{V.key}'] = data[ V.lang].replace("\\n", "\n") deep_set(dict_lang[V.lang], f'{V.group}.{V.arg}.{V.key}', data[V.lang].replace("\\n", "\n")) continue def setting(): data = input_group(inputs=[ select(name='language', label='Language', options=LANGUAGES, value=V.lang, required=True), checkbox( name='check', label='Other settings', options=[{ "label": 'Button [Next] only shows untranslated key', 'value': 'untranslated', 'selected': V.untranslated_only }, { "label": 'Do not fill input with old value (only effect the language you selected)', "value": "clear", "selected": V.clear }]) ]) V.lang = data['language'] V.untranslated_only = True if 'untranslated' in data['check'] else False V.clear = True if 'clear' in data['check'] else False put_buttons([{ "label": "Start", "value": "start" }, { "label": "Setting", "value": "setting" }], onclick=[loop, setting]) next_key() setting() hold()