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_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()))
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 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(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
def _build_footer(self): def _pack(btn): return ('fixed', len(btn.label) + 4, btn) buttons = [] buttons.append(('fixed', 2, Text(""))) buttons.append(_pack(self.button('QUIT', app.ui.quit))) if self.show_back_button: buttons.append(_pack(self.button('BACK', self.prev_screen))) buttons.append(('weight', 2, Text(""))) buttons.extend([_pack(btn) for btn in self.build_buttons()]) buttons.append(('fixed', 2, Text(""))) self.button_row = Columns(buttons, 2) self.footer_msg = Text(self.footer) footer_widget = Columns([ Text(''), ('pack', self.footer_msg), Text(''), ]) footer_widget = Padding.center_90(self.footer_msg) if self.footer_height != 'auto': footer_widget = BoxAdapter(Filler(footer_widget, valign='bottom'), self.footer_height) footer = Pile([ Padding.center_90(HR()), Color.body(footer_widget), Padding.line_break(""), Color.frame_footer( Pile([ Padding.line_break(""), self.button_row, ])), ]) 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
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
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
def build_widget(self): widget = MenuSelectButtonList() if self.app.jaas_ok: widget.append_option('Juju-as-a-Service (JaaS) ' 'Free Controller', 'jaas') if len(self.controllers) > 0: if self.app.jaas_ok: widget.append(HR()) widget.append(Color.label( Text("Existing Self-Hosted Controllers"))) widget.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, d)) for cloudname, cloud_d in sorted(cdict.items()): widget.append(Color.label(Text(" {}".format(cloudname)))) for regionname, controllers in cloud_d.items(): for controller_name, controller in sorted(controllers): label = " {}".format(controller_name) if regionname: label += " ({})".format(regionname) widget.append_option( label, controller_name, enabled=controller.get('api-endpoints')) widget.append(Padding.line_break("")) widget.append(Padding.line_break("")) widget.append(HR()) widget.append_option("Deploy New Self-Hosted Controller", None) widget.select_first() return widget
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.public_clouds) > 0: total_items.append(Text("Public Clouds")) total_items.append(HR()) for item in self.public_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("")) if len(self.custom_clouds) > 0: total_items.append(Text("Your Clouds")) total_items.append(HR()) for item in self.custom_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("")) new_clouds = juju.get_compatible_clouds( ['localhost', 'maas', 'vsphere']) if new_clouds: total_items.append(Text("Configure a New Cloud")) total_items.append(HR()) for item in sorted(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'))
def _build_widget(self): total_items = [] for controller in sorted(self.controllers): models = self.models[controller]['models'] if len(models) > 0: total_items.append( Color.label( Text("{} ({})".format(controller, models[0].get('cloud', ""))))) for model in sorted(models, key=itemgetter('name')): if model['name'] == "controller": continue if model['life'] == 'dying': continue label = " {}, Machine Count: {}{}".format( model['name'], self._total_machines(model), ", Running since: {}".format( model['status'].get('since')) if 'since' in model['status'] else '') total_items.append( Color.body(menu_btn(label=label, on_press=partial( self.submit, controller, model)), focus_map='menu_button focus')) total_items.append(Padding.line_break("")) total_items.append(Padding.line_break("")) return Padding.center_80(Filler(Pile(total_items), valign='top'))
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") self.apply_button = menu_btn(on_press=self.do_commit, label="\n APPLY\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.center_90(self.description_w), Padding.line_break(""), Color.frame_footer(Pile([ Padding.line_break(""), self.buttons])) ]) return footer
def _build_field_labels(self): return Pile([ Text("Email:"), Padding.line_break(""), Text("Password:"******""), Text("Two-Factor Auth (2FA):") ])
def __init__(self, app, results, cb): self.app = app self.results = results self.cb = cb self.result_pile = [Padding.line_break("")] self.result_pile += [ Padding.center_90(s) for s in self.build_results() ] super().__init__(Filler(Pile(self.result_pile), valign="top"))
def __init__(self, app, cb): self.app = app self.text = Text("deploying...") _pile = [ Padding.center_79(self.text), Padding.line_break(""), Padding.center_20(self.buttons()) ] super().__init__(Filler(Pile(_pile), valign="middle"))
def __init__(self, app, results, cb): self.app = app self.results = results self.cb = cb self.result_pile = [Padding.line_break("")] self.result_pile += [ Padding.center_90(s) for s in self.build_results() ] super().__init__(ListBox(self.result_pile))
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
def __init__(self, common, provider, cb): self.common = common self.provider = provider self.text = Text(self.provider.to_yaml()) _pile = [ Padding.center_79(self.text), Padding.line_break(""), Padding.center_20(self.buttons()) ] super().__init__(Filler(Pile(_pile), valign="middle"))
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'))
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
def __init__(self): message = "Conjure-up is shutting down, please wait." box = Padding.center_45( LineBox( Pile([ Padding.line_break(""), Text(message, align="center"), Padding.line_break(""), ]))) super().__init__(Filler(box, valign="middle"))
def build_widget(self): return Pile([ Columns([ ('fixed', 3, self.icon), self.description, ], dividechars=1), Padding.line_break(""), Padding.push_4(self.output) ])
def __init__(self, app, results, cb): self.app = app self.results = results self.cb = cb self.result_pile = [ Padding.line_break("") ] self.result_pile += [Padding.center_90(s) for s in self.build_results()] super().__init__(Filler(Pile(self.result_pile), valign="top"))
def _build_widget(self): default_selection = None cloud_types_by_name = juju.get_cloud_types_by_name() if len(self.public_clouds) > 0: self._add_item(Text("Public Clouds")) self._add_item(HR()) for cloud_name in self.public_clouds: cloud_type = cloud_types_by_name[cloud_name] allowed = cloud_type in self.compatible_cloud_types if allowed and default_selection is None: default_selection = len(self.items.contents) self._add_item( CloudWidget(name=cloud_name, cb=self.submit, enabled=allowed)) self._add_item(Padding.line_break("")) if len(self.custom_clouds) > 0: self._add_item(Text("Your Clouds")) self._add_item(HR()) for cloud_name in self.custom_clouds: cloud_type = cloud_types_by_name[cloud_name] allowed = cloud_type in self.compatible_cloud_types if allowed and default_selection is None: default_selection = len(self.items.contents) self._add_item( CloudWidget(name=cloud_name, cb=self.submit, enabled=allowed)) self._add_item(Padding.line_break("")) new_clouds = juju.get_compatible_clouds(CUSTOM_PROVIDERS) if new_clouds: lxd_allowed = cloud_types.LOCALHOST in self.compatible_cloud_types self._add_item(Text("Configure a New Cloud")) self._add_item(HR()) for cloud_type in sorted(CUSTOM_PROVIDERS): if cloud_type == cloud_types.LOCALHOST and lxd_allowed: self._items_localhost_idx = len(self.items.contents) if default_selection is None: default_selection = len(self.items.contents) self._add_item( CloudWidget(name=cloud_type, cb=self.submit, enabled=events.LXDAvailable.is_set(), disabled_msg=self.lxd_unavailable_msg)) else: allowed = cloud_type in self.compatible_cloud_types if allowed and default_selection is None: default_selection = len(self.items.contents) self._add_item( CloudWidget(name=cloud_type, cb=self.submit, enabled=allowed)) self.items.focus_position = default_selection or 2 return self.items
def __init__(self, common, cb): self.common = common self.cb = cb _pile = [ Padding.center_90(Text("Choose a solution to get started:")), Padding.center_90(Divider("\N{BOX DRAWINGS LIGHT HORIZONTAL}")), Padding.center_90(self.build_menuable_items()), Padding.line_break(""), Padding.center_20(self.buttons()) ] super().__init__(ListBox(_pile))
def __init__(self, cb): self.cb = cb self.fname_id_map = {} self.current_focus = 2 _pile = [ Padding.line_break(""), Padding.center_90(self.build_menuable_items()), Padding.line_break(""), Padding.center_20(self.buttons()) ] super().__init__(Filler(Pile(_pile), valign="top"))
def build_widget(self): widget = MenuSelectButtonList() cloud_types_by_name = juju.get_cloud_types_by_name() if len(self.public_clouds) > 0: widget.append(Text("Public Clouds")) widget.append(HR()) for cloud_name in self.public_clouds: cloud_type = cloud_types_by_name[cloud_name] allowed = cloud_type in self.compatible_cloud_types widget.append_option(cloud_name, enabled=allowed) widget.append(Padding.line_break("")) if len(self.custom_clouds) > 0: widget.append(Text("Your Clouds")) widget.append(HR()) for cloud_name in self.custom_clouds: cloud_type = cloud_types_by_name[cloud_name] allowed = cloud_type in self.compatible_cloud_types widget.append_option(cloud_name, enabled=allowed) widget.append(Padding.line_break("")) lxd_allowed = cloud_types.LOCALHOST in self.compatible_cloud_types widget.append(Text("Configure a New Cloud")) widget.append(HR()) for cloud_type in sorted(CUSTOM_PROVIDERS): if cloud_type == cloud_types.LOCALHOST and lxd_allowed: self._items_localhost_idx = len(widget.contents) widget.append_option(cloud_type, enabled=events.LXDAvailable.is_set(), user_data={ 'disabled_msg': self.lxd_unavailable_msg, }) else: allowed = cloud_type in self.compatible_cloud_types widget.append_option(cloud_type, enabled=allowed) if app.provider and app.provider.cloud: widget.select_item_by_value(app.provider.cloud) elif app.metadata.cloud_whitelist: # whitelist is cloud types, widget is cloud names # (except for new clouds) whitelist = app.metadata.cloud_whitelist values = {opt.value for opt in widget.option_widgets} whitelisted_values = { value for value in values if value in whitelist or cloud_types_by_name.get(value) in whitelist } widget.select_first_of_values(whitelisted_values) else: widget.select_first() return widget
def __init__(self, app, msg, cb): self.app = app self.msg = msg self.cb = cb _pile = [ Padding.center_60(Instruction("LXD Configuration is required")), Padding.center_60(HR()), Padding.center_60(self.build_info()), Padding.line_break(""), Padding.center_20(self.buttons()) ] super().__init__(Filler(Pile(_pile), valign="middle"))
def _build_form_fields(self): """ Generates widgets for additional input fields. """ form_fields = [] self.fields = [] for i in self.model.additional_input: label = i['label'] key = i['key'] if i['type'] not in self.INPUT_TYPES: self.app.log.error('Invalid input type "{}" in step {}; ' 'should be one of: {}'.format( i['type'], self.model.title, ', '.join(self.INPUT_TYPES.keys()))) field = None else: input_type = self.INPUT_TYPES[i['type']] value = self.app.steps_data[self.model.name][key] if issubclass(input_type, RadioList): select_w = input_type([choice for choice in i['choices']]) select_w.select_option(i['default']) field = StepField(key, label, select_w, i['type']) else: field = StepField(key, label, input_type(default=value), i['type']) self.fields.append(field) column_input = [('weight', 0.5, Padding.left(field.label_widget, left=5))] if field: column_input.append( ('weight', 1, Color.string_input(field.input, focus_map='string_input focus'))) form_fields.extend([ Padding.line_break(""), Columns(column_input, dividechars=3), ]) self.button = SubmitButton(label="Next", on_press=self.submit) self.requires_input = self.sudo_input or self.fields form_fields.extend([ Padding.line_break(""), self.button if self.requires_input else Text(""), HR(), ]) if self.requires_input: self.complete.clear() else: self.complete.set() return form_fields
def _build_widget(self): total_items = [Padding.center_60(HR())] for spell in self.spells: total_items.append( Padding.center_60( Color.body(menu_btn(label=spell['name'], on_press=self.submit, user_data=spell), focus_map='menu_button focus'))) total_items.append(Padding.center_60(HR())) total_items.append(Padding.center_20(self._build_buttons())) return Filler(Pile(total_items), valign='top')
def _build_fields(self): self.email = Edit() self.password = Edit(mask='*') self.twofa = Edit() # can't use IntEdit because it precludes leading zeros self.twofa.valid_char = lambda ch: ch in '0123456789' return Pile([ Color.string_input(self.email), Padding.line_break(""), Color.string_input(self.password), Padding.line_break(""), Color.string_input(self.twofa) ])
def _build_footer(self): return Pile([ Padding.center_60( Text('Enter your Ubuntu SSO (Launchpad) email address and ' 'password. If you have Two-Factor Authentication (2FA) ' 'enabled, enter that as well, otherwise leave that field ' 'blank. For more information about 2FA, see: ' 'https://help.ubuntu.com/community/SSO/FAQs/2FA')), Padding.line_break(""), Color.frame_footer(Pile([ Padding.line_break(""), self.buttons, ])), ])
def __init__(self, app, msg, cb): self.app = app self.msg = msg self.cb = cb _pile = [ Padding.center_60(Instruction( "Please configure networking for LXD" )), Padding.center_60(HR()), Padding.center_60(self.build_info()), Padding.line_break(""), Padding.center_20(self.buttons()) ] super().__init__(Filler(Pile(_pile), valign="middle"))
def _build_widget(self): total_items = [ Padding.center_60(Instruction("Choose a Cloud")), Padding.center_60(HR()) ] for item in self.clouds: total_items.append( Padding.center_60( Color.body(menu_btn(label=item, on_press=self.submit), focus_map='menu_button focus'))) total_items.append(Padding.center_60(HR())) total_items.append(Padding.center_20(self._build_buttons())) return Filler(Pile(total_items), valign='top')
def build_fields(self): """ Generates widgets for additional input fields. """ pile_opts = self.step_pile.options() self.fields = [] for i in self.model.additional_input: label = i['label'] key = i['key'] if i['type'] not in self.INPUT_TYPES: self.app.log.error('Invalid input type "{}" in step {}; ' 'should be one of: {}'.format( i['type'], self.model.title, ', '.join(self.INPUT_TYPES.keys()))) field = None else: input_type = self.INPUT_TYPES[i['type']] value = self.app.steps_data[self.model.name][key] if input_type == SelectorHorizontal: select_w = input_type([choice for choice in i['choices']]) select_w.set_default(i['default'], True) field = StepField(key, label, select_w, i['type']) else: field = StepField(key, label, input_type(default=value), i['type']) self.fields.append(field) column_input = [('weight', 0.5, Padding.left(field.label_widget, left=5))] if field: column_input.append( ('weight', 1, Color.string_input(field.input, focus_map='string_input focus'))) self.step_pile.contents.extend([ (Padding.line_break(""), pile_opts), (Columns(column_input, dividechars=3), pile_opts), ]) self.button = submit_btn(label="Next", on_press=self.submit) self.step_pile.contents.extend([ (Padding.line_break(""), pile_opts), (Text(""), pile_opts), (HR(), pile_opts), ]) if self.sudo_input or self.fields: self.show_button() self.step_pile.focus_position = 4 else: self.complete.set()
def __init__(self, app, cloud, schema, cb): self.app = app self.cloud = cloud self.input_items = schema self.cb = cb _pile = [ Padding.center_60(Instruction( "Enter your {} credentials:".format(self.cloud.upper()))), Padding.center_60(HR()), Padding.center_60(self.build_inputs()), Padding.line_break(""), Padding.center_20(self.buttons()) ] super().__init__(Filler(Pile(_pile), valign="top"))
def _build_widget(self): total_items = [ Padding.center_60(Text(self.title, align="center")), Padding.center_60( Divider("\N{BOX DRAWINGS LIGHT HORIZONTAL}", 1, 1)) ] for item in self.radio_items.keys(): opt = self.radio_items[item] col = Columns([opt]) total_items.append(Padding.center_60(col)) total_items.append( Padding.center_60( Divider("\N{BOX DRAWINGS LIGHT HORIZONTAL}", 1, 1))) total_items.append(Padding.center_20(self._build_buttons())) return Filler(Pile(total_items), valign='middle')
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 build_widgets(self): controller_is_maas = app.current_cloud == 'maas' if controller_is_maas: extra = (" Press enter on a machine ID to pin it to " "a specific MAAS node.") else: extra = "" ws = [Text("Choose where to place {} unit{} of {}.{}".format( self.application.num_units, "" if self.application.num_units == 1 else "s", self.application.service_name, extra))] self.juju_machines_list = JujuMachinesList( self.application, self._machines, self.do_assign, self.do_unassign, self.add_machine, self.remove_machine, self, show_filter_box=True, show_pins=controller_is_maas) ws.append(self.juju_machines_list) self.pile = Pile(ws) return Padding.center_90(Filler(self.pile, valign="top"))
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)
def __init__(self, app, cb): self.app = app self.input_items = NETWORK self.cb = cb _pile = [ # Padding.center_60(Instruction( # "Enter LXD information:")), Padding.center_60(Instruction( "Please configure networking for LXD" )), Padding.center_60(HR()), Padding.center_60(self.build_info()), Padding.line_break(""), Padding.center_20(self.buttons()) ] super().__init__(Filler(Pile(_pile), valign="middle"))
def _build_widget(self): total_items = [HR()] total_items += [spell for spell in self.spells] total_items += [HR()] self.pile = Pile(total_items) return Padding.center_60(Filler(self.pile, valign="top"))
def __init__(self, app, steps, cb=None): """ init Arguments: cb: process step callback """ self.app = app self.cb = cb self.steps = steps self.step_pile = Pile( [Padding.center_90(HR()), Padding.line_break("")] + [Padding.center_90(s) for s in self.steps] + [Padding.line_break("")] ) super().__init__(Filler(self.step_pile, valign="top"))
def _build_node_waiting(self): """ creates a loading screen if nodes do not exist yet """ text = [Padding.line_break(""), self.message, Padding.line_break(""), self.output, Padding.line_break("")] _boxes = [] _boxes.append(('weight', 1, Text(''))) for i in self.loading_boxes: _boxes.append(('pack', i)) _boxes.append(('weight', 1, Text(''))) _boxes = Columns(_boxes) return Filler(Pile(text + [_boxes]), valign="middle")
def _build_widget(self): total_items = [ Padding.center_60(HR()) ] for spell in self.spells: total_items.append(Padding.center_60( Color.body( menu_btn(label=spell, on_press=self.submit), focus_map='menu_button focus' ) )) total_items.append( Padding.center_60(HR())) total_items.append(Padding.center_20(self._build_buttons())) return Filler(Pile(total_items), valign='top')
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)
def _build_widget(self): total_items = [ Padding.center_60(Instruction("Choose a Cloud")), Padding.center_60(HR()) ] for item in self.clouds: total_items.append(Padding.center_60( Color.body( menu_btn(label=item, on_press=self.submit), focus_map='menu_button focus' ) )) total_items.append( Padding.center_60(HR())) total_items.append(Padding.center_20(self._build_buttons())) return Filler(Pile(total_items), valign='top')
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
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
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"))
def build_info(self): items = [ Text("There was no LXD bridge found on your system " "which usually means this is your first time running " "LXD."), Padding.line_break(""), Text("If you wish to do so now pressing confirm will drop you out " "of the installer and walk you through configuring your " "network for LXD. Once complete the installer will " "start again from the beginning where you can choose " "to deploy the bundle via LXD.") ] return Pile(items)
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()))
def __init__(self, error): body = [ Padding.center_60( Text("Oops, there was a problem with your install:", align="center")), Padding.center_95( Divider("\N{BOX DRAWINGS LIGHT HORIZONTAL}", 1, 1)), Padding.center_85(Text("Reason:")), Padding.center_80(Color.error_major(Text(error))), Padding.line_break(""), Padding.line_break(""), Padding.center_95( Divider("\N{BOX DRAWINGS LIGHT HORIZONTAL}", 1, 1)), Padding.center_20(self._build_buttons()) ] super().__init__(Filler(Pile(body), valign="middle"))