def __init__(self, dict, title): self.selectedCmd = None self.dict = dict self.main = urwid.Padding(self.__menu(title), left=2, right=2) top = urwid.Overlay(self.main, urwid.SolidFill(u'\N{MEDIUM SHADE}'), align='center', width=('relative', 80), valign='middle', height=('relative', 80), min_width=20, min_height=9) self.txt = urwid.Text(u"Hello World", align='center') fill = urwid.Filler(self.txt, valign='middle') box = urwid.LineBox(fill, title='Information') widget_list = [] widget_list.append(top) widget_list.append(box) self.col = urwid.Columns(widget_list, 0, None, 1, None) self.mainLoop = urwid.MainLoop(self.col, palette=[('reversed', 'standout', '')], unhandled_input=show_or_exit)
def run(self): if not sys.stdout.isatty(): print( "Error: mitmproxy's console interface requires a tty. " "Please run mitmproxy in an interactive shell environment.", file=sys.stderr) sys.exit(1) self.ui = window.Screen() self.ui.set_terminal_properties(256) self.set_palette(self.options, None) self.options.subscribe( self.set_palette, ["console_palette", "console_palette_transparent"]) self.loop = urwid.MainLoop( urwid.SolidFill("x"), event_loop=urwid.AsyncioEventLoop(loop=asyncio.get_event_loop()), screen=self.ui, handle_mouse=self.options.console_mouse, ) self.window = window.Window(self) self.loop.widget = self.window self.window.refresh() if self.start_err: def display_err(*_): self.sig_add_log(None, self.start_err) self.start_err = None self.loop.set_alarm_in(0.01, display_err) super().run_loop(self.loop.run)
def decorate(self, pos, widget, is_first=True): line = None indent = self._tree.depth(pos) * self._indent cols = [(indent, urwid.SolidFill(' ')), widget] # construct a Columns, defining all spacer as Box widgets line = urwid.Columns(cols, box_columns=range(len(cols))[:-1]) return line
def test_overlay(self): s1 = urwid.SolidFill(u'1') s2 = urwid.SolidFill(u'2') o = urwid.Overlay(s1, s2, 'center', ('relative', 50), 'middle', ('relative', 50)) self.assertEqual(o.focus, s1) self.assertEqual(o.focus_position, 1) self.assertRaises(IndexError, lambda: setattr(o, 'focus_position', None)) self.assertRaises(IndexError, lambda: setattr(o, 'focus_position', 2)) self.assertEqual(o.contents[0], (s2, urwid.Overlay._DEFAULT_BOTTOM_OPTIONS)) self.assertEqual(o.contents[1], (s1, ('center', None, 'relative', 50, None, 0, 0, 'middle', None, 'relative', 50, None, 0, 0)))
def run(self): self.ui = urwid.raw_display.Screen() self.ui.set_terminal_properties(256) self.set_palette(self.options, None) self.options.subscribe( self.set_palette, ["console_palette", "console_palette_transparent"]) self.loop = urwid.MainLoop( urwid.SolidFill("x"), screen=self.ui, handle_mouse=self.options.console_mouse, ) self.ab = statusbar.ActionBar() self.loop.set_alarm_in(0.01, self.ticker) self.loop.set_alarm_in(0.0001, lambda *args: self.view_flowlist()) self.start() try: self.loop.run() except Exception: self.loop.stop() sys.stdout.flush() print(traceback.format_exc(), file=sys.stderr) print("mitmproxy has crashed!", file=sys.stderr) print("Please lodge a bug report at:", file=sys.stderr) print("\thttps://github.com/mitmproxy/mitmproxy", file=sys.stderr) print("Shutting down...", file=sys.stderr) finally: sys.stderr.flush() super().shutdown()
def display(loop, news_items): terminal_size = os.get_terminal_size() unread_count = get_node_unread_count(state.selected_node_id) unread_count_txt = urwid.Text('Unread: {}'.format(unread_count)) last_update_txt = urwid.Text('Updated: {}'.format(datetime.now().strftime('%Y-%m-%d %H:%M:%S')), align='right') columns_info = urwid.Columns([(round(terminal_size.columns / 2), unread_count_txt), last_update_txt]) sources_list = generate_sources_list() news_list = generate_news_list(news_items) elements_list = urwid.ListBox(news_list) sources_list = urwid.ListBox(sources_list) if state.list_with_focus == 'news_list': selected_list = elements_list else: selected_list = sources_list if len(selected_list.body) == 0: pass elif len(selected_list.body) > state.index_with_focus: selected_list.set_focus(state.index_with_focus) elif len(selected_list.body) == state.index_with_focus: selected_list.set_focus((state.index_with_focus - 1)) columns_news = urwid.Columns([(28, sources_list), (1, urwid.SolidFill(' ')), ((terminal_size.columns - 29), elements_list)]) columns_news.set_focus(selected_list) pile = urwid.Pile([columns_info, urwid.Divider(), (terminal_size.lines - 2, columns_news)]) widget = urwid.Filler(pile, valign='top') state.loop.widget = widget
def on_unicode_checkbox(self, w=None, state=False): """Enable smooth edges if utf-8 is supported""" logging.debug("unicode State is %s", state) # Update the controller to the state of the checkbox self.controller.smooth_graph_mode = state if state: self.hline = urwid.AttrWrap( urwid.SolidFill(u'\N{LOWER ONE QUARTER BLOCK}'), 'line') else: self.hline = urwid.AttrWrap(urwid.SolidFill(u' '), 'line') for graph in self.graphs.values(): graph.set_smooth_colors(state) self.show_graphs()
def __init__(self, master): self.master = master body = [urwid.Divider()] new_game_button = urwid.Button("New Game") new_game_button._label.align = "center" urwid.connect_signal(new_game_button, "click", self.new_game) body.append(urwid.AttrMap(new_game_button, None, focus_map="line")) quick_game_button = urwid.Button("Quick Start") quick_game_button._label.align = "center" urwid.connect_signal(quick_game_button, "click", self.quick_game) body.append(urwid.AttrMap(quick_game_button, None, focus_map="line")) help_button = urwid.Button("Help") help_button._label.align = "center" urwid.connect_signal(help_button, "click", self.help) body.append(urwid.AttrMap(help_button, None, focus_map="line")) quit_button = urwid.Button("Quit") quit_button._label.align = "center" urwid.connect_signal(quit_button, "click", self.exit_program) body.append(urwid.AttrMap(quit_button, None, focus_map="line")) listbox = urwid.ListBox(urwid.SimpleFocusListWalker(body)) super(StartScreen, self).__init__(listbox, urwid.SolidFill(u"\N{MEDIUM SHADE}"), align="center", width=("relative", 60), valign="middle", height=("relative", 60), min_width=40, min_height=16)
def render(self, size, focus=False): if not self._connected: size = self.pack(size) return urwid.AttrMap(urwid.SolidFill(' '), 'bottombar').render(size) canv_up_tail = self._mk_tail_canv('up', '↑') canv_dn_tail = self._mk_tail_canv('down', '↓') # List of (canvas, position, focus) tuples combinelist = [] # Download canv_dn = self._attr_dn.render((self._RATE_WIDTH,)) combinelist.append((canv_dn, None, False, self._RATE_WIDTH)) if self._dn_limit_width > 0: canv_dn_limit = self._attr_dn_limit.render((self._dn_limit_width,)) combinelist.append((canv_dn_limit, None, False, self._dn_limit_width)) combinelist.append((canv_dn_tail, None, False, self._TAIL_WIDTH)) combinelist.append((self._spacer_canvas, None, False, self._SPACER_WIDTH)) # Upload canv_up = self._attr_up.render((self._RATE_WIDTH,)) combinelist.append((canv_up, None, False, self._RATE_WIDTH)) if self._up_limit_width > 0: canv_up_limit = self._attr_up_limit.render((self._up_limit_width,)) combinelist.append((canv_up_limit, None, False, self._up_limit_width)) combinelist.append((canv_up_tail, None, False, self._TAIL_WIDTH)) return urwid.CanvasJoin(combinelist)
def build(self): """ Composes child views and components into a single object to be rendered. Parameters ---------- None Returns ------- None Raises ------ None """ self.controls = DashboardControls(self.model) self.liveDashboard = LiveDashboardData(self.model) self.prerecordedDashboard = PrerecordedDashboardData(self.model) self.emptyDashboard = urwid.Pile([]) self.data = urwid.WidgetPlaceholder(self.emptyDashboard) vline = urwid.AttrWrap(urwid.SolidFill(u'\u2502'), 'line') body = urwid.Columns([ (30, self.controls), # 30 is number of columns wide ('fixed', 1, vline), # fixed means it can't move self.data ], dividechars=1) return body
def __init__(self, master): self.master = master text = """ write me, help! help! """ utext = urwid.Text(text) body = [utext] back_button = urwid.Button("Back") back_button._label.align = "center" urwid.connect_signal(back_button, "click", self.back) body.append(urwid.AttrMap(back_button, None, focus_map="line")) listbox = urwid.ListBox(urwid.SimpleFocusListWalker(body)) super(HelpScreen, self).__init__(listbox, urwid.SolidFill(u"\N{MEDIUM SHADE}"), align="center", width=("relative", 60), valign="middle", height=("relative", 60), min_width=40, min_height=16)
def __init__(self, controller): self.controller = controller self.hline = urwid.AttrWrap(urwid.SolidFill(u'_'), 'line') clock_text = seconds_to_text(self.controller.stress_time) self.clock_view = urwid.Text(('bold text', clock_text), align="center") self.mode_buttons = [] self.refresh_rate_ctrl = urwid.Edit(('bold text', u'Refresh[s]:'), self.controller.refresh_rate) # Visible graphs are the graphs currently displayed, this is a # subset of the available graphs for display self.visible_graphs = {} self.graph_place_holder = urwid.WidgetPlaceholder(urwid.Pile([])) self.main_window_w = [] self.stress_menu = StressMenu(self.on_menu_close) self.help_menu = HelpMenu(self.on_menu_close) self.about_menu = AboutMenu(self.on_menu_close) self.temp_sensors_menu = TempSensorsMenu(self.on_sensors_menu_close) self.global_data = GlobalData(is_admin) self.stress_menu.sqrt_workers = str(self.global_data.num_cpus) self.left_margin = 0 self.top_margin = 0 urwid.WidgetPlaceholder.__init__(self, self.main_window()) urwid.connect_signal(self.refresh_rate_ctrl, 'change', self.update_refresh_rate)
def __init__(self, top_widget, *args, **kw): super(SSHDialog, self).__init__(top_widget, *args, **kw) self.top_widget = top_widget content_frame = urwid.Frame(body=None) top = urwid.Text(self.text) top = urwid.Padding(top, align='left', width='pack') top = urwid.AttrMap(urwid.Filler(top, valign='top'), 'wcolor') yes = urwid.AttrMap(urwid.Button('Yes', self.handle_input), 'focus', 'selectable') no = urwid.AttrMap(urwid.Button('No', self.handle_input), 'focus', 'selectable') buttons = urwid.GridFlow([no, yes], 10, 3, 1, 'center') bottom = urwid.Padding(buttons, align='right', width='pack') bottom = urwid.AttrMap(urwid.Filler(bottom, valign='bottom'), 'wcolor') content = urwid.Pile([top, bottom], focus_item=1) content = urwid.AttrMap(urwid.LineBox(content), 'wcolor') content = urwid.Overlay(content, urwid.AttrMap(urwid.SolidFill(gli.SFILL), 'bgcolor'), align='center', valign='middle', width=50, height=10) content_frame.body = content self._w = content_frame
def main(): palette = [ ("banner", "", "", "", "#ffa", "#60d"), ("streek", "", "", "", "g50", "#60a"), ("in", "", "", "", "g38", "#808"), ("out", "", "", "", "g27", "#a06"), ("bg", "", "", "", "g7", "#d06"), ] placeholder = urwid.SolidFill() loop = urwid.MainLoop(placeholder, palette, unhandled_input=show_or_exit) loop.screen.set_terminal_properties(colors=256) loop.widget = urwid.AttrMap(placeholder, "bg") loop.widget.original_widget = urwid.Filler(urwid.Pile([])) div = urwid.Divider() outside = urwid.AttrMap(div, "out") inside = urwid.AttrMap(outside, "in") txt = urwid.Text(("banner", u"Hello World)"), align="center") streek = urwid.AttrMap(txt, "streek") pile = loop.widget.base_widget #this skips decorations for item in (outside, inside, streek, inside, outside): pile.contents.append((item, pile.options())) loop.run()
def __get_screen(self): arena = urwid.AttrMap(urwid.SolidFill(' '), 'arena') arena = self.player.render(arena) for e in self.entities: arena = e.render(arena) return urwid.Overlay(arena, self.background, 'center', Config.ARENA_WIDTH, 'middle', Config.ARENA_HEIGHT)
def _build_container(self, ui_container): assert ui.ContainerElement in type(ui_container).mro() widgets = [] for element in ui_container.children: widget = self.build(element) if type(ui_container) is ui.ConfirmedEntry: # Special handling of the special widget, but why? # Why? Because nested Pile's need to be taken care of. # FIXME Generalize this (to cover other widgets too) widgets.append(widget) else: widgets.append(("pack", widget)) # Add buttons if hasattr(ui_container, "buttons") and ui_container.buttons: widgets.append(self._build_button_bar(ui_container.buttons)) if not any(type(t) is not tuple or t[0] == "weight" for t in widgets): # Add a weighted dummy if no weigthed dummy is in the Pile, # to fullfill urwid's assumptions # FIXME this whole function can be cleaned up! widgets.append(urwid.SolidFill()) if ui.Page in type(ui_container).mro(): page = uw.PageWidget(widgets, ui_container.title) else: page = uw.TabablePile(widgets) return page
def draw(self): content_frame = urwid.Frame(body=None) top = urwid.Text(self.text) top = urwid.Padding(top, align='left', width='pack') top = urwid.AttrMap(urwid.Filler(top, valign='top'), 'wcolor') yes = urwid.AttrMap(urwid.Button('Yes', self.handle_input), 'focus', 'selectable') no = urwid.AttrMap(urwid.Button('No', self.handle_input), 'focus', 'selectable') buttons = urwid.GridFlow([yes, no], 10, 3, 1, 'center') bottom = urwid.Padding(buttons, align='right', width='pack') bottom = urwid.AttrMap(urwid.Filler(bottom, valign='bottom'), 'wcolor') content = urwid.Pile([top, bottom], focus_item=1) content = urwid.AttrMap(urwid.LineBox(content), 'wcolor') content = urwid.Overlay(content, urwid.AttrMap(urwid.SolidFill(gli.SFILL), 'bgcolor'), align='center', valign='middle', width=60, height=20) content_frame.body = content self._w = content_frame
def test_urwid(terminal_colors): import urwid def exit_on_q(key): if key.casefold() == 'q': raise urwid.ExitMainLoop() palette = [ ('banner', '', '', '', '#ffa', '#60d'), ('streak', '', '', '', 'g50', '#60a'), ('inside', '', '', '', 'g38', '#808'), ('outside', '', '', '', 'g27', '#a06'), ('bg', '', '', '', 'g7', '#d06'),] placeholder = urwid.SolidFill() loop = urwid.MainLoop(placeholder, palette, unhandled_input=exit_on_q) loop.screen.set_terminal_properties(colors=256 if terminal_colors else 16) loop.widget = urwid.AttrMap(placeholder, 'bg') loop.widget.original_widget = urwid.Filler(urwid.Pile([])) div = urwid.Divider() outside = urwid.AttrMap(div, 'outside') inside = urwid.AttrMap(div, 'inside') txt = urwid.Text(('banner', u" KalCI == Here For U "), align='center') streak = urwid.AttrMap(txt, 'streak') pile = loop.widget.base_widget # .base_widget skips the decorations for item in [outside, inside, streak, inside, outside]: pile.contents.append((item, pile.options())) try: loop.run() except KeyboardInterrupt: pass
def _get_arrowhead_aligner(self): if self.message.has_replies(): aligner = u'\u2502' else: aligner = ' ' aligner = urwid.SolidFill(aligner) return ('fixed', 1, urwid.AttrMap(aligner, self.arrow_bars_att))
def ssid_widget(ssids): main = urwid.Padding(menu(u'Select SSID:', ssids), left=2, right=2) top = urwid.Overlay(main, urwid.SolidFill(u'\N{MEDIUM SHADE}'), align='center', width=('relative', 60), valign='middle', height=('relative', 60), min_width=20, min_height=9) return top
def main_window(self): # Initiating the data self.graph_cpu = self.bar_graph('util light', 'util dark', 'CPU Utilization Across all workers[%]', [], [0, 50, 100]) self.graph_mem = self.bar_graph('temp dark', 'temp light', 'Used Memory', [], [0, 25, 50, 75, 100]) self.graph_data.graph_num_bars = self.graph_cpu.bar_graph.get_size()[1] self.graph_cpu.bar_graph.set_bar_width(1) self.graph_mem.bar_graph.set_bar_width(1) vline = urwid.AttrWrap(urwid.SolidFill(u'\u2502'), 'line') self.visible_graphs = [self.graph_cpu, self.graph_mem] self.show_graphs() graph_controls = self.graph_controls() overview_stats = self.init_overview_stats() text_col = urwid.ListBox(urwid.SimpleListWalker(overview_stats + [urwid.Divider()] + graph_controls )) w = urwid.Columns([('weight', 2, self.graph_place_holder), ('fixed', 1, vline), ('fixed', 20, text_col)], dividechars=1, focus_column=2) self.main_window_w = w return self.main_window_w
def password_menu(): global password_widget password_prompt = urwid.Text("Password: "******"", align='center', mask='*') txt_password = urwid.AttrMap(password_widget, 'prompt') btn_ok = urwid.Button('Ok') btn_cancel = urwid.Button('Cancel') urwid.connect_signal(btn_cancel, 'click', exit_program) urwid.connect_signal(btn_ok, 'click', connect_network) filler = urwid.Filler( urwid.Pile([ password_prompt, txt_password, urwid.AttrMap(btn_ok, None, 'reversed'), urwid.AttrMap(btn_cancel, None, 'reversed') ])) padding = urwid.Padding(filler, left=2, right=2) ppadding = urwid.AttrMap(padding, 'banner') # prompt = urwid.Edit(u"Password", mask=u'*') top = urwid.Overlay(ppadding, urwid.SolidFill(u' '), align='center', width=('relative', 60), valign='middle', height=('relative', 60), min_width=20, min_height=9) topp = urwid.AttrMap(top, 'bg') return topp
def main(): global proc name = ' '.join(sys.argv[1:]) if not name: print("Usage: killit <search term>") sys.exit() processes = get_processes_by_name(name) for p in processes: _proc[p.pid] = p lines = [ '%s: %s' % (pid, ' '.join(p.cmdline())) for (pid, p) in _proc.items() ] menu = Menu() main = urwid.Padding(menu.menu(APP_BANNER, lines), left=2, right=2) top = urwid.Overlay(main, urwid.SolidFill(u'\N{MEDIUM SHADE}'), align='center', width=('relative', 80), valign='middle', height=('relative', 80), min_width=20, min_height=9) urwid.MainLoop(top, palette=[('reversed', 'standout', '')], unhandled_input=handle_keys).run()
def __init__(self, widget): hline = urwid.Divider('─') self._vline = urwid.AttrMap(urwid.SolidFill('│'), 'frame') self._topline = urwid.AttrMap( urwid.Columns([ ('fixed', 1, urwid.Text('┌')), hline, ('fixed', 1, urwid.Text('┐')), ]), 'frame') self._bottomline = urwid.AttrMap( urwid.Columns([ ('fixed', 1, urwid.Text('└')), hline, ('fixed', 1, urwid.Text('┘')), ]), 'frame') self._middle = urwid.Columns( [('fixed', 1, self._vline), widget, ('fixed', 1, self._vline)], focus_column=1, ) self._all = urwid.Pile( [('flow', self._topline), self._middle, ('flow', self._bottomline)], focus_item=1, ) urwid.WidgetWrap.__init__(self, self._all) urwid.WidgetDecoration.__init__(self, widget)
def rebuild(self): try: self.thread.refresh() except NonexistantObjectError: self.body = urwid.SolidFill() self.message_count = 0 return self._tree = ThreadTree(self.thread) # define A to be the tree to be wrapped by a NestedTree and displayed. # We wrap the thread tree into an ArrowTree for decoration if # indentation was requested and otherwise use it as is. if self._indent_width == 0: A = self._tree else: # we want decoration. bars_att = settings.get_theming_attribute('thread', 'arrow_bars') # only add arrow heads if there is space (indent > 1). heads_char = None heads_att = None if self._indent_width > 1: heads_char = u'\u27a4' heads_att = settings.get_theming_attribute( 'thread', 'arrow_heads') A = ArrowTree(self._tree, indent=self._indent_width, childbar_offset=0, arrow_tip_att=heads_att, arrow_tip_char=heads_char, arrow_att=bars_att) self._nested_tree = NestedTree(A, interpret_covered=True) self.body = TreeBox(self._nested_tree) self.message_count = self.thread.get_total_messages()
def __init__(self, mainloop: urwid.MainLoop) -> None: self._mainloop = mainloop self._main_view = urwid.WidgetPlaceholder(urwid.SolidFill(" ")) self.layout = self._create_layout() self._act_stack: List[ActivityContext] = [] self._mainloop.widget = self.layout
def __init__(self, loop): base = urwid.SolidFill("") self.loop = urwid.MainLoop( base, event_loop=urwid.AsyncioEventLoop(loop=loop), palette=palettes) self.base = base
def __init__(self, controller, args): self.controller = controller self.custom_temp = args.custom_temp self.custom_fan = args.custom_fan self.args = args self.hline = urwid.AttrWrap(urwid.SolidFill(u'_'), 'line') self.mode_buttons = [] self.refresh_rate_ctrl = urwid.Edit(('bold text', u'Refresh[s]:'), self.controller.refresh_rate) self.visible_graphs = {} self.graph_place_holder = urwid.WidgetPlaceholder(urwid.Pile([])) self.main_window_w = [] self.stress_menu = StressMenu(self.on_menu_close) self.help_menu = HelpMenu(self.on_menu_close) self.about_menu = AboutMenu(self.on_menu_close) self.temp_sensors_menu = TempSensorsMenu(self.on_sensors_menu_close) self.global_data = GlobalData(is_admin) self.stress_menu.sqrt_workers = str(self.global_data.num_cpus) self.left_margin = 0 self.top_margin = 0 self.v_relative = 50 self.h_relative = 50 urwid.WidgetPlaceholder.__init__(self, self.main_window()) urwid.connect_signal(self.refresh_rate_ctrl, 'change', self.update_refresh_rate)
def __init__(self, walker=None): def f(char, attr): return urwid.AttrMap(urwid.SolidFill(char), attr) self.boxes = [ urwid.AttrMap(urwid.SolidFill("\N{FULL BLOCK}"), 'scrollbar_bg'), urwid.AttrMap(urwid.SolidFill("\N{FULL BLOCK}"), 'scrollbar_fg'), ] self.bar = Pile([ ('weight', 1, f("\N{BOX DRAWINGS LIGHT VERTICAL}", 'scrollbar_bg')), ('weight', 1, self.boxes[0]), ('weight', 1, f("\N{BOX DRAWINGS LIGHT VERTICAL}", 'scrollbar_bg')), ]) super().__init__(walker)
def draw_output(self, tag, text, prefix=None): time = datetime.now().strftime("%H:%M:%S") time = (len(time), urwid.Text("{}".format(time))) tag_width = max([len(tag) for tag in TAG_SYMBOLS.values()]) tag = (tag_width, urwid.Text(TAG_SYMBOLS[tag])) if not prefix: prefix = urwid.Text("") elif isinstance(prefix, User): prefix = self.user_list.get_user_text(prefix) else: prefix = urwid.Text(prefix) prefix.set_align_mode("right") prefix = (USER_WIDTH, prefix) hline = (1, urwid.SolidFill(u'\u2502')) text = urwid.Text(text) self.output_box.body.append( urwid.Columns([time, tag, prefix, hline, text], dividechars=1, box_columns=[3])) # Scroll to bottom self.output_box.set_focus(len(self.output_box.body) - 1, "above") self._refresh()