diff sat_frontends/jp/xmlui_manager.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 26edcf3a30eb
children bdb8276fd2da
line wrap: on
line diff
--- a/sat_frontends/jp/xmlui_manager.py	Wed Jun 27 07:51:29 2018 +0200
+++ b/sat_frontends/jp/xmlui_manager.py	Wed Jun 27 20:14:46 2018 +0200
@@ -18,6 +18,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from sat.core.log import getLogger
+
 log = getLogger(__name__)
 from sat_frontends.tools import xmlui as xmlui_manager
 from sat_frontends.jp.constants import Const as C
@@ -27,14 +28,15 @@
 
 # workflow constants
 
-SUBMIT = 'SUBMIT'  # submit form
-
+SUBMIT = "SUBMIT"  # submit form
 
 
 ## Widgets ##
 
+
 class Base(object):
     """Base for Widget and Container"""
+
     type = None
     _root = None
 
@@ -58,7 +60,7 @@
 
 
 class Widget(Base):
-    category = u'widget'
+    category = u"widget"
     enabled = True
 
     @property
@@ -85,16 +87,19 @@
         if value is None:
             value = self.name
         if self.host.verbosity:
-            to_disp = [A.FG_MAGENTA,
-                       u' ' if elems else u'',
-                       u'({})'.format(value), A.RESET]
+            to_disp = [
+                A.FG_MAGENTA,
+                u" " if elems else u"",
+                u"({})".format(value),
+                A.RESET,
+            ]
             if elems is None:
                 self.host.disp(A.color(*to_disp))
             else:
                 elems.extend(to_disp)
 
+
 class ValueWidget(Widget):
-
     def __init__(self, xmlui_parent, value):
         super(ValueWidget, self).__init__(xmlui_parent)
         self.value = value
@@ -105,7 +110,6 @@
 
 
 class InputWidget(ValueWidget):
-
     def __init__(self, xmlui_parent, value, read_only=False):
         super(InputWidget, self).__init__(xmlui_parent, value)
         self.read_only = read_only
@@ -115,7 +119,6 @@
 
 
 class OptionsWidget(Widget):
-
     def __init__(self, xmlui_parent, options, selected, style):
         super(OptionsWidget, self).__init__(xmlui_parent)
         self.options = options
@@ -157,21 +160,20 @@
     def items(self):
         """return suitable items, according to style"""
         no_select = self.no_select
-        for value,label in self.options:
+        for value, label in self.options:
             if no_select or value in self.selected:
-                yield value,label
+                yield value, label
 
     @property
     def inline(self):
-        return u'inline' in self.style
+        return u"inline" in self.style
 
     @property
     def no_select(self):
-        return u'noselect' in self.style
+        return u"noselect" in self.style
 
 
 class EmptyWidget(xmlui_manager.EmptyWidget, Widget):
-
     def __init__(self, _xmlui_parent):
         Widget.__init__(self)
 
@@ -193,7 +195,7 @@
         except AttributeError:
             return None
 
