Mercurial > libervia-backend
diff sat_frontends/jp/xmlui_manager.py @ 3568:04283582966f
core, frontends: fix invalid translatable strings.
Some f-strings where used in translatable text, this has been fixed by using explicit
`format()` call (using a script based on `tokenize`).
As tokenize messes with spaces, a reformating tool (`black`) has been applied to some
files afterwards.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 14 Jun 2021 18:35:12 +0200 |
parents | be6d91572633 |
children | 53a8b50d69ca |
line wrap: on
line diff
--- a/sat_frontends/jp/xmlui_manager.py Mon Jun 14 12:19:21 2021 +0200 +++ b/sat_frontends/jp/xmlui_manager.py Mon Jun 14 18:35:12 2021 +0200 @@ -174,12 +174,11 @@ class EmptyWidget(xmlui_base.EmptyWidget, Widget): - def __init__(self, xmlui_parent): Widget.__init__(self, xmlui_parent) async def show(self): - self.host.disp('') + self.host.disp("") class TextWidget(xmlui_base.TextWidget, ValueWidget): @@ -199,7 +198,7 @@ except AttributeError: return None - async def show(self, end='\n', ansi=""): + async def show(self, end="\n", ansi=""): """show label @param end(str): same as for [JP.disp] @@ -211,6 +210,7 @@ class JidWidget(xmlui_base.JidWidget, TextWidget): type = "jid" + class StringWidget(xmlui_base.StringWidget, InputWidget): type = "string" @@ -221,7 +221,7 @@ elems = [] self.verboseName(elems) if self.value: - elems.append(_(f"(enter: {self.value})")) + elems.append(_("(enter: {value})").format(value=self.value)) elems.extend([C.A_HEADER, "> "]) value = await self.host.ainput(A.color(*elems)) if value: @@ -244,21 +244,24 @@ self.disp(self.value) else: if self.value: - self.disp(A.color(C.A_HEADER, "↓ current value ↓\n", A.FG_CYAN, self.value, - "")) + self.disp( + A.color(C.A_HEADER, "↓ current value ↓\n", A.FG_CYAN, self.value, "") + ) values = [] while True: try: if not values: - line = await self.host.ainput(A.color(C.A_HEADER, "[Ctrl-D to finish]> ")) + line = await self.host.ainput( + A.color(C.A_HEADER, "[Ctrl-D to finish]> ") + ) else: line = await self.host.ainput() values.append(line) except EOFError: - break + break - self.value = '\n'.join(values).rstrip() + self.value = "\n".join(values).rstrip() class XHTMLBoxWidget(xmlui_base.XHTMLBoxWidget, StringWidget): @@ -269,7 +272,8 @@ # this only for now to make it simpler, it must be refactored # to use async when jp will be fully async (expected for 0.8) self.value = await self.host.bridge.syntaxConvert( - self.value, C.SYNTAX_XHTML, "markdown", False, self.host.profile) + self.value, C.SYNTAX_XHTML, "markdown", False, self.host.profile + ) await super(XHTMLBoxWidget, self).show() @@ -285,7 +289,7 @@ if not self.options: return - # list display + # list display self.verboseName() for idx, (value, label) in enumerate(self.options): @@ -304,12 +308,15 @@ self.value = self.options[0][0] return - # we ask use to choose an option + # we ask use to choose an option choice = None limit_max = len(self.options) - 1 while choice is None or choice < 0 or choice > limit_max: choice = await self.host.ainput( - A.color(C.A_HEADER, _(f"your choice (0-{limit_max}): ")) + A.color( + C.A_HEADER, + _("your choice (0-{limit_max}): ").format(limit_max=limit_max), + ) ) try: choice = int(choice) @@ -328,12 +335,14 @@ if self.read_only or self.root.read_only: self.disp(disp_true if self.value else disp_false) else: - self.disp(A.color(C.A_HEADER, "0: ", - disp_false, A.RESET, - " *" if not self.value else "")) - self.disp(A.color(C.A_HEADER, "1: ", - disp_true, A.RESET, - " *" if self.value else "")) + self.disp( + A.color( + C.A_HEADER, "0: ", disp_false, A.RESET, " *" if not self.value else "" + ) + ) + self.disp( + A.color(C.A_HEADER, "1: ", disp_true, A.RESET, " *" if self.value else "") + ) choice = None while choice not in ("0", "1"): elems = [C.A_HEADER, _("your choice (0,1): ")] @@ -345,8 +354,7 @@ def _xmluiGetValue(self): return C.boolConst(self.value) - -## Containers ## + ## Containers ## class Container(Base): @@ -383,7 +391,7 @@ async def show(self): for child in self.children: - end = '\n' + end = "\n" # we check linked widget type # to see if we want the label on the same line or not if child.type == "label": @@ -396,15 +404,14 @@ "string", "jid_input", ): - end = ' ' + end = " " elif wid_type == "bool" and for_widget.read_only: - end = ' ' + end = " " await child.show(end=end, ansi=A.FG_CYAN) else: await child.show() - -## Dialogs ## + ## Dialogs ## class Dialog(object): @@ -422,8 +429,8 @@ """ raise NotImplementedError(self.__class__) + class MessageDialog(xmlui_base.MessageDialog, Dialog): - def __init__(self, xmlui_parent, title, message, level): Dialog.__init__(self, xmlui_parent) xmlui_base.MessageDialog.__init__(self, xmlui_parent) @@ -437,7 +444,6 @@ class NoteDialog(xmlui_base.NoteDialog, Dialog): - def __init__(self, xmlui_parent, title, message, level): Dialog.__init__(self, xmlui_parent) xmlui_base.NoteDialog.__init__(self, xmlui_parent) @@ -456,12 +462,15 @@ class ConfirmDialog(xmlui_base.ConfirmDialog, Dialog): - def __init__(self, xmlui_parent, title, message, level, buttons_set): Dialog.__init__(self, xmlui_parent) xmlui_base.ConfirmDialog.__init__(self, xmlui_parent) self.title, self.message, self.level, self.buttons_set = ( - title, message, level, buttons_set) + title, + message, + level, + buttons_set, + ) async def show(self): # TODO: handle buttons_set and level @@ -469,16 +478,15 @@ if self.title: self.disp(A.color(C.A_HEADER, self.title)) input_ = None - while input_ not in ('y', 'n'): + while input_ not in ("y", "n"): input_ = await self.host.ainput(f"{self.message} (y/n)? ") input_ = input_.lower() - if input_ == 'y': + if input_ == "y": self._xmluiValidated() else: self._xmluiCancelled() - -## Factory ## + ## Factory ## class WidgetFactory(object): @@ -496,8 +504,17 @@ workflow = None _submit_cb = None - def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, - ignore=None, whitelist=None, profile=None): + def __init__( + self, + host, + parsed_dom, + title=None, + flags=None, + callback=None, + ignore=None, + whitelist=None, + profile=None, + ): xmlui_base.XMLUIPanel.__init__( self, host, @@ -588,7 +605,7 @@ await xmlui.show() if xmlui.submit_id: await xmlui.onFormSubmitted() - # TODO: handle data other than XMLUI + # TODO: handle data other than XMLUI if not XMLUIPanel._actions: if self._submit_cb is None: self.host.quit() @@ -622,6 +639,7 @@ pass -create = partial(xmlui_base.create, class_map={ - xmlui_base.CLASS_PANEL: XMLUIPanel, - xmlui_base.CLASS_DIALOG: XMLUIDialog}) +create = partial( + xmlui_base.create, + class_map={xmlui_base.CLASS_PANEL: XMLUIPanel, xmlui_base.CLASS_DIALOG: XMLUIDialog}, +)