def __init__(self): self.screen = Screen() self.screen.set_input_timeouts(max_wait=0) self.steps = GridFlow([], 20, 2, 1, 'left') self.progress = SimpleFocusListWalker([]) self.log = SimpleFocusListWalker([]) self.widget = AttrMap( LineBox(Pile([ ('fixed', 6, AttrMap(Filler(self.steps), 'default')), ('fixed', 1, Filler(Divider('\u2500'))), ('fixed', 3, ListBox(self.progress)), AttrMap(LineBox(ListBox(self.log), title='Message log'), 'default') ]), title='Indico 1.2 -> 2.0 migration'), 'global_frame') self.screen.register_palette( [('green', 'light green', ''), ('white', 'white', ''), ('red', 'dark red', ''), ('yellow', 'yellow', ''), ('progress_empty', 'black', 'light gray'), ('progress_progress', 'light cyan', 'light gray'), ('progress_done', 'black', 'light cyan'), ('box', 'white', 'dark gray'), ('step_done', 'light green', ''), ('step_working', 'dark gray', ''), ('global_frame', 'light cyan', ''), ('fill', 'light cyan', 'dark cyan'), ('done', 'white', 'dark green'), ('eta', 'yellow', 'dark gray')] + generate_urwid_palette(PALETTE))
def __init__(self): grading_directory = LineBox( Edit(("header", "Grading directory\n\n"), state.grading_directory)) subdirectories = LineBox( Edit(("header", "Subdirectories\n\n"), state.subdirectories)) assignment_type = RadioGroup("Assignment type", AssignmentType, state.assignment_type) deadline = LineBox(Edit(("header", "Deadline\n\n"), state.deadline)) assignment_sname = LineBox( Edit(("header", "Assignment short name\n\n"), state.assignment_sname)) assignment_lname = LineBox( Edit(("header", "Assignment long name\n\n"), state.assignment_lname)) grid_elements = [ { "grading_directory": grading_directory, "subdirectories": subdirectories }, { "assignment_type": assignment_type, "deadline": deadline }, { "assignment_sname": assignment_sname, "assignment_lname": assignment_lname }, ] super().__init__("Grade", grid_elements, grade)
def __init__(self): sender = LineBox( Edit(("header", "Sender email\n\n"), state.sender_email)) recipient = LineBox( Edit(("header", "Recipient email\n\n"), state.recipient_email)) grading_directory = LineBox( Edit(("header", "Grading directory\n\n"), state.grading_directory)) subject = LineBox(Edit(("header", "Subject\n\n"), state.subject)) message = LineBox( Edit(("header", "Message\n\n"), state.message, multiline=True)) grid_elements = [ { "sender_email": sender, "recipient_email": recipient }, { "grading_directory": grading_directory, "subject": subject }, { "message": message }, ] super().__init__("Mail", grid_elements, mail)
def __init__(self, choice_callback=None, command_callback=None, help_callback=None): self.palette = [ ('brick', 'light red', 'black'), ('rubble', 'yellow', 'black'), ('wood', 'light green', 'black'), ('concrete', 'white', 'black'), ('stone', 'light cyan', 'black'), ('marble', 'light magenta', 'black'), ('jack', 'dark gray', 'white'), ('msg_info', 'white', 'black'), ('msg_err', 'light red', 'black'), ('msg_debug', 'light green', 'black'), ] self.choice_callback = choice_callback self.command_callback = command_callback self.help_callback = help_callback self.screen = None self.loop = None self.called_loop_stop = False self.reactor_stop_fired = False self.quit_flag = False self.edit_msg = "Make selection ('q' to quit): " self.roll_list = SimpleListWalker([]) self.game_log_list = SimpleListWalker([]) self.choices_list = SimpleListWalker([]) self.state_text = SimpleListWalker([Text('Connecting...')]) self.edit_widget = Edit(self.edit_msg) self.roll = ListBox(self.roll_list) self.game_log = ListBox(self.game_log_list) self.choices = ListBox(self.choices_list) self.state = ListBox(self.state_text) self.left_frame = Pile([ LineBox(self.state), (13, LineBox(self.choices)), ]) self.right_frame = Pile([LineBox(self.game_log), LineBox(self.roll)]) self.state.set_focus(len(self.state_text) - 1) self.columns = Columns([('weight', 0.75, self.left_frame), ('weight', 0.25, self.right_frame)]) self.frame_widget = Frame(footer=self.edit_widget, body=self.columns, focus_part='footer') self.exc_info = None
def top(period=1, get_state=get_demo_state): """Display process information. Arguments: - period (float) : update period - get_state (callable) : function to generate state information """ engine_table = Columns([]) process_table = Columns([]) def make_text(title, attr="", align="left"): """Create a Text object with given content, style and alignment.""" return Text((attr, " %s" % title), align=align) def make_separator(): """Create a separator.""" return make_text("") def update(): engines, processes = get_state() engine_table.contents = get_engine_table_content(engines) process_table.contents = get_process_table_content([header] + processes) items = [ make_separator(), make_text("Process Viewer", attr="section", align="center"), make_text("Engine Usage:"), LineBox(engine_table, **{arg: " " for arg in linebox_args}), make_text("Process Table:"), make_separator(), LineBox(process_table), make_separator(), make_text("Press (q) to quit.") ] def on_timer(loop, user_data): update() loop.set_alarm_in(period, on_timer) def on_key(key): if key in ('q', 'Q'): raise ExitMainLoop() loop = MainLoop(get_padded(items), palette, unhandled_input=on_key) on_timer(loop, None) # Start timer loop.run()
def __init__(self): grading_directory = LineBox(Edit(("header", "Grading directory\n\n"), state.grading_directory)) grader_name = LineBox(Edit(("header", "Grader's name\n\n"), state.grader_name)) group_number = LineBox(IntEdit(("header", "Group number\n\n"), state.group_number)) team_type = RadioGroup("Team type", TeamType, state.team_type) username = LineBox(Edit(("header", "Username\n\n"), "")) password = LineBox(Edit(("header", "Password\n\n"), "", mask="*")) grid_elements = [ {"grading_directory": grading_directory, "grader_name": grader_name}, {"group_number": group_number, "team_type": team_type}, {"username": username, "password": password}, ] super().__init__("Clone", grid_elements, clone)
def main(): task_list_box = TaskListBox() refresh = partial(on_tasks_refresh, task_list_box) with just_start(write_status, refresh, client_notify) as action_runner: task_list_box.action_handler = ActionHandler(action_runner, FocusedTask(task_list_box)) task_list_box = LineBox(task_list_box, title='Tasks') status_box = LineBox(Filler(status, valign=TOP), title='App Status') columns = Columns([('weight', 1.3, task_list_box), ('weight', 1, status_box)]) MainLoop( TopWidget(columns, footer=pomodoro_status_box), palette=( ('error', *get_error_colors()), ) ).run()
def __init__(self): grading_directory = LineBox( Edit(("header", "Grading directory\n\n"), state.grading_directory)) assignment_sname = LineBox( Edit(("header", "Assignment short name\n\n"), state.assignment_sname)) grid_elements = [ { "grading_directory": grading_directory, "assignment_sname": assignment_sname }, ] super().__init__("Push", grid_elements, push)
def __init__(self, parent): self.parent = parent close = ActionBackButton("(close)") connect_signal(close, "click", self.close) group = [Color.menu_button(close)] width = 0 for i, option in enumerate(self.parent._options): if option.enabled: if isinstance(option.label, Widget): btn = option.label else: btn = Color.menu_button(ActionMenuButton(option.label)) width = max(width, len(btn.base_widget.label)) connect_signal(btn.base_widget, 'click', self.click, option.value) else: label = option.label if isinstance(label, Widget): label = label.base_widget.label width = max(width, len(label)) btn = Columns([ ('fixed', 1, Text("")), Text(label), ('fixed', 1, Text(">")), ], dividechars=1) btn = AttrWrap(btn, 'info_minor') group.append(btn) self.width = width super().__init__(LineBox(ListBox(group)))
def __init__(self, title, enum_type, starting_value, policy=RadioPolicy.VERTICAL): self.selected_value = starting_value self.enum_type = enum_type self.radio_group = [] for choice in enum_type: RadioButton(self.radio_group, label=choice.name.capitalize(), state=choice is starting_value) rows = [[Text(("header", title))]] if policy is RadioPolicy.VERTICAL: for radio in self.radio_group: rows.append([radio]) else: col = [] for radio in self.radio_group: col.append(radio) rows.append(col) super().__init__(rows) self._w = LineBox(self._w)
def create_pop_up(self): line_box = LineBox( Filler(Text(self._text, align='center')), title=self._title, ) return AttrMap(line_box, 'popup')
def __init__(self, list_data=None): self.is_editing = False self.tasks = [] self.name = None self.group = None self.id = None if list_data: # Parse the data. self.parse_data(list_data) else: # Must be a new list self.name = 'untitled' self.group = 'none' self.id = uuid.uuid4().hex # AttrSpecs self.attr_spec = AttrSpec('', '') self.focus_nav = AttrSpec('h12', '') self.focus_ins = AttrSpec('h160', '') # Build widget stack self.title = TitleBar(self.name) self.group_foot = GroupFoot(self.group) self.body = urwid.SimpleFocusListWalker(self.tasks) self.list_box = ListBox(self.body) self.list_frame = Frame(self.list_box, header=self.title, footer=self.group_foot) self.line_box = LineBox(self.list_frame) self.line_attr = AttrMap(self.line_box, self.attr_spec, self.focus_nav) super().__init__(self.line_attr)
def build_widgets(self): instructions = Text("Remove services from {}".format( self.machine.hostname)) self.machine_widget = MachineWidget(self.machine, self.controller, show_hardware=True) def show_remove_p(cc): md = self.controller.get_assignments(cc) for atype, ms in md.items(): hostnames = [m.hostname for m in ms] if self.machine.hostname in hostnames: return True return False actions = [(show_remove_p, 'Remove', self.do_remove)] self.services_list = ServicesList(self.controller, actions, actions, machine=self.machine) close_button = AttrMap(Button('X', on_press=self.close_pressed), 'button_secondary', 'button_secondary focus') p = Pile([ GridFlow([close_button], 5, 1, 0, 'right'), instructions, Divider(), self.machine_widget, Divider(), self.services_list ]) return LineBox(p, title="Remove Services")
def __init__(self, parent, cur_index): self.parent = parent group = [] for i, option in enumerate(self.parent._options): if option.enabled: btn = ClickableThing(option.label) connect_signal(btn, 'click', self.click, i) if i == cur_index: rhs = '\N{BLACK LEFT-POINTING SMALL TRIANGLE} ' else: rhs = '' else: btn = option.label rhs = '' row = Columns([ (1, Text("")), btn, (2, Text(rhs)), ]) if option.enabled: row = AttrWrap(row, 'menu_button', 'menu_button focus') else: row = AttrWrap(row, 'info_minor') btn = UrwidPadding(row, width=self.parent._padding.width) group.append(btn) list_box = ListBox(group) list_box.base_widget.focus_position = cur_index super().__init__(Color.body(LineBox(list_box)))
def __init__(self): # self.caption = AttrMap( # Text( # ('caption', self.caption_text), align='center' # ), # 'blackongrey' # ) self.caption = Text(('caption', self.caption_text), align='center') self.inputbox_a = Padding(AttrMap( Edit(multiline=False, mask=self.mask), 'inputfield'), align='center', width=24) self.divider = Padding(Divider(' '), align='center') self.inputbox_b = Padding(AttrMap( Edit(multiline=False, mask=self.mask), 'inputfield'), align='center', width=24) self.innerbox = AttrMap( LineBox(Pile([self.inputbox_a, self.divider, self.inputbox_b])), 'blackongrey') # scratchpad = Text('<enter>') self.button = Button('OK', on_press=self._ok_button) self.button_wrap = Padding(AttrMap(self.button, 'button.normal', 'button.focus'), align='center', width=15)
def _build_widget(self, **kwargs): total_items = [] for _item in self.radio_items.keys(): desc = AttrWrap( Text(" {}".format( self.radio_items[_item][1])), 'input', 'input focus') total_items.append( AttrWrap(self.radio_items[_item][0], 'input', 'input focus')) total_items.append(AttrWrap(desc, 'input')) total_items.append(Divider('-')) self.input_lbox = ListBox(SimpleListWalker(total_items[:-1])) self.add_buttons() self.container_box_adapter = BoxAdapter(self.input_lbox, len(total_items)) self.container_lbox = ListBox( [self.container_box_adapter, Divider(), self.btn_pile]) return LineBox( BoxAdapter(self.container_lbox, height=len(total_items) + 3), title=self.title)
def build_widget(self, **kwargs): def remove_p(charm_class): n = self.pc.assignment_machine_count_for_charm(charm_class) return n > 0 def not_conflicted_p(cc): state, _, _ = self.pc.get_charm_state(cc) return state != CharmState.CONFLICTED actions = [(remove_p, 'Remove', self.do_remove), (not_conflicted_p, 'Add', self.do_add)] self.unrequired_undeployed_sl = ServicesList(self.pc, actions, actions, ignore_deployed=True, title="Un-Deployed") self.deployed_sl = ServicesList(self.pc, actions, actions, deployed_only=True, show_placements=True, title="Deployed Services") self.assigned_sl = ServicesList(self.pc, actions, actions, assigned_only=True, show_placements=True, title="Services to be Deployed") self.buttons = [] self.button_grid = GridFlow(self.buttons, 22, 1, 1, 'center') self.pile1 = Pile([self.button_grid, self.assigned_sl, self.unrequired_undeployed_sl]) self.pile2 = Pile([self.deployed_sl]) return LineBox(Columns([self.pile1, self.pile2]), title="Add Services")
def __init__(self, message, close_func): self.close_func = close_func button = Button("Close", self.do_close) box = LineBox(Pile([Text(message), button]), title="Info") super().__init__(box)
def __init__(self, msg=None, height=10): if not msg: msg = "Processing." listbox = ListBox([Text(msg)]) box_adapter = BoxAdapter(listbox, height=height) linebox = LineBox(box_adapter, title="Info") super().__init__(AttrWrap(linebox, 'dialog'))
def menu(): hello = Text( "Приветствую! Для продолжения настройте параметры лабиринта.\n" + "Если карта лабиринта будет некорректно отображаться, " + "попробуйте уменьшить значение ширины или развернуть окно.") height_enter = IntEdit("Высота лабиринта: ", 30) width_enter = IntEdit("Ширина лабиринта: ", 45) done = Button("Готово") done_pad = Padding(done, align="center", width=10) back = AttrMap(SolidFill("\u25E6"), "blueprint") pile = Pile( [hello, Divider("\u2500"), height_enter, width_enter, done_pad]) menu = Filler(LineBox(pile)) main_widget = Overlay(menu, back, align="center", width=35, height=12, valign="middle") loop = MainLoop(main_widget, palette) connect_signal(done, 'click', start_game) loop.run() return MazeGame(height_enter.value(), width_enter.value())
def _create_text(self): self.text = [] for line in self.HELP_TEXT: self._insert_line(line) return LineBox(BoxAdapter( ScrollableListBox(self.text), height=20), title='Help \u21C5 Scroll (ESC) Close')
def __init__(self, keyboard_detector, step): # step is an instance of pc105.Step self.keyboard_detector = keyboard_detector self.step = step lb = LineBox( Pile([('pack', Text("")), ('pack', UrwidPadding(self.make_body(), left=2, right=2)), ('pack', Text(""))]), _("Keyboard auto-detection")) super().__init__(lb)
def __init__(self, text: str, palette: str, callback: Callable): connect_signal(self, CLICK_SIGNAL, callback) widget = LineBox( AttrMap(Text(f"[{text}]", align="center"), "default", palette)) super().__init__(widget) # Glitch self._w.base_widget._selectable = True
def __init__(self, parent, ssids): self.parent = parent button = cancel_btn(_("Cancel"), on_press=self.do_cancel) ssid_list = [menu_btn(label=ssid, on_press=self.do_network) for ssid in ssids] p = Pile([BoxAdapter(ListBox(ssid_list), height=10), Padding.fixed_10(button)]) box = LineBox(p, title="Select a network") super().__init__(box)
def __init__(self, step_count, cancel_func): self.cancel_func = cancel_func button = cancel_btn(_("Cancel"), on_press=self.do_cancel) self.bar = ProgressBar(normal='progress_incomplete', complete='progress_complete', current=0, done=step_count) box = LineBox(Pile([self.bar, button_pile([button])]), title=_("Applying network config")) super().__init__(box)
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 main(): background = AttrMap(SolidFill(' '), 'basic') pwdialog = PasswordDialog().compose() box = AttrMap(LineBox(pwdialog), 'blackongrey') window = Overlay(box, background, 'center', 30, 'middle', 10) mainloop = MainLoop(window, unhandled_input=callback, palette=simple_colours) mainloop.run()
def __init__(self, step_count, cancel_func): self.cancel_func = cancel_func button = cancel_btn(on_press=self.do_cancel) self.bar = ProgressBar(normal='progress_incomplete', complete='progress_complete', current=0, done=step_count) box = LineBox(Pile([self.bar, Padding.fixed_10(button)]), title="Applying network config") super().__init__(box)
def _build_widget(self, **kwargs): # Charm selections num_of_items, charm_sel = self._insert_charm_selections() # Control buttons buttons = self._insert_buttons() return LineBox(BoxAdapter(ListBox([charm_sel, Divider(), buttons]), height=num_of_items + 2), title="Add unit")
def __init__(self, loop): spinner = Spinner(loop, style='dots') spinner.start() text = _("Applying config") # | text | # 12 34 self.width = len(text) + 4 super().__init__( LineBox(Pile([ ('pack', Text(' ' + text)), ('pack', spinner), ])))