-    def show(self, no_lf=False, ansi=u''):
+    def show(self, no_lf=False, ansi=u""):
         """show label
 
         @param no_lf(bool): same as for [JP.disp]
@@ -212,18 +214,17 @@
             elems = []
             self.verboseName(elems)
             if self.value:
-                elems.append(_(u'(enter: {default})').format(default=self.value))
-            elems.extend([C.A_HEADER, u'> '])
+                elems.append(_(u"(enter: {default})").format(default=self.value))
+            elems.extend([C.A_HEADER, u"> "])
             value = raw_input(A.color(*elems))
             if value:
-                # TODO: empty value should be possible
+                #  TODO: empty value should be possible
                 #       an escape key should be used for default instead of enter with empty value
                 self.value = value
 
 
-
 class JidInputWidget(xmlui_manager.JidInputWidget, StringWidget):
-    type = u'jid_input'
+    type = u"jid_input"
 
 
 class TextBoxWidget(xmlui_manager.TextWidget, StringWidget):
@@ -231,7 +232,7 @@
 
 
 class ListWidget(xmlui_manager.ListWidget, OptionsWidget):
-    type = u'list'
+    type = u"list"
     # TODO: handle flags, notably multi
 
     def show(self):
@@ -248,7 +249,7 @@
         for idx, (value, label) in enumerate(self.options):
             elems = []
             if not self.root.read_only:
-                elems.extend([C.A_SUBHEADER, unicode(idx), A.RESET, u': '])
+                elems.extend([C.A_SUBHEADER, unicode(idx), A.RESET, u": "])
             elems.append(label)
             self.verboseName(elems, value)
             self.disp(A.color(*elems))
@@ -261,45 +262,49 @@
             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 = raw_input(A.color(C.A_HEADER, _(u'your choice (0-{max}): ').format(max=limit_max)))
+        limit_max = len(self.options) - 1
+        while choice is None or choice < 0 or choice > limit_max:
+            choice = raw_input(
+                A.color(C.A_HEADER, _(u"your choice (0-{max}): ").format(max=limit_max))
+            )
             try:
                 choice = int(choice)
             except ValueError:
                 choice = None
         self.value = self.options[choice][0]
-        self.disp('')
+        self.disp("")
 
 
 class BoolWidget(xmlui_manager.BoolWidget, InputWidget):
-    type = u'bool'
+    type = u"bool"
 
     def show(self):
-        disp_true = A.color(A.FG_GREEN, u'TRUE')
-        disp_false = A.color(A.FG_RED,u'FALSE')
+        disp_true = A.color(A.FG_GREEN, u"TRUE")
+        disp_false = A.color(A.FG_RED, u"FALSE")
         if self.read_only:
             self.disp(disp_true if self.value else disp_false)
         else:
-            self.disp(A.color(C.A_HEADER, u'0: ', disp_false))
-            self.disp(A.color(C.A_HEADER, u'1: ', disp_true))
+            self.disp(A.color(C.A_HEADER, u"0: ", disp_false))
+            self.disp(A.color(C.A_HEADER, u"1: ", disp_true))
             choice = None
-            while choice not in ('0', '1'):
-                elems = [C.A_HEADER, _(u'your choice (0,1): ')]
+            while choice not in ("0", "1"):
+                elems = [C.A_HEADER, _(u"your choice (0,1): ")]
                 self.verboseName(elems)
                 choice = raw_input(A.color(*elems))
             self.value = bool(int(choice))
-            self.disp('')
+            self.disp("")
 
     def _xmluiGetValue(self):
         return C.boolConst(self.value)
 
+
 ## Containers ##
 
+
 class Container(Base):
-    category = u'container'
+    category = u"container"
 
     def __init__(self, xmlui_parent):
         super(Container, self).__init__(xmlui_parent)
@@ -320,39 +325,43 @@
 
 
 class VerticalContainer(xmlui_manager.VerticalContainer, Container):
-    type = u'vertical'
+    type = u"vertical"
 
 
 class PairsContainer(xmlui_manager.PairsContainer, Container):
-    type = u'pairs'
+    type = u"pairs"
 
 
 class LabelContainer(xmlui_manager.PairsContainer, Container):
-    type = u'label'
+    type = u"label"
 
     def show(self):
         for child in self.children:
             no_lf = False
             # we check linked widget type
             # to see if we want the label on the same line or not
-            if child.type == u'label':
+            if child.type == u"label":
                 for_name = child.for_name
                 if for_name is not None:
                     for_widget = self.root.widgets[for_name]
                     wid_type = for_widget.type
-                    if self.root.values_only or wid_type in ('text', 'string', 'jid_input'):
+                    if self.root.values_only or wid_type in (
+                        "text",
+                        "string",
+                        "jid_input",
+                    ):
                         no_lf = True
-                    elif wid_type == 'bool' and for_widget.read_only:
+                    elif wid_type == "bool" and for_widget.read_only:
                         no_lf = True
                 child.show(no_lf=no_lf, ansi=A.FG_CYAN)
             else:
                 child.show()
 
+
 ## Dialogs ##
 
 
 class Dialog(object):
-
     def __init__(self, xmlui_parent):
         self.xmlui_parent = xmlui_parent
         self.host = self.xmlui_parent.host
@@ -369,7 +378,6 @@
 
 
 class NoteDialog(xmlui_manager.NoteDialog, Dialog):
-
     def show(self):
         # TODO: handle title and level
         self.disp(self.message)
@@ -379,11 +387,11 @@
         xmlui_manager.NoteDialog.__init__(self, _xmlui_parent)
         self.title, self.message, self.level = title, message, level
 
+
 ## Factory ##
 
 
 class WidgetFactory(object):
-
     def __getattr__(self, attr):
         if attr.startswith("create"):
             cls = globals()[attr[6:]]
@@ -398,15 +406,27 @@
     workflow = None
     _submit_cb = None
 
-    def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, ignore=None, whitelist=None, profile=None):
-        xmlui_manager.XMLUIPanel.__init__(self,
-                                          host,
-                                          parsed_dom,
-                                          title = title,
-                                          flags = flags,
-                                          ignore = ignore,
-                                          whitelist = whitelist,
-                                          profile=host.profile)
+    def __init__(
+        self,
+        host,
+        parsed_dom,
+        title=None,
+        flags=None,
+        callback=None,
+        ignore=None,
+        whitelist=None,
+        profile=None,
+    ):
+        xmlui_manager.XMLUIPanel.__init__(
+            self,
+            host,
+            parsed_dom,
+            title=title,
+            flags=flags,
+            ignore=ignore,
+            whitelist=whitelist,
+            profile=host.profile,
+        )
         self.submitted = False
 
     @property
@@ -455,7 +475,7 @@
             elif isinstance(cmd, list):
                 name, value = cmd
                 widget = self.widgets[name]
-                if widget.type == 'bool':
+                if widget.type == "bool":
                     value = C.bool(value)
                 widget.value = value
         self.show()
@@ -465,7 +485,7 @@
         self.onFormSubmitted()
 
     def onFormSubmitted(self, ignore=None):
-        # self.submitted is a Q&D workaround to avoid
+        #  self.submitted is a Q&D workaround to avoid
         # double submit when a workflow is set
         if self.submitted:
             return
@@ -478,8 +498,8 @@
     def _launchActionCb(self, data):
         XMLUIPanel._actions -= 1
         assert XMLUIPanel._actions >= 0
-        if u'xmlui' in data:
-            xmlui_raw = data['xmlui']
+        if u"xmlui" in data:
+            xmlui_raw = data["xmlui"]
             xmlui = xmlui_manager.create(self.host, xmlui_raw)
             xmlui.show()
             if xmlui.submit_id:
@@ -498,13 +518,16 @@
             data,
             self.profile,
             callback=self._launchActionCb,
-            errback=partial(self.command.errback,
-                            msg=_(u"can't launch XMLUI action: {}"),
-                            exit_code=C.EXIT_BRIDGE_ERRBACK))
+            errback=partial(
+                self.command.errback,
+                msg=_(u"can't launch XMLUI action: {}"),
+                exit_code=C.EXIT_BRIDGE_ERRBACK,
+            ),
+        )
 
 
 class XMLUIDialog(xmlui_manager.XMLUIDialog):
-    type = 'dialog'
+    type = "dialog"
     dialog_factory = WidgetFactory()
     read_only = False