示例#1
0
    def build_footer(self):
        # cancel = menu_btn(on_press=self.cancel,
        #                   label="\n  BACK\n")

        self.buttons = Columns([
            ('fixed', 2, Text("")),
            # ('fixed', 13, Color.menu_button(
            #     cancel,
            #     focus_map='button_primary focus')),
            Text(""),
            ('fixed', 40, Color.menu_button(
                self.skip_rest_button,
                focus_map='button_primary focus'
            )),
            ('fixed', 2, Text(""))
        ])

        footer = Pile([
            HR(top=0),
            Padding.center_90(self.description_w),
            Padding.line_break(""),
            Color.frame_footer(Pile([
                Padding.line_break(""),
                self.buttons]))
        ])
        return footer
    def build_footer(self):
        cancel = menu_btn(on_press=self.do_cancel,
                          label="\n  BACK\n")
        confirm = menu_btn(on_press=self.do_commit,
                           label="\n APPLY CHANGES\n")
        self.buttons = Columns([
            ('fixed', 2, Text("")),
            ('fixed', 13, Color.menu_button(
                cancel,
                focus_map='button_primary focus')),
            Text(""),
            ('fixed', 20, Color.menu_button(
                confirm,
                focus_map='button_primary focus')),
            ('fixed', 2, Text(""))
        ])

        footer = Pile([
            HR(top=0),
            Padding.center_90(self.description_w),
            Padding.line_break(""),
            Color.frame_footer(Pile([
                Padding.line_break(""),
                self.buttons]))
        ])

        return footer
示例#3
0
    def build_footer(self):
        cancel = menu_btn(on_press=self.do_cancel,
                          label="\n  BACK\n")
        self.apply_button = menu_btn(on_press=self.do_done,
                                     label="\n DONE\n")
        self.buttons = Columns([
            ('fixed', 2, Text("")),
            ('fixed', 13, Color.menu_button(
                cancel,
                focus_map='button_primary focus')),
            Text(""),
            ('fixed', 20, Color.menu_button(
                self.apply_button,
                focus_map='button_primary focus')),
            ('fixed', 2, Text(""))
        ])

        footer = Pile([
            HR(top=0),
            Padding.line_break(""),
            Color.frame_footer(Pile([
                Padding.line_break(""),
                self.buttons]))
        ])

        return footer
示例#4
0
    def generate_additional_input(self):
        """ Generates additional input fields, useful for doing it after
        a previous step is run
        """
        self.set_description(self.model.description, 'body')
        self.icon.set_text((
            'pending_icon',
            self.icon.get_text()[0]
        ))
        for i in self.additional_input:
            self.app.log.debug(i)
            self.step_pile.contents.append((Padding.line_break(""),
                                            self.step_pile.options()))
            column_input = [
                ('weight', 0.5, Padding.left(i['label'], left=5))
            ]
            if i['input']:
                column_input.append(
                    ('weight', 1, Color.string_input(
                        i['input'],
                        focus_map='string_input focus')))
            self.step_pile.contents.append(
                (Columns(column_input, dividechars=3),
                 self.step_pile.options()))

        self.button = submit_btn(label="Run", on_press=self.submit)
        self.step_pile.contents.append(
            (Padding.right_20(
                Color.button_primary(self.button,
                                     focus_map='button_primary focus')),
             self.step_pile.options()))
        self.step_pile.contents.append((HR(), self.step_pile.options()))
        self.step_pile.focus_position = self.current_button_index
示例#5
0
 def _build_widget(self):
     total_items = []
     if len(self.clouds) > 0:
         total_items.append(Text("Choose a Cloud"))
         total_items.append(HR())
         for item in self.clouds:
             total_items.append(
                 Color.body(
                     menu_btn(label=item,
                              on_press=self.submit),
                     focus_map='menu_button focus'
                 )
             )
         total_items.append(Padding.line_break(""))
     total_items.append(Text("Configure a New Cloud"))
     total_items.append(HR())
     for item in ['localhost', 'maas']:
         total_items.append(
             Color.body(
                 menu_btn(label=item,
                          on_press=self.submit),
                 focus_map='menu_button focus'
             )
         )
     return Padding.center_80(Filler(Pile(total_items), valign='top'))
    def _build_widget(self):
        total_items = []
        if len(self.controllers) > 0:
            total_items.append(HR())
            cdict = defaultdict(lambda: defaultdict(list))
            for cname, d in self.controllers.items():
                cdict[d['cloud']][d.get('region', None)].append(cname)

            for cloudname, cloud_d in sorted(cdict.items()):
                total_items.append(Color.label(
                    Text("  {}".format(cloudname))))
                for regionname, controllers in cloud_d.items():
                    for controller in sorted(controllers):
                        label = "    {}".format(controller)
                        if regionname:
                            label += " ({})".format(regionname)
                        total_items.append(
                            Color.body(
                                menu_btn(label=label,
                                         on_press=partial(self.submit,
                                                          controller)),
                                focus_map='menu_button focus'
                            )
                        )
                total_items.append(Padding.line_break(""))
            total_items.append(Padding.line_break(""))
        total_items.append(HR())
        total_items.append(
            Color.body(
                menu_btn(label="Create New",
                         on_press=self.handle_create_new),
                focus_map='menu_button focus'
            )
        )
        return Padding.center_80(Filler(Pile(total_items), valign='top'))
    def build_widgets(self, maxlen):
        num_str = "{}".format(self.application.num_units)
        col_pad = 6
        self.unit_w = Text('Units: {:4d}'.format(self.application.num_units),
                           align='right')
        cws = [
            (maxlen + col_pad,
             Text(self.application.service_name)),
            (10 + len(num_str), self.unit_w),
            # placeholder for instance type
            ('weight', 1, Text(" ")),
            # placeholder for configure button
            ('weight', 1, Text(" ")),
            (20, Color.button_primary(
                PlainButton("Deploy",
                            partial(self.deploy_cb,
                                    self.application)),
                focus_map='button_primary focus'))
        ]
        if not self.hide_config:
            cws[3] = (20, Color.button_secondary(
                PlainButton("Configure",
                            partial(self.controller.do_configure,
                                    self.application)),
                focus_map='button_secondary focus'))

        self.columns = Columns(cws, dividechars=1)
        return self.columns
