示例#1
0
    def screenUI(cls,
                 modobj,
                 header_text,
                 fields,
                 defaults,
                 show_all_buttons=False,
                 buttons_visible=True):

        log.debug("Preparing screen UI for %s", modobj.name)

        # Define text labels, text fields, and buttons first
        listbox_content = cls._get_header_content(header_text)

        edits = cls.setup_widgets(modobj.parent.footer, fields, defaults)

        listbox_content.append(blank)
        listbox_content.extend(edits)
        listbox_content.append(blank)

        # Wrap buttons into Columns so it doesn't expand and look ugly
        if buttons_visible:
            listbox_content.append(
                cls._get_check_column(modobj, show_all_buttons))

        # Add everything into a ListBox and return it
        listwalker = widget.TabbedListWalker(listbox_content)
        screen = urwid.ListBox(listwalker)
        modobj.edits = edits
        modobj.walker = listwalker
        modobj.listbox_content = listbox_content
        return screen
示例#2
0
    def screenUI(cls,
                 modobj,
                 headertext,
                 fields,
                 defaults,
                 showallbuttons=False,
                 buttons_visible=True):

        log.debug("Preparing screen UI for %s" % modobj.name)
        #Define text labels, text fields, and buttons first
        header_content = []
        for text in headertext:
            if isinstance(text, str):
                header_content.append(urwid.Text(text))
            else:
                header_content.append(text)

        edits = []
        toolbar = modobj.parent.footer
        for key in fields:
            #Example: key = hostname, label = Hostname, value = fuel-pm
            if key == "blank":
                edits.append(blank)
            elif defaults[key]["value"] == "radio":
                label = widget.TextLabel(defaults[key]["label"])
                if "choices" in defaults[key]:
                    choices_list = defaults[key]["choices"]
                else:
                    choices_list = ["Yes", "No"]
                choices = widget.ChoicesGroup(choices_list,
                                              default_value="Yes",
                                              fn=modobj.radioSelect)
                columns = widget.Columns([('weight', 2, label),
                                          ('weight', 3, choices)])
                #Attach choices rb_group so we can use it later
                columns.rb_group = choices.rb_group
                edits.append(columns)
            elif defaults[key]["value"] == "label":
                edits.append(widget.TextLabel(defaults[key]["label"]))
            else:
                ispassword = "******" in key.upper()
                caption = defaults[key]["label"]
                default = defaults[key]["value"]
                tooltip = defaults[key]["tooltip"]
                edits.append(
                    widget.TextField(key,
                                     caption,
                                     23,
                                     default,
                                     tooltip,
                                     toolbar,
                                     ispassword=ispassword))

        listbox_content = []
        listbox_content.extend(header_content)
        listbox_content.append(blank)
        listbox_content.extend(edits)
        listbox_content.append(blank)

        #Wrap buttons into Columns so it doesn't expand and look ugly
        if buttons_visible:
            #Button to check
            button_check = widget.Button("Check", modobj.check)
            #Button to revert to previously saved settings
            button_cancel = widget.Button("Cancel", modobj.cancel)
            #Button to apply (and check again)
            button_apply = widget.Button("Apply", modobj.apply)

            if modobj.parent.globalsave and showallbuttons is False:
                check_col = widget.Columns([button_check])
            else:
                check_col = widget.Columns([
                    button_check, button_cancel, button_apply,
                    ('weight', 2, blank)
                ])
            listbox_content.append(check_col)

        #Add everything into a ListBox and return it
        listwalker = widget.TabbedListWalker(listbox_content)
        screen = urwid.ListBox(listwalker)
        modobj.edits = edits
        modobj.walker = listwalker
        modobj.listbox_content = listbox_content
        return screen