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"))
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 = [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 build_widget(self): rows = [ Text("Select primary/external network, " "and datastore for this deployment:"), HR(), Columns([ ('weight', 0.5, Text('primary network', align="right")), Color.string_input( self.vsphere_config['primary-network'], focus_map='string_input focus') ], dividechars=1), HR(), Columns([ ('weight', 0.5, Text('external network (optional)', align="right")), Color.string_input( self.vsphere_config['external-network'], focus_map='string_input focus') ], dividechars=1), HR(), Columns([ ('weight', 0.5, Text('datastore', align="right")), Color.string_input( self.vsphere_config['datastore'], focus_map='string_input focus') ], dividechars=1) ] self.pile = Pile(rows) return self.pile
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_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"))
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): return [ HR(), SelectorList(self.credentials, self.select_cb), Padding.line_break(""), HR(), SelectorList(["Add a new credential"], lambda _: self.new_cb()), ]
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 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 build_widget(self): self.choices.append(HR()) for addon in sorted(app.addons.values(), key=attrgetter('name')): self.choices.append( CheckBoxValued(addon.friendly_name, value=addon.name)) self.choices.append(Padding.line_break("")) self.choices.append( Columns([('fixed', 3, Text('')), Text(addon.description)], dividechars=5)) self.choices.append(HR()) return self.choices
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"))
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_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 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
async def _build_widget(self): ws = [] if not self.application.is_subordinate: ws.append(OptionWidget("Units", "int", "How many units to deploy.", self.application.num_units, current_value=self.num_units_copy, value_changed_callback=self.handle_scale)) constraints_ow = OptionWidget( "Constraints", "string", "Set constraints on the application, ie. cores=4 mem=4G.", self.application.constraints, current_value=self.constraints_copy, value_changed_callback=self.handle_constraints) ws.append(constraints_ow) ws.append(self.constraints_error_label) ws += await self.get_whitelisted_option_widgets() self.toggle_show_all_button_index = len(ws) + 1 self.toggle_show_all_button = SecondaryButton( "Show Advanced Configuration", lambda sender: app.loop.create_task( self.do_toggle_show_all_config())) if await self.get_non_whitelisted_option_widgets(): ws += [HR(), Columns([('weight', 1, Text(" ")), (36, self.toggle_show_all_button)])] for widget in ws: self.widget.contents.append((widget, self.widget.options()))
def _gen_credentials(self): total_items = [ Text("Enter your {} credentials:".format( app.current_cloud.upper())) ] total_items += [HR()] for field in self.schema.fields(): label = field.key if field.label is not None: label = field.label col = Columns([('weight', 0.5, Text(label, align='right')), Color.string_input(field.widget, focus_map='string_input focus')], dividechars=1) total_items.append(col) total_items.append( Columns([('weight', 0.5, Text("")), Color.error_major(field.error)], dividechars=1)) total_items.append(Padding.line_break("")) if len(self.regions) > 0: total_items.append( Columns([ ('weight', 0.5, Text("Select a Cloud Region", align='right')), self.regions_w ], dividechars=1)) return total_items
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_widget(self): total_items = [HR()] prev_cat = None for category, spell in self.spells: if category == "_unassigned_spells": category = "other" if category != prev_cat: if prev_cat: total_items.append(Text("")) total_items.append(Color.label(Text(category))) prev_cat = category total_items.append(SpellPickerWidget(spell, self.submit)) total_items += [HR()] self.pile = Pile(total_items) return Padding.center_60(Filler(self.pile, valign='top'))
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_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): self.choices.append(HR()) for addon in sorted(app.addons.values(), key=attrgetter('name')): self.choices.append_option(label=addon.friendly_name, value=addon.name, state=addon.name in app.selected_addons) self.choices.append(Padding.line_break("")) self.choices.append( Columns([ ('fixed', 3, Text('')), Text(addon.description) ], dividechars=5) ) self.choices.append(HR()) if app.addons: self.choices.focus_position = 1 return self.choices
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
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
def build_widget(self): self.widgets = {} rows = [ Columns([('fixed', 3, Text('')), ('weight', 0.1, Text('Application')), ('weight', 0.4, Text('Result'))], dividechars=5), HR(), ] for step in app.steps: widget = StepResult(step) self.widgets[step.name] = widget rows.extend([ widget, HR(), ]) self.pile = Pile(rows) return self.pile
def addRow(self, item, use_divider=True): """ Appends widget to Pile Arguments: item: Widget to add to listbox use_divider: use divider for row item """ if use_divider and len(self._rows) != 0: self._rows.append(HR(0, 0)) self._rows.append(item)
def build_widgets(self): ws = [Text("Configure {}".format(self.application.service_name))] ws += self.get_option_widgets() ws += [ HR(), PlainButton("Cancel", self.do_cancel), PlainButton("Accept Changes", self.do_commit) ] self.pile = Pile(ws) return Padding.center_90(Filler(self.pile, valign="top"))
def build_widgets(self): self.services_column = ServicesColumn(self.display_controller, self.placement_controller, self) self.machines_column = MachinesColumn(self.display_controller, self.placement_controller, self) self.relations_column = RelationsColumn(self.display_controller, self.placement_controller, self, self.metadata_controller) self.charmstore_column = CharmstoreColumn(self.display_controller, self.placement_controller, self, self.metadata_controller) self.options_column = OptionsColumn(self.display_controller, self.placement_controller, self, self.metadata_controller) self.machines_header = self.get_machines_header(self.machines_column) self.relations_header = self.get_relations_header() self.services_header = self.get_services_header() self.charmstore_header = self.get_charmstore_header( self.charmstore_column) self.options_header = self.get_options_header(self.options_column) cs = [self.services_header, self.charmstore_header] self.header_columns = Columns(cs, dividechars=2) self.columns = Columns([self.services_column, self.machines_column], dividechars=2) self.deploy_button = MenuSelectButton("\nCommit\n", on_press=self.do_deploy) self.deploy_button_label = Text("Some charms use default") self.placement_edit_body_pile = Pile([self.columns]) self.placement_edit_body = Filler(Padding( self.placement_edit_body_pile, align='center', width=('relative', 95)), valign='top') self.bundle_graph_text = Text("No graph to display yet.") self.bundle_graph_widget = Padding(self.bundle_graph_text, 'center', 'pack') b = AttrMap(self.deploy_button, 'frame_header', 'button_primary focus') self.footer_grid = GridFlow( [self.deploy_button_label, Padding(b, width=28, align='center')], 28, 1, 1, 'right') f = AttrMap(self.footer_grid, 'frame_footer', 'frame_footer') self.frame = Frame(header=Pile([self.header_columns, HR()]), body=self.placement_edit_body, footer=f) return self.frame
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
def build_widget(self): return [ Columns([('fixed', 16, Text('network bridge', align="right")), Color.string_input(self.lxd_config['network'], focus_map='string_input focus')], dividechars=1), HR(), Columns([('fixed', 16, Text('storage pool', align="right")), Color.string_input(self.lxd_config['storage-pool'], focus_map='string_input focus')], dividechars=1), ]