示例#8
0
    def buttons(self):
        confirm = confirm_btn(on_press=self.submit)
        cancel = cancel_btn(on_press=self.cancel)

        buttons = [
            Color.button_primary(confirm, focus_map='button_primary focus'),
            Color.button_secondary(cancel, focus_map='button_secondary focus')
        ]
        return Pile(buttons)
示例#9
0
    def buttons(self):
        confirm = confirm_btn(on_press=self.submit, label="Add credential")
        cancel = back_btn(on_press=self.cancel)

        buttons = [
            Color.button_primary(confirm, focus_map='button_primary focus'),
            Color.button_secondary(cancel, focus_map='button_secondary focus')
        ]
        return Pile(buttons)
 def _build_buttons(self):
     buttons = [
         Color.button_primary(
             Button("Confirm", self.submit),
             focus_map='button_primary focus'),
         Color.button_secondary(
             Button("Cancel", self.cancel),
             focus_map='button_secondary focus')
     ]
     return Pile(buttons)
示例#11
0
    def __init__(self, app, steps, cb=None):
        """ init

        Arguments:
        cb: process step callback
        """
        self.app = app
        self.table = Table()
        self.cb = cb

        self.steps_queue = steps
        for step_model in self.steps_queue:
            step_widget = self.add_step_widget(step_model)
            self.table.addColumns(
                step_model.path,
                [
                    ('fixed', 3, step_widget['icon']),
                    step_widget['description'],
                ]
            )
            # Need to still prompt for the user to submit
            # even though no questions are asked
            if len(step_widget['additional_input']) == 0:
                self.table.addRow(
                    Padding.right_20(
                        Color.button_primary(
                            submit_btn(on_press=self.submit,
                                       user_data=(step_model, step_widget)),
                            focus_map='button_primary focus')), False)
            for i in step_widget['additional_input']:
                self.table.addRow(Padding.line_break(""), False)
                self.table.addColumns(
                    step_model.path,
                    [
                        ('weight', 0.5, Padding.left(i['label'], left=5)),
                        ('weight', 1, Color.string_input(
                            i['input'],
                            focus_map='string_input focus')),
                    ], force=True
                )
                self.table.addRow(
                    Padding.right_20(
                        Color.button_primary(
                            submit_btn(
                                on_press=self.submit,
                                user_data=(step_model, step_widget)),
                            focus_map='button_primary focus')), False)
                self.table.addRow(Padding.line_break(""), False)

        self.table.addRow(Padding.center_20(
                        Color.button_primary(
                            done_btn(on_press=self.done, label="View Summary"),
                            focus_map='button_primary focus')))
        super().__init__(Padding.center_80(self.table.render()))
示例#12
0
    def build_widgets(self):
        self.description_w = Text("Description Loading…")
        self.readme_w = Text("README Loading…")
        self.scale_edit = IntegerEditor(default=self.service.num_units)
        connect_signal(self.scale_edit._edit, 'change',
                       self.handle_scale_changed)
        self.skip_rest_button = PlainButton(
            "Deploy all {} Remaining Applications with Bundle Defaults".format(
                self.n_remaining),
            self.do_skip_rest
        )
        col = Columns(
            [
                (6, Text('Units:', align='right')),
                (15,
                 Color.string_input(self.scale_edit,
                                    focus_map='string_input focus'))
            ], dividechars=1
        )

        if self.n_remaining == 0:
            buttons = [Padding.right_50(Color.button_primary(
                PlainButton("Deploy and Continue",
                            self.do_deploy),
                focus_map='button_primary focus'))]
        else:
            buttons = [
                Padding.right_50(Color.button_primary(
                    PlainButton(
                        "Deploy and Configure Next Application",
                        self.do_deploy),
                    focus_map='button_primary focus')),
                Padding.right_50(
                    Color.button_secondary(
                        self.skip_rest_button,
                        focus_map='button_secondary focus'))]

        ws = [Text("{} of {}: {}".format(self.idx+1, self.n_total,
                                         self.service.service_name.upper())),
              Padding.center(HR()),
              Padding.center(self.description_w, left=2),
              Padding.line_break(""),
              Padding.center(self.readme_w, left=2),
              Padding.center(HR())]

        if not self.service.subordinate:
            ws.append(Padding.left(col, left=1))

        ws.append(Padding.line_break(""))
        ws += buttons

        self.pile = Pile(ws)
        return Padding.center_90(Filler(self.pile, valign="top"))
