Python urwid.AttrMap() Examples

The following are 30 code examples for showing how to use urwid.AttrMap(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module urwid , or try the search function .

Example 1
Project: sncli   Author: insanum   File: view_help.py    License: MIT License 6 votes vote down vote up
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 2
Project: sncli   Author: insanum   File: view_help.py    License: MIT License 6 votes vote down vote up
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 3
Project: sncli   Author: insanum   File: view_note.py    License: MIT License 6 votes vote down vote up
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 4
Project: sncli   Author: insanum   File: sncli.py    License: MIT License 6 votes vote down vote up
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 5
Project: ec2-gazua   Author: leejaycoke   File: gazua.py    License: MIT License 6 votes vote down vote up
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 6
Project: vpngate-with-proxy   Author: Dragon2fly   File: ui_elements.py    License: GNU General Public License v2.0 6 votes vote down vote up
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 7
Project: zulip-terminal   Author: zulip   File: buttons.py    License: Apache License 2.0 6 votes vote down vote up
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 8
Project: zulip-terminal   Author: zulip   File: views.py    License: Apache License 2.0 6 votes vote down vote up
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 9
Project: screeps_console   Author: screepers   File: interactive.py    License: MIT License 6 votes vote down vote up
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 10
Project: bbj   Author: bbj-dev   File: main.py    License: MIT License 6 votes vote down vote up
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 11
Project: bbj   Author: bbj-dev   File: main.py    License: MIT License 6 votes vote down vote up
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 12
Project: sen   Author: TomasTomecek   File: ui.py    License: MIT License 6 votes vote down vote up
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 13
Project: sen   Author: TomasTomecek   File: ui.py    License: MIT License 6 votes vote down vote up
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 14
Project: sen   Author: TomasTomecek   File: util.py    License: MIT License 6 votes vote down vote up
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 15
Project: sen   Author: TomasTomecek   File: base.py    License: MIT License 6 votes vote down vote up
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 16
Project: pycopia   Author: kdart   File: treewidgets.py    License: Apache License 2.0 6 votes vote down vote up
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 17
Project: pycopia   Author: kdart   File: widgets.py    License: Apache License 2.0 6 votes vote down vote up
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 18
Project: pycopia   Author: kdart   File: widgets.py    License: Apache License 2.0 6 votes vote down vote up
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 19
Project: pycopia   Author: kdart   File: widgets.py    License: Apache License 2.0 6 votes vote down vote up
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 20
Project: pycopia   Author: kdart   File: widgets.py    License: Apache License 2.0 6 votes vote down vote up
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 21
Project: pycopia   Author: kdart   File: widgets.py    License: Apache License 2.0 6 votes vote down vote up
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 22
Project: pycopia   Author: kdart   File: widgets.py    License: Apache License 2.0 6 votes vote down vote up
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 23
Project: pycopia   Author: kdart   File: widgets.py    License: Apache License 2.0 6 votes vote down vote up
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 24
Project: pycopia   Author: kdart   File: widgets.py    License: Apache License 2.0 6 votes vote down vote up
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 25
Project: pycopia   Author: kdart   File: main.py    License: Apache License 2.0 6 votes vote down vote up
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 26
Project: sncli   Author: insanum   File: view_help.py    License: MIT License 5 votes vote down vote up
def create_kb_help_lines(self, header, use):
        lines = [ urwid.AttrMap(urwid.Text(''),
                                'help_header',
                                'help_focus') ]
        lines.append(urwid.AttrMap(urwid.Text(' ' + header),
                                   'help_header',
                                   'help_focus'))
        for c in self.config.keybinds:
            if use not in self.config.get_keybind_use(c):
                continue
            lines.append(
                urwid.AttrMap(urwid.AttrMap(
                    urwid.Text(
                    [
                     ('help_descr',  ('{:>' + str(self.descr_width) + '} ').format(self.config.get_keybind_descr(c))),
                     ('help_config', ('{:>' + str(self.config_width) + '} ').format('kb_' + c)),
                     ('help_value',  "'" + self.config.get_keybind(c) + "'")
                    ]
                    ),
                    attr_map = None,
                    focus_map = {
                                 'help_value'  : 'help_focus',
                                 'help_config' : 'help_focus',
                                 'help_descr'  : 'help_focus'
                                }
                ), 'default', 'help_focus'))
        return lines 
Example 27
Project: sncli   Author: insanum   File: view_help.py    License: MIT License 5 votes vote down vote up
def create_config_help_lines(self):
        lines = [ urwid.AttrMap(urwid.Text(''),
                                'help_header',
                                'help_focus') ]
        lines.append(urwid.AttrMap(urwid.Text(' Configuration'),
                                   'help_header',
                                   'help_focus'))
        for c in self.config.configs:
            if c in [ 'sn_username', 'sn_password' ]: continue
            lines.append(
                urwid.AttrMap(urwid.AttrMap(
                    urwid.Text(
                    [
                     ('help_descr',  ('{:>' + str(self.descr_width) + '} ').format(self.config.get_config_descr(c))),
                     ('help_config', ('{:>' + str(self.config_width) + '} ').format('cfg_' + c)),
                     ('help_value',  "'" + self.config.get_config(c) + "'")
                    ]
                    ),
                    attr_map = None,
                    focus_map = {
                                 'help_value'  : 'help_focus',
                                 'help_config' : 'help_focus',
                                 'help_descr'  : 'help_focus'
                                }
                ), 'default', 'help_focus'))
        return lines 
Example 28
Project: sncli   Author: insanum   File: view_log.py    License: MIT License 5 votes vote down vote up
def update_log(self):
        lines = []
        f = open(self.config.logfile)
        for line in f:
            lines.append(
                urwid.AttrMap(urwid.Text(line.rstrip()),
                                'note_content',
                                'note_content_focus'))
        f.close()
        if self.config.get_config('log_reversed') == 'yes':
            lines.reverse()
        self.body[:] = urwid.SimpleFocusListWalker(lines)
        self.focus_position = 0 
Example 29
Project: sncli   Author: insanum   File: view_titles.py    License: MIT License 5 votes vote down vote up
def get_note_title(self, note):
        return urwid.AttrMap(self.format_title(note),
                             'default',
                             { 'default'            : 'note_focus',
                               'note_title_day'     : 'note_focus',
                               'note_title_week'    : 'note_focus',
                               'note_title_month'   : 'note_focus',
                               'note_title_year'    : 'note_focus',
                               'note_title_ancient' : 'note_focus',
                               'note_date'          : 'note_focus',
                               'note_flags'         : 'note_focus',
                               'note_tags'          : 'note_focus' }) 
Example 30
Project: sncli   Author: insanum   File: view_titles.py    License: MIT License 5 votes vote down vote up
def get_status_bar(self):
        cur   = -1
        total = 0
        if len(self.body.positions()) > 0:
            cur   = self.focus_position
            total = len(self.body.positions())

        hdr = 'Simplenote'

        # include simplenote connection status in header
        hdr += ' (' + self.ndb.simplenote.status + ')'

        if self.search_string != None:
            hdr += ' - Search: ' + self.search_string

        status_title = \
            urwid.AttrMap(urwid.Text(hdr,
                                     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')