本文整理匯總了Python中urwid.Overlay方法的典型用法代碼示例。如果您正苦於以下問題:Python urwid.Overlay方法的具體用法?Python urwid.Overlay怎麽用?Python urwid.Overlay使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類urwid
的用法示例。
在下文中一共展示了urwid.Overlay方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import urwid [as 別名]
# 或者: from urwid import Overlay [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)
示例2: quote_view_action
# 需要導入模塊: import urwid [as 別名]
# 或者: from urwid import Overlay [as 別名]
def quote_view_action(self, button, message):
"""
Callback function to view a quote from the message object menu.
"""
widget = OptionsMenu(
ActionBox(urwid.SimpleFocusListWalker(self.make_message_body(message))),
**self.frame_theme(">>%d" % message["post_id"])
)
self.loop.widget = urwid.Overlay(
widget, self.loop.widget,
align=("relative", 50),
valign=("relative", 50),
width=("relative", 98),
height=("relative", 60)
)
示例3: search_prompt
# 需要導入模塊: import urwid [as 別名]
# 或者: from urwid import Overlay [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 Overlay [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: test_shards_bug
# 需要導入模塊: import urwid [as 別名]
# 或者: from urwid import Overlay [as 別名]
def test_shards_bug(self):
scrl = Scrollable(
urwid.Pile([urwid.Columns([urwid.Text("text")] * 3)] * 3)
)
sb = ScrollBar(scrl, thumb_char='#', trough_char='|', width=3)
area = urwid.Overlay(urwid.SolidFill("O"), sb, "center", 4, "middle", 5)
self.check(area, (10, 5), cursor_pos=(), text=(
'tetOOOO###',
'xttOOOO###',
'tetOOOO###',
'xttOOOO###',
'tetOOOO|||',
))
# https://github.com/urwid/urwid/issues/226#issuecomment-437176837
示例6: test_overlay
# 需要導入模塊: import urwid [as 別名]
# 或者: from urwid import Overlay [as 別名]
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)))
示例7: test_focus_path
# 需要導入模塊: import urwid [as 別名]
# 或者: from urwid import Overlay [as 別名]
def test_focus_path(self):
# big tree of containers
t = urwid.Text(u'x')
e = urwid.Edit(u'?')
c = urwid.Columns([t, e, t, t])
p = urwid.Pile([t, t, c, t])
a = urwid.AttrMap(p, 'gets ignored')
s = urwid.SolidFill(u'/')
o = urwid.Overlay(e, s, 'center', 'pack', 'middle', 'pack')
lb = urwid.ListBox(urwid.SimpleFocusListWalker([t, a, o, t]))
lb.focus_position = 1
g = urwid.GridFlow([t, t, t, t, e, t], 10, 0, 0, 'left')
g.focus_position = 4
f = urwid.Frame(lb, header=t, footer=g)
self.assertEqual(f.get_focus_path(), ['body', 1, 2, 1])
f.set_focus_path(['footer']) # same as f.focus_position = 'footer'
self.assertEqual(f.get_focus_path(), ['footer', 4])
f.set_focus_path(['body', 1, 2, 2])
self.assertEqual(f.get_focus_path(), ['body', 1, 2, 2])
self.assertRaises(IndexError, lambda: f.set_focus_path([0, 1, 2]))
self.assertRaises(IndexError, lambda: f.set_focus_path(['body', 2, 2]))
f.set_focus_path(['body', 2]) # focus the overlay
self.assertEqual(f.get_focus_path(), ['body', 2, 1])
示例8: _showSearchView
# 需要導入模塊: import urwid [as 別名]
# 或者: from urwid import Overlay [as 別名]
def _showSearchView(self):
self.searchView = SearchViewUrwid(self._callbackSearchFieldChange)
# show search view as an overlay
overlayView = urwid.Overlay(self.searchView.get(),
self.mainFrame,
align="center",
width=("relative", 80),
min_width=80,
valign="middle",
height=("relative", 5),
min_height=5)
self.mainLoop.widget = overlayView
self.inSearchView = True
# internal function that shows the sensor urwid objects given
# by a page index
示例9: openOverlay
# 需要導入模塊: import urwid [as 別名]
# 或者: from urwid import Overlay [as 別名]
def openOverlay(widget, title=None, height=('relative', 50), width=('relative', 50)):
if widget.sizing() == {'flow'}:
height = 'pack'
box = urwid.LineBox(widget, title or widget.title)
overlay = urwid.Overlay(box, mainwidget, 'center', width, 'middle', height)
loop.widget = overlay
示例10: show_pop_up
# 需要導入模塊: import urwid [as 別名]
# 或者: from urwid import Overlay [as 別名]
def show_pop_up(self, to_show: Any) -> None:
double_lines = dict(tlcorner='╔', tline='═', trcorner='╗',
rline='║', lline='║',
blcorner='╚', bline='═', brcorner='╝')
self.loop.widget = urwid.Overlay(
urwid.LineBox(to_show,
to_show.title,
**double_lines),
self.view,
align='center',
valign='middle',
# +2 to both of the following, due to LineBox
width=to_show.width + 2,
height=to_show.height + 2,
)
示例11: show_shutdown_dialog
# 需要導入模塊: import urwid [as 別名]
# 或者: from urwid import Overlay [as 別名]
def show_shutdown_dialog(self, exit_code):
self.frame.body = Overlay(ShutdownView(exit_code),
self.frame.body,
'center', ('relative', 45),
'middle', 'pack')
示例12: overlay_p
# 需要導入模塊: import urwid [as 別名]
# 或者: from urwid import Overlay [as 別名]
def overlay_p(self):
"""
Return True or False if the current widget is an overlay.
"""
return isinstance(self.loop.widget, urwid.Overlay)
示例13: remove_overlays
# 需要導入模塊: import urwid [as 別名]
# 或者: from urwid import Overlay [as 別名]
def remove_overlays(self, *_):
"""
Remove ALL urwid.Overlay objects which are currently covering the base
widget.
"""
while True:
try:
self.loop.widget = self.loop.widget[0]
except:
break
示例14: quote_view_menu
# 需要導入模塊: import urwid [as 別名]
# 或者: from urwid import Overlay [as 別名]
def quote_view_menu(self, button, post_ids):
"""
Receives a list of quote ids and makes a frilly menu to pick one to view.
It retrieves messages objects from the thread and attaches them to a
callback to `quote_view_action`
"""
buttons = []
for pid in post_ids:
try:
message = self.thread["messages"][pid]
if len(post_ids) == 1:
return self.quote_view_action(button, message)
author = self.usermap[message["author"]]
label = [
("button", ">>%d " % pid),
"(",
(str(author["color"]),
author["user_name"]),
")"
]
buttons.append(cute_button(label, self.quote_view_action, message))
except IndexError:
continue # users can submit >>29384234 garbage references
widget = OptionsMenu(
urwid.ListBox(urwid.SimpleFocusListWalker(buttons)),
**self.frame_theme("View a Quote")
)
self.loop.widget = urwid.Overlay(
widget, self.loop.widget,
align=("relative", 50),
valign=("relative", 50),
height=len(buttons) + 3,
width=30
)
示例15: deletion_dialog
# 需要導入模塊: import urwid [as 別名]
# 或者: from urwid import Overlay [as 別名]
def deletion_dialog(self, button, message):
"""
Prompts the user to confirm deletion of an item.
This can delete either a thread or a post.
"""
op = message["post_id"] == 0
buttons = [
urwid.Text(("bold", "Delete this %s?" % ("whole thread" if op else "post"))),
urwid.Divider(),
cute_button(("10" , ">> Yes"), lambda _: [
network.message_delete(message["thread_id"], message["post_id"]),
self.remove_overlays(),
self.index() if op else self.refresh()
]),
cute_button(("30", "<< No"), self.remove_overlays)
]
# TODO: create a central routine for creating popups. this is getting really ridiculous
popup = OptionsMenu(
urwid.ListBox(urwid.SimpleFocusListWalker(buttons)),
**self.frame_theme())
self.loop.widget = urwid.Overlay(
popup, self.loop.widget,
align=("relative", 50),
valign=("relative", 50),
width=30, height=6)