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 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 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_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 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