示例#13
0
    def build_widgets(self):
        desc_text = Text(["\n", strip_solo_dots(self.description)])

        self.reset_button = PlainButton("Reset to Default", self.do_reset)
        if self.optype == OptionType.BOOLEAN:
            self.control = CheckBox('', state=bool(self.current_value))
            self.wrapped_control = self.control
        elif self.optype == OptionType.INT:
            self.control = IntEdit(default=self.current_value)
            self.wrapped_control = Color.string_input(
                self.control, focus_map='string_input focus')
        elif self.optype == OptionType.STRING:
            edit_text = self.current_value or ""
            self.control = StringEditor(edit_text=edit_text)
            self.wrapped_control = Color.string_input(
                self.control, focus_map='string_input focus')
        elif self.optype == OptionType.FLOAT:
            edit_text = str(self.current_value)
            self.control = StringEditor(edit_text=edit_text)
            self.wrapped_control = Color.string_input(
                self.control, focus_map='string_input focus')
        else:
            raise Exception("Unknown option type")

        self.control_columns = Columns(
            [
                ('pack', Text("{}:".format(self.name), align='right')),
                (80, self.wrapped_control)
            ],
            dividechars=1
        )

        if self.optype in [OptionType.STRING, OptionType.FLOAT]:
            connect_signal(self.control._edit, 'change',
                           self.handle_value_changed)
        else:
            connect_signal(self.control, 'change',
                           self.handle_value_changed)

        button_grid = GridFlow([
            Color.button_secondary(self.reset_button,
                                   focus_map='button_secondary focus')],
                               36, 1, 0, 'right')

        return Pile([Padding.line_break(""),
                     Padding.left(self.control_columns, left=1),
                     Padding.left(desc_text, left=2),
                     button_grid])
    def refresh_nodes(self, nodes):
        """ Adds services to the view if they don't already exist
        """
        for node in nodes:
            services_list = []
            charm_class, service = node
            if len(service.units) > 0:
                for u in sorted(service.units, key=attrgetter('unit_name')):
                    # Refresh any state changes
                    try:
                        unit_w = self.deployed[u.unit_name]
                    except:
                        hwinfo = self._get_hardware_info(u)
                        self.deployed[u.unit_name] = UnitInfoWidget(
                            u,
                            charm_class,
                            hwinfo)
                        unit_w = self.deployed[u.unit_name]
                        for k, label, width in self.view_columns:
                            if width == 0:
                                services_list.append(getattr(unit_w, k))
                            else:
                                services_list.append(('fixed', width,
                                                      getattr(unit_w, k)))

                        self.table.addColumns(u.unit_name, services_list)
                        self.table.addColumns(
                            u.unit_name,
                            [
                                ('fixed', 5, Text("")),
                                Color.frame_subheader(unit_w.workload_info)
                            ],
                            force=True)
                    self.update_ui_state(charm_class, u,
                                         unit_w)
示例#15
0
    def build_widgets(self):
        readme_files = glob(os.path.join(app.config['spell-dir'], 'README.*'))
        if len(readme_files) == 0:
            self.readme_w = Text("No README found for bundle.")
        else:
            readme_file = readme_files[0]
            if len(readme_files) != 1:
                utils.warning("Unexpected: {} files matching README.*"
                              "- using {}".format(len(readme_files),
                                                  readme_file))
            with open(readme_file) as rf:
                rlines = [Text(l) for l in rf.readlines()]
                self.readme_w = BoxAdapter(ListBox(rlines),
                                           self.initial_height)

        ws = [Text("About {}:".format(app.config['spell'])),
              Padding.right_50(Color.button_primary(
                  PlainButton("Continue",
                              self.do_continue),
                  focus_map='button_primary focus')),
              Padding.center(HR()),
              Padding.center(self.readme_w, left=2),
              Padding.center(HR()),
              Padding.center(Text("Use arrow keys to scroll text "
                                  "and TAB to select the button."))]

        self.pile = Pile(ws)
        return Padding.center_90(Filler(self.pile, valign="top"))
示例#16
0
文件: jaas.py 项目: zhatin/conjure-up
 def add_row(label, field):
     rows.extend([
         Columns([('fixed', 23, Text(label)),
                  Color.string_input(field,
                                     focus_map='string_input focus')]),
         Padding.line_break(""),
     ])
示例#17
0
 def build_menuable_items(self):
     """ Builds a list of bundles available to install
     """
     cols = []
     for bundle in app.bundles:
         bundle_metadata = bundle['Meta']['bundle-metadata']
         try:
             conjure_data = bundle['Meta']['extra-info/conjure-up']
             name = conjure_data.get('friendly-name',
                                     bundle['Meta']['id']['Name'])
         except KeyError:
             name = bundle['Meta']['id']['Name']
         self.fname_id_map[name] = bundle
         cols.append(
             Columns(
                 [
                     ("weight", 0.2, Color.body(
                         menu_btn(label=name,
                                  on_press=self.done),
                         focus_map="menu_button focus")),
                     ("weight", 0.3, Text(
                         bundle_metadata.get('Description',
                                             'Needs a description'),
                         align="left"))
                 ],
                 dividechars=1
             )
         )
         cols.append(Padding.line_break(""))
     return Pile(cols)
示例#18
0
 def buttons(self):
     buttons = [
         Color.button_primary(
             done_btn(on_press=self.done, label="View Summary"),
             focus_map='button_primary focus')
     ]
     return Pile(buttons)
示例#19
0
    def buttons(self):
        cancel = quit_btn(on_press=self.cancel)

        buttons = [
            Color.button_secondary(cancel, focus_map='button_secondary focus')
        ]
        return Pile(buttons)
示例#20
0
    def buttons(self):
        cancel = cancel_btn(on_press=self.cancel)

        buttons = [
            Color.button_secondary(cancel, focus_map='button_secondary focus')
        ]
        return Pile(buttons)
