本文整理汇总了Python中urwid.AttrMap方法的典型用法代码示例。如果您正苦于以下问题:Python urwid.AttrMap方法的具体用法?Python urwid.AttrMap怎么用?Python urwid.AttrMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urwid
的用法示例。
在下文中一共展示了urwid.AttrMap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_status_bar
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import AttrMap [as 别名]
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')
示例2: create_color_help_lines
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import AttrMap [as 别名]
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
示例3: get_note_content_as_list
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import AttrMap [as 别名]
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
示例4: log_timeout
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import AttrMap [as 别名]
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()
示例5: _create_widget
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import AttrMap [as 别名]
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')
示例6: __init__
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import AttrMap [as 别名]
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
示例7: update_widget
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import AttrMap [as 别名]
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')
示例8: __init__
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import AttrMap [as 别名]
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)
示例9: __init__
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import AttrMap [as 别名]
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)
示例10: search_prompt
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import AttrMap [as 别名]
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)
示例11: set_escape_key
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import AttrMap [as 别名]
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
)
示例12: notify_message
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import AttrMap [as 别名]
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)
示例13: run
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import AttrMap [as 别名]
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])
示例14: get_operation_notify_widget
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import AttrMap [as 别名]
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)
示例15: status_bar
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import AttrMap [as 别名]
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