本文整理汇总了Python中urwid.ListBox方法的典型用法代码示例。如果您正苦于以下问题:Python urwid.ListBox方法的具体用法?Python urwid.ListBox怎么用?Python urwid.ListBox使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urwid
的用法示例。
在下文中一共展示了urwid.ListBox方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import ListBox [as 别名]
def __init__(self, topics_btn_list: List[Any], view: Any,
stream_button: Any) -> None:
self.view = view
self.log = urwid.SimpleFocusListWalker(topics_btn_list)
self.topics_btn_list = topics_btn_list
self.stream_button = stream_button
self.focus_index_before_search = 0
self.list_box = urwid.ListBox(self.log)
self.topic_search_box = PanelSearchBox(self,
'SEARCH_TOPICS',
self.update_topics)
self.header_list = urwid.Pile([self.stream_button,
urwid.Divider('─'),
self.topic_search_box])
super().__init__(self.list_box, header=urwid.LineBox(
self.header_list, tlcorner='─', tline='', lline='',
trcorner='─', blcorner='─', rline='',
bline='─', brcorner='─'
))
self.search_lock = threading.Lock()
示例2: resolve_action
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import ListBox [as 别名]
def resolve_action(self, p_action_str, p_size=None):
"""
Checks whether action specified in p_action_str is "built-in" or
contains topydo command (i.e. starts with 'cmd') and forwards it to
proper executing methods.
p_size should be specified for some of the builtin actions like 'up' or
'home' as they can interact with urwid.ListBox.keypress or
urwid.ListBox.calculate_visible.
"""
if p_action_str.startswith(('cmd ', 'cmdv ')):
prefix, cmd = p_action_str.split(' ', 1)
execute_signal = get_execute_signal(prefix)
if '{}' in cmd:
self._execute_on_selected(cmd, execute_signal)
else:
urwid.emit_signal(self, execute_signal, cmd)
else:
self.execute_builtin_action(p_action_str, p_size)
示例3: search_prompt
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import ListBox [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)
示例4: formatting_help
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import ListBox [as 别名]
def formatting_help(self, *_):
"""
Pops a help window for formatting directives.
"""
# we can "recycle" the server's formatting abilities to
# use the same syntax for the help text itself
message = network.fake_message(
"\n\n".join(format_help), format="sequential")
widget = OptionsMenu(
urwid.ListBox(urwid.SimpleFocusListWalker(app.make_message_body(message, True))),
**self.frame_theme("Formatting Help")
)
va = 5 if self.window_split else 50
vh = 45 if self.window_split else 75
app.loop.widget = urwid.Overlay(
widget, app.loop.widget,
align=("relative", 50),
valign=("relative", va),
width=self.prefs["max_text_width"],
height=("relative", vh)
)
示例5: set_escape_key
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import ListBox [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
)
示例6: build
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import ListBox [as 别名]
def build(self):
wlist = []
addnew = urwid.Button("Add")
urwid.connect_signal(addnew, 'click', self._add_new_option)
addnew = urwid.AttrWrap(addnew, 'selectable', 'butfocus')
wlist.append(addnew)
for attrib in getattr(self.row, self.metadata.colname): # list-like attribute
entry = ListEntry(urwid.Columns(
[(30, urwid.Text(str(attrib.type))),
urwid.Text(unicode(attrib.value).encode("utf-8"))]))
entry.attrname = attrib.type.name
urwid.connect_signal(entry, 'activate', self._edit_option)
urwid.connect_signal(entry, 'delete', self._delete)
wlist.append(entry)
listbox = urwid.ListBox(urwid.SimpleFocusListWalker(wlist))
return urwid.BoxAdapter(urwid.LineBox(listbox), max(7, len(wlist)+2))
示例7: build
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import ListBox [as 别名]
def build(self):
environments = db.get_environment_names()
reports = [None] + db.get_report_names()
self._envsel = widgets.ListScrollSelector(environments)
self._repsel = widgets.ListScrollSelector(reports)
self._tclist = urwid.SimpleListWalker([])
butcols = urwid.Columns([
("pack", urwid.Text("environment:")),
AM(self._envsel, "selectable", "butfocus"),
("pack", urwid.Text("report:")),
AM(self._repsel, "selectable", "butfocus"),
], dividechars=2)
header = urwid.Pile([
AM(urwid.Text("Select environment, report, and set options. Use Tab to switch to environment selector. Selected:"), "subhead"),
urwid.BoxAdapter(urwid.ListBox(self._tclist), 2),
butcols,
])
body = self._build_test_selector(False)
return urwid.Frame(body, header=header, focus_part="body")
示例8: _create_relation_input
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import ListBox [as 别名]
def _create_relation_input(self):
choices = dict(models.get_choices(self.session, self.modelclass, self.metadata.colname, None))
addnew = urwid.Button("Add New")
urwid.connect_signal(addnew, 'click', self._add_new_related)
# Cancel
canc = urwid.Button("Cancel")
urwid.connect_signal(canc, 'click', self._cancel)
butcol = urwid.Columns([AM(addnew, "buttn", "buttnf"), AM(canc, "buttn", "buttnf")])
wlist = [butcol]
if self.metadata.nullable:
entry = ListEntry(urwid.Text("None (remove)"))
urwid.connect_signal(entry, 'activate', self._single_select)
wlist.append(entry)
for pk, cname in choices.items():
entry = ListEntry(urwid.Text(cname))
urwid.connect_signal(entry, 'activate', self._single_select, pk)
wlist.append(entry)
listbox = urwid.ListBox(urwid.SimpleListWalker(wlist))
return urwid.BoxAdapter(urwid.LineBox(listbox), 9)
示例9: build
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import ListBox [as 别名]
def build(self):
wlist = []
addnew = urwid.Button("Add")
urwid.connect_signal(addnew, 'click', self._add_new_attribute)
addnew = urwid.AttrWrap(addnew, 'selectable', 'butfocus')
wlist.append(addnew)
for attrib in getattr(self.row, self.metadata.colname): # list-like attribute
entry = ListEntry(urwid.Columns(
[(30, urwid.Text(str(attrib.type))),
urwid.Text(unicode(attrib.value).encode("utf-8"))]))
entry.attrname = attrib.type.name
urwid.connect_signal(entry, 'activate', self._edit_attribute)
urwid.connect_signal(entry, 'delete', self._delete)
wlist.append(entry)
listbox = urwid.ListBox(urwid.SimpleFocusListWalker(wlist))
return urwid.BoxAdapter(urwid.LineBox(listbox), max(7, len(wlist)+2))
# edit attrib
示例10: _delete_ok
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import ListBox [as 别名]
def _delete_ok(self, dlg, listentry):
listbox = self._w.contents[1][0].base_widget
assert type(listbox) is urwid.ListBox
listbox.body.remove(listentry)
urwid.disconnect_signal(dlg, 'ok', self._delete_ok, listentry)
urwid.disconnect_signal(dlg, 'cancel', self._delete_cancel, listentry)
del self._oldw
try:
self.session.delete(listentry.testequipment)
self.session.commit()
except:
ex, val, tb = sys.exc_info()
self.session.rollback()
DEBUG(ex.__name__, val)
self._emit("message", "{}: {}".format(ex.__name__, val))
listentry.testequipment = None
urwid.disconnect_signal(listentry, 'activate', self._edit_testequipment)
urwid.disconnect_signal(listentry, 'delete', self._delete_testequipment)
示例11: _add_complete
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import ListBox [as 别名]
def _add_complete(self, form, pkval=None):
urwid.disconnect_signal(form, 'popform', self._add_complete)
if pkval is not None:
intf = self.session.query(models.Interface).get(pkval)
if intf.name in self.equipmentrow.interfaces:
self._emit("message", "Interface with that name already exists. Not adding.")
else:
self.equipmentrow.interfaces.set(intf)
try:
self.session.commit()
except:
ex, val, tb = sys.exc_info()
self.session.rollback()
DEBUG(ex.__name__, val)
self._emit("message", "{}: {}".format(ex.__name__, val))
else:
listbox = self._w.contents[1][0].base_widget
assert type(listbox) is urwid.ListBox
entry = self._get_intf_entry(intf)
listbox.body.append(entry)
form._emit("popform")
示例12: _build_list
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import ListBox [as 别名]
def _build_list(self):
choices = get_related_choices(self.session, self.modelclass, self.metadata, None)
#listbox.body.remove(listentry)
#choices.update(self.currentvalue)
wlist = []
# current = self.currentvalue
# for pk, cobj in choices.items():
# if pk in current:
# but = urwid.CheckBox(str(cobj), state=True)
# else:
# but = urwid.CheckBox(str(cobj), state=False)
# urwid.connect_signal(but, 'change', self._multi_select, (pk, cobj))
# wlist.append(but)
# return urwid.ListBox(urwid.SimpleListWalker(wlist))
示例13: set_y_label
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import ListBox [as 别名]
def set_y_label(self, y_label):
if not y_label:
text = urwid.Text("1")
pile = urwid.Pile([urwid.ListBox([text])])
self.y_label = ('fixed', 1, pile)
return
str_y_label = [str(i) for i in y_label]
y_label_nums = str_y_label[1:]
y_list_walker = [(1, urwid.ListBox([urwid.Text(str_y_label[0])]))]
for num in y_label_nums:
y_list_walker = [urwid.ListBox([urwid.Text(num)])] + y_list_walker
y_list_walker = urwid.Pile(y_list_walker, focus_item=0)
y_scale_len = len(max(str_y_label, key=len))
self.y_label = ('fixed', y_scale_len, y_list_walker)
示例14: playlistitems
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import ListBox [as 别名]
def playlistitems(title):
global listitems
bt_sv = urwid.Button("Save")
urwid.connect_signal(bt_sv, 'click', showmenu)
bt_ca = urwid.Button("Cancel")
urwid.connect_signal(bt_ca, 'click', showmenu)
bt_sa = urwid.Button("Select all")
urwid.connect_signal(bt_sa, 'click', select_all)
bt_da = urwid.Button("Deselect all")
urwid.connect_signal(bt_da, 'click', deselect_all)
footer = urwid.Columns([bt_sv, bt_sa, bt_da, bt_ca], 1)
items = []
for item in playlist_names:
items.append(urwid.CheckBox(item['name'], is_selected(item['id']), on_state_change=checkbox_callback, user_data=item['id']))
start.original_widget = TabFrame(urwid.ListBox(urwid.SimpleListWalker(items)), header=urwid.Text("Select Playlists"), footer=footer, focus_part='body')
# main menu button handler
示例15: setup_widgets
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import ListBox [as 别名]
def setup_widgets(self):
self.intro_frame = urwid.LineBox(
urwid.Filler(
urwid.Text(('body_text', self.INTRO_MESSAGE.format("")), align=urwid.CENTER),
valign=urwid.MIDDLE,
)
)
self.frame = urwid.Frame(
body=self.intro_frame,
footer=urwid.Text(
[self.FOOTER_START, ('heartbeat_inactive', self.HEARTBEAT_ICON)],
align=urwid.CENTER
)
)
self.loop = urwid.MainLoop(
urwid.AttrMap(self.frame, 'body_text'),
unhandled_input=show_or_exit,
palette=PALETTE,
)
self.list_walker = urwid.SimpleListWalker(self.message_list)
self.list_box = urwid.ListBox(self.list_walker)
urwid.connect_signal(self.list_walker, "modified", self.item_focused)