示例#21
0
    def build_widgets(self):
        ws = [Text("{} Applications in {}:".format(len(self.applications),
                                                   app.config['spell']))]
        max_app_name_len = max([len(a.service_name) for a in
                                self.applications])

        for a in self.applications:
            ws.append(Text(""))
            ws.append(ApplicationWidget(a, max_app_name_len,
                                        self.controller,
                                        self.do_deploy))

        self.description_w = Text("App description")
        ws += [HR(), self.description_w]

        self.skip_rest_button = PlainButton(
            "Deploy all",
            self.controller.do_deploy_remaining
        )
        cws = [('weight', 1, Text(" ")),
               (20, Color.button_secondary(
                   self.skip_rest_button,
                   focus_map='button_secondary focus'))]
        self.button_columns = Columns(cws, dividechars=1)

        ws += [HR(), self.button_columns]
        self.pile = Pile(ws)
        return Padding.center_90(Filler(self.pile, valign="top"))
示例#22
0
 def _build_buttons(self):
     buttons = [
         Color.button_secondary(
             cancel_btn(label="Quit", on_press=self.cancel),
             focus_map="button_secondary focus")
     ]
     return Pile(buttons)
示例#23
0
    def refresh_nodes(self, applications):
        """Adds services to the view if they don't already exist

        Schedules UI update on main thread to avoid urwid issues with
        changing listbox state during render.
        """
        for name, service in sorted(applications.items()):
            service_w = ServiceWidget(name, service)
            for unit in service_w.Units:
                try:
                    unit_w = self.deployed[unit._name]
                except:
                    self.deployed[unit._name] = unit
                    unit_w = self.deployed[unit._name]
                    self.table.addColumns(
                        unit._name,
                        [
                            ('fixed', 3, getattr(unit_w, 'Icon')),
                            ('fixed', 50, getattr(unit_w, 'Name')),
                            ('fixed', 20, getattr(unit_w, 'AgentStatus'))
                        ]
                    )

                    if not hasattr(unit_w, 'WorkloadInfo'):
                        continue
                    self.table.addColumns(
                        unit._name,
                        [
                            ('fixed', 5, Text("")),
                            Color.info_context(
                                unit_w.WorkloadInfo)
                        ],
                        force=True)
                self.update_ui_state(unit_w, unit._unit)
示例#24
0
 def build_widget(self):
     """ Provides a rendered spell widget suitable for pile
     """
     return Color.body(menu_btn(label=self._spell['name'],
                                on_press=self.cb,
                                user_data=self._spell),
                       focus_map='menu_button focus')
示例#25
0
    def _refresh_nodes_on_main_thread(self):
        status = model_status()
        for name, service in sorted(status['applications'].items()):
            service_w = ServiceWidget(name, service)
            for unit in service_w.Units:
                try:
                    unit_w = self.deployed[unit._name]
                except:
                    self.deployed[unit._name] = unit
                    unit_w = self.deployed[unit._name]
                    self.table.addColumns(
                        unit._name,
                        [
                            ('fixed', 3, getattr(unit_w, 'Icon')),
                            ('fixed', 50, getattr(unit_w, 'Name')),
                            ('fixed', 20, getattr(unit_w, 'AgentStatus'))
                        ]
                    )

                    if not hasattr(unit_w, 'WorkloadInfo'):
                        continue
                    self.table.addColumns(
                        unit._name,
                        [
                            ('fixed', 5, Text("")),
                            Color.info_context(
                                unit_w.WorkloadInfo)
                        ],
                        force=True)
                self.update_ui_state(unit_w, unit._unit)
示例#26
0
    def refresh_nodes(self):
        """ Adds services to the view if they don't already exist
        """
        status = model_status()
        for name, service in sorted(status['applications'].items()):
            service_w = ServiceWidget(name, service)
            for unit in service_w.Units:
                services_list = []
                try:
                    unit_w = self.deployed[unit._name]
                except:
                    self.deployed[unit._name] = unit
                    unit_w = self.deployed[unit._name]
                    for k, label, width in self.view_columns:
                        if width == 0:
                            services_list.append(getattr(unit_w, k))
                        else:
                            if not hasattr(unit_w, k):
                                continue
                            services_list.append(('fixed', width,
                                                  getattr(unit_w, k)))

                    self.table.addColumns(unit._name, services_list)
                    if not hasattr(unit_w, 'WorkloadInfo'):
                        continue
                    self.table.addColumns(
                        unit._name,
                        [
                            ('fixed', 5, Text("")),
                            Color.info_context(
                                unit_w.WorkloadInfo)
                        ],
                        force=True)
                self.update_ui_state(unit_w, unit._unit)
示例#27
0
    def build_widgets(self):
        readme_files = glob(os.path.join(self.spell_dir, 'README.*'))
        if len(readme_files) == 0:
            self.readme_w = Text("No README found for bundle.")
        else:
            readme_file = readme_files[0]
            if len(readme_files) != 1:
                utils.warning("Unexpected: {} files matching README.*"
                              "- using {}".format(len(readme_files),
                                                  readme_file))
            with open(readme_file) as rf:
                rlines = [Text(l) for l in rf.readlines()]
                self.readme_w = BoxAdapter(ListBox(rlines),
                                           self.initial_height)

        ws = [
            Text("About {}:".format(self.spell_name)),
            Padding.right_50(
                Color.button_primary(PlainButton("Continue", self.do_continue),
                                     focus_map='button_primary focus')),
            Padding.center(HR()),
            Padding.center(self.readme_w, left=2),
            Padding.center(HR()),
            Padding.center(
                Text("Use arrow keys to scroll text "
                     "and TAB to select the button."))
        ]

        self.pile = Pile(ws)
        return Padding.center_90(Filler(self.pile, valign="top"))
