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, name, named_grid_elements: list, callback: Callable): self.name = name self.named_widgets = {} unnamed_grid_elements = [] for row in named_grid_elements: self.named_widgets.update(row) unnamed_grid_elements.append(list(row.values())) confirm = Button("Confirm", "confirm_button", self.__confirm) abort = Button("Abort", "abort_button", self.__quit) unnamed_grid_elements.append([confirm, abort]) super().__init__(unnamed_grid_elements) self.keybind["f1"] = self.keybind["ctrl x"] = self.__confirm self.keybind["f5"] = self.keybind["ctrl g"] = self.__quit self.on_submit = callback bottom = Filler(self, valign="top") popup = AttrWrap( Filler(Text("Work in progress...\n\nPlease wait.", "center")), "popup") self.overlay = Overlay(popup, bottom, "center", 30, "middle", 5) self.root = WidgetPlaceholder(bottom)
def __init__(self): self.idx = 0 b_txt = BigText("Taurus", Thin6x6Font()) b_txt = Padding(b_txt, CENTER, width=CLIP) b_txt = Filler(b_txt) self.byb = Filler(Text('', align=CENTER)) parts = [ (5, b_txt), (1, self.byb), ] super(TaurusLogo, self).__init__(parts)
def gen_columns(present, columns): names = 'Name\n\n' + '\n'.join([x['name'] for x in present.values()]) orgs = 'Org\n\n' + '\n'.join([x['org'] for x in present.values()]) times = 'Arrived\n\n' + '\n'.join([ str(int((time.time() - x['arrived']) / 60)) + ' mins ago' for x in present.values() ]) columns.contents = ( (Filler(Text(names), 'top'), columns.options()), (Filler(Text(orgs), 'top'), columns.options()), (Filler(Text(times), 'top'), columns.options()), )
def __init__(self, parser, encoding): self.loop = None self.parser = parser self.panel_focus = 1 self.show_ladder = False self.search = { 'phone': '', 'chan': '', 'call_id': '', } self.sidebar = Sidebar(sorted(self.parser.get_phone_set())) connect_signal(self.sidebar, 'select', self.on_result_selected) connect_signal(self.sidebar, 'search', self.on_search) self.log_display = LogDisplay(parser, encoding) self.cols = Columns([ ('fixed', 20, self.sidebar), ('fixed', 1, Filler(Divider(), 'top')), ('weight', 1, self.log_display), ]) self.footer = Text('') self.set_footer_text() self.frame = Frame(self.cols, footer=AttrWrap(self.footer, 'bar'))
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 parse_tag_from_node(node): from . import tags valign = node.attr.valign or 'middle' children = node.children() assert len(children) == 1, 'Filler can only have one child.' filler = Filler(tags.parse_tag_from_node(PyQuery(children[0])), valign) return filler
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, edit_text, strike=False, new=False): self.strikethrough = strike self.new_expan = new # Spacing strings self.leading_space = ' ' self.leading_char = '- ' self.leading_STRIKE = 'x ' # Default color specs self.text_attr = AttrSpec('h6', '') self.text_STRIKE = AttrSpec('h6, strikethrough', '') self.focus_attr = AttrSpec('h6, bold', '') self.focus_STRIKE = AttrSpec('h6, bold, strikethrough', '') if not self.strikethrough: caption = self.leading_space + self.leading_char attr = self.text_attr attr_focus = self.focus_attr else: caption = self.leading_space + self.leading_STRIKE attr = self.text_STRIKE attr_focus = self.focus_STRIKE self.edit = Edit(caption, edit_text, wrap='clip') self.map = AttrMap(self.edit, attr_map=attr, focus_map=attr_focus) self.fill = Filler(self.map) super().__init__(self.map)
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): 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 __init__(self, name, number): WidgetWrap.__init__( self, BoxAdapter(Filler(BaseClipButton(str(number).rjust(3), name), top=1, bottom=1), height=3))
def __init__(self, executor_widgets): self.log_widget = ScrollingLog() self.latest_stats = LatestStats() self.cumulative_stats = CumulativeStats() stats_pane = Pile([(WEIGHT, 0.333, self.latest_stats), (WEIGHT, 0.667, self.cumulative_stats)]) self.graphs = ThreeGraphs() self.logo = TaurusLogo() ordered_widgets = sorted(executor_widgets, key=lambda x: x.priority) right_widgets = ListBox( SimpleListWalker([Pile([x, Divider()]) for x in ordered_widgets])) widget_pile = Pile([ (7, self.logo), right_widgets, ]) log_block = Pile([(1, Filler(Divider('─'))), self.log_widget]) right_pane = Pile([(WEIGHT, 0.667, widget_pile), (WEIGHT, 0.333, log_block)]) columns = [(WEIGHT, 0.25, self.graphs), (WEIGHT, 0.50, stats_pane), (WEIGHT, 0.25, right_pane)] super(TaurusConsole, self).__init__(columns)
def build_widgets(self): cloud_type = get_cloud_types_by_name()[app.current_cloud] controller_is_maas = cloud_type == '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_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 = [] 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 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 _build_widget(self, **kwargs): total_items = [ Padding.center_60(Text(self.title, align="center")), Padding.center_60( Divider("\N{BOX DRAWINGS LIGHT HORIZONTAL}", 1, 1)) ] if self.input_items: for item in self.input_items: key = item[0] caption = item[1] try: mask = item[2] except: mask = None self.input_selection[key] = StringEditor(caption="", mask=mask) col = Columns([ ("weight", 0.4, Text(caption, align="right")), Color.string_input(self.input_selection[key], focus_map="string_input focus") ]) 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_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): 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_node_waiting(self): """ creates a loading screen if nodes do not exist yet """ text = [ Padding.line_break(""), Text(self.message, align="center"), Padding.line_break("") ] load_box = [ Color.pending_icon_on(Text("\u2581", align="center")), Color.pending_icon_on(Text("\u2582", align="center")), Color.pending_icon_on(Text("\u2583", align="center")), Color.pending_icon_on(Text("\u2584", align="center")), Color.pending_icon_on(Text("\u2585", align="center")), Color.pending_icon_on(Text("\u2586", align="center")), Color.pending_icon_on(Text("\u2587", align="center")), Color.pending_icon_on(Text("\u2588", align="center")) ] # Add loading boxes random.shuffle(load_box) loading_boxes = [] loading_boxes.append(('weight', 1, Text(''))) for i in load_box: loading_boxes.append( ('pack', load_box[random.randrange(len(load_box))])) loading_boxes.append(('weight', 1, Text(''))) loading_boxes = Columns(loading_boxes) return Filler(Pile(text + [loading_boxes]), valign="middle")
def compose(self): return Filler( Pile([ self.caption, self.innerbox, # scratchpad, self.button_wrap ]))
def build_widgets(self): self.message = Text("Please review available machines in MAAS", align='center') self.button_pile = Pile([]) self.main_pile = Pile([self.message, Divider(), self.button_pile]) return Filler(self.main_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__(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, info): self.text = Text("", align="center") self.text._selectable = True # glitch to make it work super().__init__(Filler(self.text, valign="middle")) self.keybind = {} self.heads = {} self.info = info
def _build_overlay_widget(self, top_w, align, width, valign, height, min_width, min_height): return Overlay(top_w=Filler(top_w), bottom_w=self.frame, align=align, width=width, valign=valign, height=height, min_width=width, min_height=height)
def __init__(self, msg=None): if not msg: msg = "Processing." items = [ Padding.center_60(Text("Information", align="center")), Padding.center_60( Divider("\N{BOX DRAWINGS LIGHT HORIZONTAL}", 1, 1)), Padding.center_60(Text(msg)) ] super().__init__(Filler(Pile(items), valign='middle'))
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 render_component(self, props): title = self.get_title(props['title']) menu = Filler(self.menu(props['choices'], props['go_to_prev']), valign='middle', height=('relative', 100)) current_song = self.get_current_song(props['current_song']) widgets = [title, menu, current_song] return Pile(widgets)