Python urwid.AttrMap() Examples
The following are 30
code examples of urwid.AttrMap().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
urwid
, or try the search function
.
Example #1
Source File: util.py From sen with MIT License | 6 votes |
def get_operation_notify_widget(operation, notif_level="info", display_always=True): if not operation: return attr = "notif_{}".format(notif_level) took = operation.took text_list = [] if took > 300: fmt_str = "{} Query took " text_list.append((attr, fmt_str.format(operation.pretty_message))) command_took_str = "{:.2f}".format(took) if took < 500: text_list.append(("notif_text_yellow", command_took_str)) elif took < 1000: text_list.append(("notif_text_orange", command_took_str)) else: command_took_str = "{:.2f}".format(took / 1000.0) text_list.append(("notif_text_red", command_took_str)) text_list.append((attr, " s")) if took < 1000: text_list.append((attr, " ms")) elif display_always: text_list.append((attr, operation.pretty_message)) else: return return urwid.AttrMap(urwid.Text(text_list), attr)
Example #2
Source File: gazua.py From ec2-gazua with MIT License | 6 votes |
def _create_widget(self, instance): widgets = [ (25, SSHCheckBox( instance.name[:21], instance.is_connectable, self._run_tmux, self.not_checkable_callback, on_state_change=self.instance_check_changed, user_data=instance)), (15, ClippedText(instance.private_ip or '-')), (15, ClippedText(instance.public_ip or '-')), (15, ClippedText(instance.type[:15])), (3, ClippedText('O' if instance.is_running else 'X')), ClippedText(instance.key_name or '-'), ] columns_widget = Columns(widgets, dividechars=1) return AttrMap(columns_widget, None, 'instance_focus')
Example #3
Source File: widgets.py From pycopia with Apache License 2.0 | 6 votes |
def build(self): header = urwid.Pile([ urwid.AttrMap(urwid.Text("Edit {}".format(self.modelclass.__name__)), "formhead"), urwid.AttrMap(urwid.Text("Arrow keys navigate, Enter to select form button. Type into other fields."), "formhead"), urwid.Divider(), ]) formstack = [] for colname in ("name", "address", "country", "contact", "notes"): colmd = self.metadata[colname] wid = self.build_input(colmd, getattr(self.row, colmd.colname)) formstack.append(wid) colmd = self.metadata["attributes"] wid = self.build_attribute_input(colmd, getattr(self.row, colmd.colname)) formstack.append(wid) # common buttons formstack.append(self.get_form_buttons()) listbox = urwid.ListBox(urwid.SimpleListWalker(formstack)) return urwid.Frame(urwid.AttrMap(listbox, 'body'), header=header)
Example #4
Source File: widgets.py From pycopia with Apache License 2.0 | 6 votes |
def build(self): header = urwid.Pile([ urwid.AttrMap(urwid.Text("Edit Test Case"), "formhead"), urwid.AttrMap(urwid.Text("Arrow keys navigate, Enter to select form button. Type into other fields."), "formhead"), urwid.Divider(), ]) formstack = [] for groupname, group in [ (None, ("name", "purpose", "passcriteria")), ("Details", ("startcondition", "endcondition", "procedure", "prerequisites")), ("Management", ("valid", "automated", "interactive", "functionalarea", "testimplementation", "time_estimate", "bugid")), ("Requirement", ("reference", "cycle", "priority")), ("Status", ("status",)), ("Comments", ("comments",)), ]: if groupname: formstack.append(self.build_divider(groupname)) for colname in group: colmd = self.metadata[colname] wid = self.build_input(colmd, getattr(self.row, colmd.colname)) formstack.append(wid) data = self.get_default_data(["lastchange"]) formstack.append(self.get_form_buttons(data)) listbox = urwid.ListBox(urwid.SimpleListWalker(formstack)) return urwid.Frame(urwid.AttrMap(listbox, 'body'), header=header)
Example #5
Source File: widgets.py From pycopia with Apache License 2.0 | 6 votes |
def build(self): header = urwid.Pile([ urwid.AttrMap(urwid.Text("Create Interface"), "formhead"), urwid.AttrMap(urwid.Text("Arrow keys navigate, Enter to select form button. Type into other fields."), "formhead"), urwid.Divider(), ]) formstack = [] for groupname, group in [ (None, ("name", "alias", "ifindex", "description")), ("Network Address", ("ipaddr",)), ("Media Access Address", ("macaddr", "vlan")), ("Extra Info", ("interface_type", "mtu", "speed")), ("Administrative", ("status",)), ("Associations", ("network", "parent")), ]: if groupname: formstack.append(self.build_divider(groupname)) for colname in group: colmd = self.metadata[colname] wid = self.build_input(colmd) formstack.append(wid) formstack.append(self.get_form_buttons(create=True)) listbox = urwid.ListBox(urwid.SimpleListWalker(formstack)) return urwid.Frame(urwid.AttrMap(listbox, 'body'), header=header)
Example #6
Source File: main.py From pycopia with Apache License 2.0 | 6 votes |
def __init__(self, session, debug=False): self.loop =None self.session = session self.footer = urwid.AttrMap( urwid.Text([ ("key", "ESC"), " Quit ", ("key", "Tab"), " Move Selection ", ("key", "F1"), " Help ", ("key", "F2"), " Reset ", ("key", "F5"), " Add Test Case ", ("key", "F6"), " Add Test Suite ", ("key", "F9"), " Add Equipment ", ("key", "F10"), " Add Environment ", ]), "foot") self.reset() self.top = urwid.Frame(urwid.AttrMap(self.form, 'body'), footer=self.footer) if debug: from pycopia import logwindow widgets.DEBUG = logwindow.DebugLogWindow()
Example #7
Source File: sncli.py From sncli with MIT License | 6 votes |
def log_timeout(self, loop, arg): self.log_lock.acquire() self.log_alarms -= 1 if self.log_alarms == 0: self.gui_footer_log_clear() self.logs = [] else: # for some reason having problems with this being empty? if len(self.logs) > 0: self.logs.pop(0) log_pile = [] for l in self.logs: log_pile.append(urwid.AttrMap(urwid.Text(l), 'log')) if self.verbose: self.gui_footer_log_set(log_pile) self.log_lock.release()
Example #8
Source File: view_note.py From sncli with MIT License | 6 votes |
def get_note_content_as_list(self): lines = [] if not self.key: return lines if self.old_note: for l in self.old_note['content'].split('\n'): lines.append( urwid.AttrMap(urwid.Text(l.replace('\t', ' ' * self.tabstop)), 'note_content_old', 'note_content_old_focus')) else: for l in self.note['content'].split('\n'): lines.append( urwid.AttrMap(urwid.Text(l.replace('\t', ' ' * self.tabstop)), 'note_content', 'note_content_focus')) lines.append(urwid.AttrMap(urwid.Divider('-'), 'default')) return lines
Example #9
Source File: view_help.py From sncli with MIT License | 6 votes |
def create_color_help_lines(self): lines = [ urwid.AttrMap(urwid.Text(''), 'help_header', 'help_focus') ] lines.append(urwid.AttrMap(urwid.Text(' Colors'), 'help_header', 'help_focus')) fmap = {} for c in self.config.colors: fmap[re.search('^(.*)(_fg|_bg)$', c).group(1)] = 'help_focus' for c in self.config.colors: lines.append( urwid.AttrMap(urwid.AttrMap( urwid.Text( [ ('help_descr', ('{:>' + str(self.descr_width) + '} ').format(self.config.get_color_descr(c))), ('help_config', ('{:>' + str(self.config_width) + '} ').format('clr_' + c)), (re.search('^(.*)(_fg|_bg)$', c).group(1), "'" + self.config.get_color(c) + "'") ] ), attr_map = None, focus_map = fmap ), 'default', 'help_focus')) return lines
Example #10
Source File: view_help.py From sncli with MIT License | 6 votes |
def get_status_bar(self): cur = -1 total = 0 if len(self.body.positions()) > 0: cur = self.focus_position total = len(self.body.positions()) status_title = \ urwid.AttrMap(urwid.Text('Help', wrap='clip'), 'status_bar') status_index = \ ('pack', urwid.AttrMap(urwid.Text(' ' + str(cur + 1) + '/' + str(total)), 'status_bar')) return \ urwid.AttrMap(urwid.Columns([ status_title, status_index ]), 'status_bar')
Example #11
Source File: widgets.py From pycopia with Apache License 2.0 | 6 votes |
def build(self): header = urwid.Pile([ urwid.AttrMap(urwid.Text("Edit Interface"), "formhead"), urwid.AttrMap(urwid.Text("Arrow keys navigate, Enter to select form button. Type into other fields."), "formhead"), urwid.Divider(), ]) formstack = [] for groupname, group in [ (None, ("name", "alias", "ifindex", "description")), ("Network Address", ("ipaddr",)), ("Media Access Address", ("macaddr", "vlan")), ("Extra Info", ("interface_type", "mtu", "speed")), ("Administrative", ("status",)), ("Associations", ("network", "equipment", "parent", "subinterfaces")), ]: if groupname: formstack.append(self.build_divider(groupname)) for colname in group: colmd = self.metadata[colname] wid = self.build_input(colmd, getattr(self.row, colmd.colname)) formstack.append(wid) formstack.append(self.get_form_buttons()) listbox = urwid.ListBox(urwid.SimpleListWalker(formstack)) return urwid.Frame(urwid.AttrMap(listbox, 'body'), header=header)
Example #12
Source File: widgets.py From pycopia with Apache License 2.0 | 6 votes |
def build(self): header = urwid.Pile([ urwid.AttrMap(urwid.Text("Create Corporation"), "formhead"), urwid.AttrMap(urwid.Text( "Arrow keys navigate," "Owner is optional, it serves as a lock on the environment. " "Usually you should leave it as None."), "formhead"), urwid.Divider(), ]) formstack = [] for colname in ("name", "address", "country", "contact", "notes"): colmd = self.metadata[colname] wid = self.build_input(colmd) formstack.append(wid) formstack.append(self.get_form_buttons(create=True)) listbox = urwid.ListBox(urwid.SimpleListWalker(formstack)) return urwid.Frame(urwid.AttrMap(listbox, 'body'), header=header)
Example #13
Source File: widgets.py From pycopia with Apache License 2.0 | 6 votes |
def build(self): header = urwid.Pile([ urwid.AttrMap(urwid.Text("Edit {}".format(self.modelclass.__name__)), "formhead"), urwid.AttrMap(urwid.Text("Arrow keys navigate, " "Enter to select form button. Tab to switch to header." "Type into other fields."), "formhead"), AM(urwid.Button("Copy from...", on_press=self._create_copy_input), "selectable", "butfocus"), urwid.Divider(), ]) formstack = [] for colname in ("name", "owner"): colmd = self.metadata[colname] wid = self.build_input(colmd, getattr(self.row, colmd.colname)) formstack.append(wid) colmd = self.metadata["attributes"] wid = self.build_attribute_input(colmd, getattr(self.row, colmd.colname)) formstack.append(wid) # test equipment colmd = self.metadata["testequipment"] tewid = self.build_testequipment_input(colmd, getattr(self.row, "testequipment")) formstack.append(tewid) # common buttons formstack.append(self.get_form_buttons()) listbox = urwid.ListBox(urwid.SimpleListWalker(formstack)) return urwid.Frame(urwid.AttrMap(listbox, 'body'), header=header)
Example #14
Source File: widgets.py From pycopia with Apache License 2.0 | 6 votes |
def build(self): header = urwid.Pile([ urwid.AttrMap(urwid.Text("Create Equipment"), "formhead"), urwid.AttrMap(urwid.Text("Arrow keys navigate, Enter to select form button. Type into other fields."), "formhead"), urwid.Divider(), ]) formstack = [] for groupname, group in [ (None, ("model", "name", "serno")), ("Localization", ("language",)), ("Asset management", ("owner", "location", "sublocation", "vendor")), ("Automation", ("account",)), ("structural relationship", ('parent',)), ("Addtional Info", ("comments",)), ]: if groupname: formstack.append(self.build_divider(groupname)) for colname in group: colmd = self.metadata[colname] wid = self.build_input(colmd) formstack.append(wid) data = self.get_default_data(["active", "addeddate"]) formstack.append(self.get_form_buttons(data, create=True)) listbox = urwid.ListBox(urwid.SimpleListWalker(formstack)) return urwid.Frame(urwid.AttrMap(listbox, 'body'), header=header)
Example #15
Source File: views.py From zulip-terminal with Apache License 2.0 | 6 votes |
def __init__(self, controller: Any, question: Any, success_callback: Callable[[], bool]): self.controller = controller self.success_callback = success_callback yes = urwid.Button('Yes', self.exit_popup_yes) no = urwid.Button('No', self.exit_popup_no) yes._w = urwid.AttrMap(urwid.SelectableIcon( 'Yes', 4), None, 'selected') no._w = urwid.AttrMap(urwid.SelectableIcon( 'No', 4), None, 'selected') display_widget = urwid.GridFlow([yes, no], 3, 5, 1, 'center') wrapped_widget = urwid.WidgetWrap(display_widget) prompt = urwid.LineBox( urwid.ListBox( urwid.SimpleFocusListWalker( [question, urwid.Divider(), wrapped_widget] ))) urwid.Overlay.__init__(self, prompt, self.controller.view, align="left", valign="top", width=self.controller.view.LEFT_WIDTH + 1, height=8)
Example #16
Source File: ui.py From sen with MIT License | 6 votes |
def run(self): """ prompt for text input. """ # set up widgets leftpart = urwid.Text(self.arguments.prompt_text, align='left') editpart = urwid.Edit(multiline=True, edit_text=self.arguments.initial_text) # build promptwidget edit = urwid.Columns([ ('fixed', len(self.arguments.prompt_text), leftpart), ('weight', 1, editpart), ]) self.ui.prompt_bar = urwid.AttrMap(edit, "main_list_dg") self.ui.reload_footer() self.ui.set_focus("footer") urwid.connect_signal(editpart, "change", run_command_callback, user_args=[self.ui, self.docker_object])
Example #17
Source File: ui.py From sen with MIT License | 6 votes |
def notify_message(self, message, level="info", clear_if_dupl=True, clear_in=CLEAR_NOTIF_BAR_MESSAGE_IN): """ :param message, str :param level: str, {info, error} :param clear_if_dupl: bool, if True, don't display the notification again :param clear_in: seconds, remove the notificantion after some time opens notification popup. """ with self.notifications_lock: if clear_if_dupl and message in self.message_widget_dict.keys(): logger.debug("notification %r is already displayed", message) return logger.debug("display notification %r", message) widget = urwid.AttrMap(urwid.Text(message), "notif_{}".format(level)) return self.notify_widget(widget, message=message, clear_in=clear_in)
Example #18
Source File: base.py From sen with MIT License | 6 votes |
def status_bar(self): columns_list = [] def add_subwidget(markup, color_attr=None): if color_attr is None: w = urwid.AttrMap(urwid.Text(markup), "status_text") else: w = urwid.AttrMap(urwid.Text(markup), color_attr) columns_list.append((len(markup), w)) if self.search_string: add_subwidget("Search: ") add_subwidget(repr(self.search_string)) if self.search_string and self.filter_query: add_subwidget(", ") if self.filter_query: add_subwidget("Filter: ") add_subwidget(repr(self.filter_query)) return columns_list
Example #19
Source File: main.py From bbj with MIT License | 6 votes |
def set_escape_key(self, button, args): mode = args[0] widget = OptionsMenu( urwid.ListBox(urwid.SimpleFocusListWalker([ urwid.Text("Press Enter when done"), urwid.AttrMap(KeyPrompt( self.prefs["edit_escapes"][mode], self.save_escape_key, [mode] ), "opt_prompt")])), **self.frame_theme("Set key for " + mode) ) app.loop.widget = urwid.Overlay( urwid.AttrMap(widget, "30"), app.loop.widget, align=("relative", 50), valign=("relative", 50), width=25, height=5 )
Example #20
Source File: main.py From bbj with MIT License | 6 votes |
def search_prompt(self): if self.mode == "index": callback = self.search_index_callback elif self.mode == "thread": callback = self.search_thread_callback else: return popup = OptionsMenu( urwid.ListBox( urwid.SimpleFocusListWalker([ urwid.Text(("button", "Enter a query:")), urwid.AttrMap(StringPrompt(callback), "opt_prompt"), urwid.Text("Use a blank query to reset the {}.".format(self.mode)) ])), **self.frame_theme()) self.loop.widget = urwid.Overlay( popup, self.loop.widget, align=("relative", 50), valign=("relative", 25 if self.window_split else 50), width=("relative", 40), height=6)
Example #21
Source File: treewidgets.py From pycopia with Apache License 2.0 | 6 votes |
def _construct_connector(self, pos): """ build widget to be used as "connector" bit between the vertical bar between siblings and their respective horizontab bars leading to the arrow tip """ # connector symbol, either L or |- shaped. connectorw = None connector = None if self._walker.next_sibling_position(pos) is not None: # |- shaped if self._arrow_connector_tchar is not None: connectorw = Text(self._arrow_connector_tchar) else: # L shaped if self._arrow_connector_lchar is not None: connectorw = Text(self._arrow_connector_lchar) if connectorw is not None: att = self._arrow_connector_att or self._arrow_att connector = AttrMap(connectorw, att) return connector
Example #22
Source File: widgets.py From pycopia with Apache License 2.0 | 6 votes |
def build(self): menulist = [] # big title bt = urwid.BigText("Storage Editor", urwid.HalfBlock5x4Font()) bt = urwid.Padding(bt, "center", None) # primary tables for editing self.primlist = [TableItemWidget(s) for s in self._PRIMARY_TABLES] for b in self.primlist: urwid.connect_signal(b, 'activate', self._select) pmenu = urwid.GridFlow(self.primlist, 20, 2, 1, "left") # heading blurbs subhead = urwid.AttrMap(urwid.Text("Select an object type to view or edit."), "subhead") supportsubhead = urwid.AttrMap(urwid.Text("Select a supporting object to view or edit."), "subhead") # secondary/support tables self.seclist = [TableItemWidget(s) for s in self._SUPPORT_TABLES] for b in self.seclist: urwid.connect_signal(b, 'activate', self._select) smenu = urwid.GridFlow(self.seclist, 25, 1, 0, "left") divider = urwid.Divider("-", top=1, bottom=1) menulist = [bt, divider, subhead, pmenu, divider, supportsubhead, smenu] listbox = urwid.ListBox(urwid.SimpleListWalker(menulist)) return urwid.Frame(listbox)
Example #23
Source File: interactive.py From screeps_console with MIT License | 6 votes |
def __init__(self, connection_name): try: self.connection_name = connection_name frame = self.getFrame() comp = self.getCommandProcessor() self.loop = urwid.MainLoop(urwid.AttrMap(frame, 'bg'), unhandled_input=comp.onInput, palette=themes['dark']) self.consoleMonitor = ScreepsConsoleMonitor(connection_name, self.consoleWidget, self.listWalker, self.loop) comp.setDisplayWidgets(self.loop, frame, self.getConsole(), self.getConsoleListWalker(), self.getEdit(), self.consoleMonitor) self.loop.run() except KeyboardInterrupt: exit(0)
Example #24
Source File: buttons.py From zulip-terminal with Apache License 2.0 | 6 votes |
def update_widget(self, count_text: str) -> Any: # Note that we don't modify self._caption max_caption_length = (self.width_for_text_and_count - len(count_text)) if len(self._caption) > max_caption_length: caption = (self._caption[:max_caption_length - 1] + '\N{HORIZONTAL ELLIPSIS}') else: caption = self._caption num_extra_spaces = ( self.width_for_text_and_count - len(count_text) - len(caption) ) # NOTE: Generated text does not include space at end self._w = urwid.AttrMap(urwid.SelectableIcon( [' ', self.prefix_character, self.post_prefix_spacing, '{}{}'.format(caption, num_extra_spaces * ' '), ' ', ('unread_count', count_text)], self.width_for_text_and_count + 5), # cursor location self.text_color, 'selected')
Example #25
Source File: ui_elements.py From vpngate-with-proxy with GNU General Public License v2.0 | 6 votes |
def __init__(self, key=None, value=('', '')): self.trigger = key self.yn = value[0] self.yn_but = MyButton([('attention', 'Use proxy: '), self.yn], self.on_change) self.input_addr = urwid.Edit(('attention', u' \N{BULLET} Address : '), edit_text=value[1], wrap='clip') self.input_port = urwid.IntEdit(('attention', u' \N{BULLET} Port : '), default=value[2]) self.input_port.set_wrap_mode('clip') exit_but = urwid.Padding(urwid.Button('OKay'.center(8), self.item_callback), 'center', 12) widgets = [self.yn_but] \ + [urwid.AttrMap(wid, None, 'popbgs') for wid in (self.input_addr, self.input_port, exit_but)] self.pile = urwid.Pile(widgets) fill = urwid.LineBox(urwid.Filler(self.pile)) self.__super.__init__(urwid.AttrWrap(fill, 'popbg')) self.chosen = value
Example #26
Source File: __main__.py From upass with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, caption, callback, user_arg, app): """Initialize a button.""" super(BackButton, self).__init__("") self.caption = caption urwid.connect_signal(self, 'click', callback, user_arg) self._w = urwid.AttrMap(urwid.SelectableIcon( [u'< ', self.caption], 0), 'button', 'button_reversed') app.back_callback = callback app.back_arg = user_arg # h/t Heiko Noordhof @hkoof
Example #27
Source File: main.py From pycopia with Apache License 2.0 | 5 votes |
def build(self): bt = urwid.BigText("Test Case Manager", urwid.HalfBlock5x4Font()) bt = urwid.Padding(bt, "center", None) # Primary functions menulist = [ widgets.MenuItemWidget("Run Test Code", self.do_run), widgets.MenuItemWidget("Run Test Job", self.do_job), ] pmenu = urwid.GridFlow(menulist, 20, 2, 1, "left") # heading blurb subhead = urwid.AttrMap(urwid.Text("Choose your desired activity."), "subhead") divider = urwid.Divider(u"-", top=1, bottom=1) formlist = [bt, divider, subhead, pmenu] listbox = urwid.ListBox(urwid.SimpleListWalker(formlist)) return urwid.Frame(listbox)
Example #28
Source File: __main__.py From upass with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, caption, callback): """Initialize a button.""" super(DirectoryButton, self).__init__("") self.caption = caption urwid.connect_signal(self, 'click', callback, self.caption) self._w = urwid.AttrMap(urwid.SelectableIcon( [u'├ ', self.caption, '/'], 0), 'button', 'button_reversed')
Example #29
Source File: widgets.py From pycopia with Apache License 2.0 | 5 votes |
def __init__(self, name): t = urwid.Text(name) w = urwid.AttrMap(t, 'body', 'focus') urwid.WidgetWrap.__init__(self, w)
Example #30
Source File: __main__.py From upass with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, caption, callback, user_arg=None): """Initialize a button.""" super(ActionButton, self).__init__("") self.caption = caption urwid.connect_signal(self, 'click', callback, user_arg) self._w = urwid.AttrMap(urwid.SelectableIcon( [u'> ', self.caption], 0), 'button', 'button_reversed')