示例#28
0
    def _build_footer(self):
        cancel = menu_btn(on_press=self.cancel, label="\n  BACK\n")
        confirm = menu_btn(on_press=self.submit, label="\n ADD CREDENTIAL\n")
        self.buttons = Columns([
            ('fixed', 2, Text("")),
            ('fixed', 13,
             Color.menu_button(cancel, focus_map='button_primary focus')),
            Text(""),
            ('fixed', 20,
             Color.menu_button(confirm, focus_map='button_primary focus')),
            ('fixed', 2, Text(""))
        ])

        footer = Color.frame_footer(
            Pile([Padding.line_break(""), self.buttons]))
        return footer
 def _build_buttons(self):
     buttons = [
         Color.button_secondary(
             cancel_btn(label="Quit", on_press=self.cancel),
             focus_map="button_secondary focus")
     ]
     return Pile(buttons)
示例#30
0
    def build_widget(self):
        self.step_pile = pile = Pile([
            Columns([
                ('fixed', 3, self.icon),
                self.description,
            ],
                    dividechars=1),
            Padding.line_break(""),
            Padding.push_4(self.output),
        ])

        if utils.is_linux() and self.model.needs_sudo:
            pile.contents.append((Padding.line_break(""), pile.options()))
            label = 'This step requires sudo.'
            if not self.app.sudo_pass:
                label += '  Enter sudo password, if needed:'
                self.sudo_input = PasswordEditor()
            columns = [
                ('weight', 0.5, Padding.left(Text(('body', label)), left=5)),
            ]
            if self.sudo_input:
                columns.append(
                    ('weight', 1,
                     Color.string_input(self.sudo_input,
                                        focus_map='string_input focus')))
            pile.contents.append((Columns(columns,
                                          dividechars=3), pile.options()))
示例#31
0
    def _build_widget(self):
        total_items = []
        if self.app.jaas_ok:
            total_items.append(HR())
            total_items.append(Color.body(
                menu_btn(
                    label='Juju-as-a-Service (JaaS) Managed Controller',
                    on_press=self.handle_jaas,
                ),
                focus_map='menu_button focus'
            ))
        if len(self.controllers) > 0:
            total_items.append(HR())
            total_items.append(Color.label(Text(
                "Existing Self-Hosted Controllers")))
            total_items.append(Padding.line_break(""))
            cdict = defaultdict(lambda: defaultdict(list))
            for cname, d in self.controllers.items():
                cdict[d['cloud']][d.get('region', None)].append(cname)

            for cloudname, cloud_d in sorted(cdict.items()):
                total_items.append(Color.label(
                    Text("  {}".format(cloudname))))
                for regionname, controllers in cloud_d.items():
                    for controller in sorted(controllers):
                        label = "    {}".format(controller)
                        if regionname:
                            label += " ({})".format(regionname)
                        total_items.append(
                            Color.body(
                                menu_btn(label=label,
                                         on_press=partial(self.submit,
                                                          controller)),
                                focus_map='menu_button focus'
                            )
                        )
                total_items.append(Padding.line_break(""))
            total_items.append(Padding.line_break(""))
        total_items.append(HR())
        total_items.append(
            Color.body(
                menu_btn(label="Deploy New Self-Hosted Controller",
                         on_press=self.handle_create_new),
                focus_map='menu_button focus'
            )
        )
        return Padding.center_80(Filler(Pile(total_items), valign='top'))
示例#32
0
 def build_widget(self):
     rows = [
         Text("Select a network bridge and storage pool "
              "for this deployment:"),
         HR(),
         Columns([('weight', 0.5, Text('network bridge', align="right")),
                  Color.string_input(self.lxd_config['network'],
                                     focus_map='string_input focus')],
                 dividechars=1),
         HR(),
         Columns([('weight', 0.5, Text('storage pool', align="right")),
                  Color.string_input(self.lxd_config['storage-pool'],
                                     focus_map='string_input focus')],
                 dividechars=1),
     ]
     self.pile = Pile(rows)
     return self.pile
示例#33
0
文件: cloud.py 项目: mnama/conjure-up
 def _build_widget(self):
     total_items = []
     if len(self.clouds) > 0:
         total_items.append(Text("Choose a Cloud"))
         total_items.append(HR())
         for item in self.clouds:
             total_items.append(
                 Color.body(menu_btn(label=item, on_press=self.submit),
                            focus_map='menu_button focus'))
         total_items.append(Padding.line_break(""))
     total_items.append(Text("Configure a New Cloud"))
     total_items.append(HR())
     for item in ['localhost', 'maas']:
         total_items.append(
             Color.body(menu_btn(label=item, on_press=self.submit),
                        focus_map='menu_button focus'))
     return Padding.center_80(Filler(Pile(total_items), valign='top'))
示例#34
0
    def generate_additional_input(self):
        """ Generates additional input fields, useful for doing it after
        a previous step is run
        """
        self.set_description(self.model.description, 'body')
        self.icon.set_text(('pending_icon', self.icon.get_text()[0]))
        if utils.is_linux() and self.model.needs_sudo:
            self.step_pile.contents.append(
                (Padding.line_break(""), self.step_pile.options()))
            can_sudo = utils.can_sudo()
            label = 'This step requires sudo.'
            if not can_sudo:
                label += '  Please enter sudo password:'******'weight', 0.5, Padding.left(Text(('body', label)), left=5)),
            ]
            if not can_sudo:
                self.sudo_input = PasswordEditor()
                columns.append(
                    ('weight', 1,
                     Color.string_input(self.sudo_input,
                                        focus_map='string_input focus')))
            self.step_pile.contents.append(
                (Columns(columns, dividechars=3), self.step_pile.options()))

        for i in self.additional_input:
            self.app.log.debug(i)
            self.step_pile.contents.append(
                (Padding.line_break(""), self.step_pile.options()))
            column_input = [('weight', 0.5, Padding.left(i['label'], left=5))]
            if i['input']:
                column_input.append(
                    ('weight', 1,
                     Color.string_input(i['input'],
                                        focus_map='string_input focus')))
            self.step_pile.contents.append(
                (Columns(column_input,
                         dividechars=3), self.step_pile.options()))

        self.button = submit_btn(label="Run", on_press=self.submit)
        self.step_pile.contents.append(
            (Padding.line_break(""), self.step_pile.options()))
        self.step_pile.contents.append((Text(""), self.step_pile.options()))
        self.step_pile.contents.append((HR(), self.step_pile.options()))
        self.show_button()
        self.step_pile.focus_position = self.current_button_index
示例#35
0
 def _build_buttons(self):
     cancel = quit_btn(on_press=self.cancel)
     buttons = [
         Padding.line_break(""),
         Color.button_secondary(cancel,
                                focus_map='button_secondary focus'),
     ]
     return Pile(buttons)
示例#36
0
 def _build_footer(self):
     footer_pile = Pile([
         Padding.line_break(""),
         Color.frame_footer(
             Columns([('fixed', 2, Text("")),
                      ('fixed', 13, self._build_buttons())]))
     ])
     return footer_pile
示例#37
0
 def _build_buttons(self):
     cancel = menu_btn(on_press=self.cancel, label="\n  QUIT\n")
     buttons = [
         Padding.line_break(""),
         Color.menu_button(cancel, focus_map='button_primary focus'),
     ]
     self.buttons_pile = Pile(buttons)
     return self.buttons_pile
示例#38
0
 def build_widget(self):
     total_items = []
     label_width = max(
         len(f.label or f.key) for f in app.provider.form.fields()) + 2
     for field in app.provider.form.fields():
         label = field.label or field.key
         total_items.extend([
             Columns([(label_width, Text(label, align='right')),
                      Color.string_input(field.widget,
                                         focus_map='string_input focus')],
                     dividechars=1),
             Columns([(label_width, Text("")),
                      Color.error_major(field.error)],
                     dividechars=1),
             Padding.line_break(""),
         ])
     return total_items
示例#39
0
    def button(self, label, callback):
        """ Build a button for the footer with the given label and callback.

        """
        return ('fixed', len(label) + 8,
                Color.menu_button(menu_btn(on_press=callback,
                                           label="\n  {}\n".format(label)),
                                  focus_map='button_primary focus'))
示例#40
0
    def build_widgets(self):
        desc_text = Text(["\n", strip_solo_dots(self.description)])

        self.reset_button = PlainButton("Reset to Default", self.do_reset)
        if self.optype == OptionType.BOOLEAN:
            self.control = CheckBox('', state=bool(self.current_value))
            self.wrapped_control = self.control
        elif self.optype == OptionType.INT:
            self.control = IntEdit(default=self.current_value)
            self.wrapped_control = Color.string_input(
                self.control, focus_map='string_input focus')
        elif self.optype == OptionType.STRING:
            edit_text = self.current_value or ""
            self.control = StringEditor(edit_text=edit_text)
            self.wrapped_control = Color.string_input(
                self.control, focus_map='string_input focus')
        elif self.optype == OptionType.FLOAT:
            edit_text = str(self.current_value)
            self.control = StringEditor(edit_text=edit_text)
            self.wrapped_control = Color.string_input(
                self.control, focus_map='string_input focus')
        else:
            raise Exception("Unknown option type")

        self.control_columns = Columns(
            [('pack', Text("{}:".format(self.name), align='right')),
             (80, self.wrapped_control)],
            dividechars=1)

        if self.optype in [OptionType.STRING, OptionType.FLOAT]:
            connect_signal(self.control._edit, 'change',
                           self.handle_value_changed)
        else:
            connect_signal(self.control, 'change', self.handle_value_changed)

        button_grid = GridFlow([
            Color.button_secondary(self.reset_button,
                                   focus_map='button_secondary focus')
        ], 36, 1, 0, 'right')

        return Pile([
            Padding.line_break(""),
            Padding.left(self.control_columns, left=1),
            Padding.left(desc_text, left=2), button_grid
        ])
示例#41
0
    def _build_widget(self):
        if len(self.public_clouds) > 0:
            self._add_item(Text("Public Clouds"))
            self._add_item(HR())
            for item in self.public_clouds:
                self._add_item(
                    Color.body(menu_btn(label=item, on_press=self.submit),
                               focus_map='menu_button focus'))
            self._add_item(Padding.line_break(""))
        if len(self.custom_clouds) > 0:
            self._add_item(Text("Your Clouds"))
            self._add_item(HR())
            for item in self.custom_clouds:
                self._add_item(
                    Color.body(menu_btn(label=item, on_press=self.submit),
                               focus_map='menu_button focus'))
            self._add_item(Padding.line_break(""))
        new_clouds = juju.get_compatible_clouds(
            ['localhost', 'maas', 'vsphere'])
        if new_clouds:
            self._add_item(Text("Configure a New Cloud"))
            self._add_item(HR())
            for item in sorted(new_clouds):
                if item == 'localhost':
                    self._add_item(
                        Color.info_context(menu_btn(
                            label=cloud_types.LOCALHOST, on_press=None),
                                           focus_map='disabled_button'))
                    self._add_item(
                        Color.info_context(
                            Padding.center_90(
                                Text("LXD not found, please install and wait "
                                     "for this message to disappear:\n\n"
                                     "  $ sudo snap install lxd\n"
                                     "  $ /snap/bin/lxd init --auto\n"
                                     "  $ /snap/bin/lxc network create lxdbr0 "
                                     "ipv4.address=auto ipv4.nat=true "
                                     "ipv6.address=none ipv6.nat=false "))))
                else:
                    self._add_item(
                        Color.body(menu_btn(label=item, on_press=self.submit),
                                   focus_map='menu_button focus'))

        self.pile.focus_position = 2
        return self.pile
示例#42
0
 def _enable_localhost_widget(self):
     """ Sets the proper widget for localhost availability
     """
     idx = self._get_localhost_widget_idx()
     widget = Color.body(menu_btn(label=cloud_types.LOCALHOST,
                                  on_press=self.submit),
                         focus_map='menu_button focus')
     self._update_pile_at_idx(idx, widget)
     del self.pile.contents[idx + 1]
示例#43
0
 def __init__(self,
              name,
              cb,
              enabled=True,
              enabled_msg=None,
              disabled_msg=None):
     self.name = name
     self._enabled_widget = Color.body(menu_btn(label=self.name,
                                                on_press=cb),
                                       focus_map='menu_button focus')
     self._disabled_widget = Color.info_context(menu_btn(label=name,
                                                         on_press=None),
                                                focus_map='disabled_button')
     self.enabled_msg = enabled_msg or self.default_enabled_msg
     self.disabled_msg = disabled_msg or self.default_disabled_msg
     self._enabled = enabled
     super().__init__(
         self._enabled_widget if enabled else self._disabled_widget)
示例#44
0
    def __init__(self, app):
        self.app = app
        self.deployed = {}
        self.unit_w = None
        self.table = Table()

        headings = []
        for key, label, width in self.view_columns:
            # If no width assume ('weight', 1, widget)
            if width == 0:
                headings.append(Color.column_header(Text(label)))
            else:
                headings.append(
                    ('fixed', width, Color.column_header(Text(label))))
        self.table.addHeadings(headings)
        super().__init__(self.table.render())

        self.refresh_nodes()
示例#45
0
    def __init__(self, app):
        self.app = app
        self.deployed = {}
        self.unit_w = None
        self.table = Table()

        headings = []
        for key, label, width in self.view_columns:
            # If no width assume ('weight', 1, widget)
            if width == 0:
                headings.append(Color.column_header(Text(label)))
            else:
                headings.append(
                    ('fixed', width, Color.column_header(Text(label))))
        self.table.addHeadings(headings)
        super().__init__(self.table.render())

        self.refresh_nodes()
示例#46
0
 def _build_footer(self):
     footer_pile = Pile([
         Padding.center_90(HR()),
         Color.body(
             BoxAdapter(
                 Filler(Columns([
                     Text(''),
                     ('pack', self.message),
                     Text(''),
                 ]),
                        valign='bottom'), 7)),
         Padding.line_break(""),
         Color.frame_footer(
             Columns([('fixed', 2, Text("")),
                      ('fixed', 13, self._build_buttons())])),
     ])
     self.update_message()
     return footer_pile
示例#47
0
def HR(top=1, bottom=1):
    """ Returns a horiztonal divider

    Arguments:
    top: padding top
    bottom: padding bottom
    """
    return Color.divider_line(
        Divider("\N{BOX DRAWINGS LIGHT HORIZONTAL}", top, bottom))
示例#48
0
 def _build_footer(self):
     self.spell_description = Text("")
     footer_pile = Pile(
         [
             Padding.center_60(self.spell_description),
             Padding.line_break(""),
             Color.frame_footer(Columns([("fixed", 2, Text("")), ("fixed", 13, self._build_buttons())])),
         ]
     )
     return footer_pile
示例#49
0
 def _build_buttons(self):
     cancel = menu_btn(on_press=self.cancel,
                       label="\n  QUIT\n")
     buttons = [
         Padding.line_break(""),
         Color.menu_button(cancel,
                           focus_map='button_primary focus'),
     ]
     self.buttons_pile = Pile(buttons)
     return self.buttons_pile
示例#50
0
 def _build_widget(self):
     rows = [
         Columns([('fixed', 23, self.field_labels), self.fields]),
     ]
     if self.error:
         rows.extend([
             Padding.line_break(""),
             Color.error_major(Text(" {}".format(self.error))),
         ])
     return Padding.center_60(Filler(Pile(rows), valign='top'))
示例#51
0
 def _build_footer(self):
     footer_pile = Pile([
         Padding.line_break(""),
         Color.frame_footer(
             Columns([
                 ('fixed', 2, Text("")),
                 ('fixed', 13, self._build_buttons())
             ]))
     ])
     return footer_pile
示例#52
0
 def _build_footer(self):
     self.spell_description = Text("")
     footer_pile = Pile([
         Padding.center_60(self.spell_description),
         Padding.line_break(""),
         Color.frame_footer(
             Columns([('fixed', 2, Text("")),
                      ('fixed', 13, self._build_buttons())]))
     ])
     return footer_pile
示例#53
0
    def _build_widget(self):
        if len(self.public_clouds) > 0:
            self._add_item(Text("Public Clouds"))
            self._add_item(HR())
            for item in self.public_clouds:
                self._add_item(
                    Color.body(menu_btn(label=item, on_press=self.submit),
                               focus_map='menu_button focus'))
            self._add_item(Padding.line_break(""))
        if len(self.custom_clouds) > 0:
            self._add_item(Text("Your Clouds"))
            self._add_item(HR())
            for item in self.custom_clouds:
                self._add_item(
                    Color.body(menu_btn(label=item, on_press=self.submit),
                               focus_map='menu_button focus'))
            self._add_item(Padding.line_break(""))
        new_clouds = juju.get_compatible_clouds(
            ['localhost', 'maas', 'vsphere'])
        if new_clouds:
            self._add_item(Text("Configure a New Cloud"))
            self._add_item(HR())
            for item in sorted(new_clouds):
                if item == 'localhost':
                    self._add_item(
                        Color.info_context(menu_btn(
                            label=cloud_types.LOCALHOST, on_press=None),
                                           focus_map='disabled_button'))
                    self._add_item(
                        Color.info_context(
                            Padding.center_90(
                                Text("LXD not found, please install with "
                                     "`sudo snap install lxd && lxd init` "
                                     "and wait for this message to disappear.")
                            )))
                else:
                    self._add_item(
                        Color.body(menu_btn(label=item, on_press=self.submit),
                                   focus_map='menu_button focus'))

        self.pile.focus_position = 2
        return self.pile
示例#54
0
 def _build_widget(self):
     total_items = []
     clouds = [x for x in self.clouds if 'localhost' != x]
     if len(clouds) > 0:
         total_items.append(Text("Choose a Cloud"))
         total_items.append(HR())
         for item in clouds:
             total_items.append(
                 Color.body(menu_btn(label=item, on_press=self.submit),
                            focus_map='menu_button focus'))
         total_items.append(Padding.line_break(""))
     # TODO: add vsphere
     new_clouds = juju.get_compatible_clouds(['localhost', 'maas'])
     if new_clouds:
         total_items.append(Text("Configure a New Cloud"))
         total_items.append(HR())
         for item in new_clouds:
             total_items.append(
                 Color.body(menu_btn(label=item, on_press=self.submit),
                            focus_map='menu_button focus'))
     return Padding.center_80(Filler(Pile(total_items), valign='top'))
示例#55
0
 def build_widget(self):
     return [
         Text("Select primary/external network, "
              "and datastore for this deployment:"),
         HR(),
         Columns([(29, Text('Primary Network', align="right")),
                  Color.string_input(self.vsphere_config['primary-network'],
                                     focus_map='string_input focus')],
                 dividechars=1),
         HR(),
         Columns(
             [(29, Text('External Network (optional)', align="right")),
              Color.string_input(self.vsphere_config['external-network'],
                                 focus_map='string_input focus')],
             dividechars=1),
         HR(),
         Columns([(29, Text('Datastore', align="right")),
                  Color.string_input(self.vsphere_config['datastore'],
                                     focus_map='string_input focus')],
                 dividechars=1)
     ]
示例#56
0
    def build_footer(self):
        cancel = menu_btn(on_press=self.do_cancel, label="\n  BACK\n")
        confirm = menu_btn(on_press=self.do_commit, label="\n APPLY CHANGES\n")
        self.buttons = Columns([
            ('fixed', 2, Text("")),
            ('fixed', 13,
             Color.menu_button(cancel, focus_map='button_primary focus')),
            Text(""),
            ('fixed', 20,
             Color.menu_button(confirm, focus_map='button_primary focus')),
            ('fixed', 2, Text(""))
        ])

        footer = Pile([
            HR(top=0),
            Padding.center_90(self.description_w),
            Padding.line_break(""),
            Color.frame_footer(Pile([Padding.line_break(""), self.buttons]))
        ])

        return footer
    def __init__(self, nodes, juju_state, maas_state, config):
        self.deployed = {}
        self.nodes = [] if nodes is None else nodes
        self.juju_state = juju_state
        self.maas_state = maas_state
        self.config = config
        self.unit_w = None
        self.log_cache = None
        self.table = Table()

        headings = []
        for key, label, width in self.view_columns:
            # If no width assume ('weight', 1, widget)
            if width == 0:
                headings.append(Color.column_header(Text(label)))
            else:
                headings.append(
                    ('fixed', width, Color.column_header(Text(label))))
        self.table.addHeadings(headings)
        super().__init__(self.table.render())

        self.refresh_nodes(self.nodes)
示例#58
0
    def _build_footer(self):
        cancel = menu_btn(on_press=self.cancel,
                          label="\n  BACK\n")
        confirm = menu_btn(on_press=self.submit,
                           label="\n ADD CREDENTIAL\n")
        self.buttons = Columns([
            ('fixed', 2, Text("")),
            ('fixed', 13, Color.menu_button(
                cancel,
                focus_map='button_primary focus')),
            Text(""),
            ('fixed', 20, Color.menu_button(
                confirm,
                focus_map='button_primary focus')),
            ('fixed', 2, Text(""))
        ])

        footer = Color.frame_footer(Pile([
            Padding.line_break(""),
            self.buttons
        ]))
        return footer
示例#59
0
    def validate(self):
        """ Will provide an error text if any fields are blank
        """
        values = [i.value for i in self.input_items.values()
                  if isinstance(i, StringEditor)]

        if None in values:
            self.pile.contents[-1] = (
                Padding.center_60(
                    Color.error_major(
                        Text("Please fill all required fields."))),
                self.pile.options())
            return False
        return True