def swarm_chosen(button, choice):
try:
copters_chosen = [x+ " \n" for x in SSID_DICT.keys() if SSID_DICT[x] == True]
response = urwid.Text([u'Swarmifying: \n', copters_chosen, u'\n'])
done = urwid.Button(u'Ok')
urwid.connect_signal(done, 'click', exit_program)
main.original_widget = urwid.Filler(urwid.Pile([response,
urwid.AttrMap(done, None, focus_map='reversed')]))
except:
pass
python类Filler()的实例源码
def __init__(self, ui, target=None):
self.ui = ui
self.target = target
if self.target:
tname = self.target.__class__.__name__
self.ui.set_header("Help: " + tname)
else:
self.ui.set_header("Help")
pile = []
if self.target and hasattr(self.target, 'keys'):
pile.append(urwid.Text('%s commands:' % (tname)))
pile.append(urwid.Text(''))
for key, cmd in sorted(self.target.keys.items()):
pile.append(self.row('target', cmd, key))
pile.append(urwid.Text(''))
pile.append(urwid.Text(''))
pile.append(urwid.Text('Global commands:'))
pile.append(urwid.Text(''))
for key, cmd in sorted(self.ui.keys.items()):
pile.append(self.row('ui', cmd, key))
w = urwid.Filler(urwid.Pile(pile))
self.__super.__init__(w)
def chosen_URL(button,choice): #######show url of chosen format #####modify so that it calls axel to dowload the given url ############### called when a particular stream is selected
v_chosen = urwid.Text([u'Video Format :- ', str(choice), u'\n'])
#v_URL = urwid.Text([u'Downloadable URL :- ', str(choice.url), u'\n'])
done = urwid.Button(u'Copy URL to Clipboard')
down = urwid.Button(u'Download using aria')
ext = urwid.Button(u'Exit')
urwid.connect_signal(done, 'click', Copy_exit,choice)
urwid.connect_signal(ext, 'click', exit_program)
urwid.connect_signal(down,'click',Down_aria,choice)
main1.original_widget = urwid.Filler(urwid.Pile([v_chosen,urwid.AttrMap(down, None, focus_map='reversed'),urwid.AttrMap(done, None, focus_map='reversed'),urwid.AttrMap(ext, None, focus_map='reversed')]))
##############################Displaying Video formats definitions########################
def item_chosen(button, choice):
response = urwid.Text([u'You chose ', choice, u'\n'])
done = urwid.Button(u'Ok')
urwid.connect_signal(done, 'click', exit_program)
main.original_widget = urwid.Filler(urwid.Pile([response,
urwid.AttrMap(done, None, focus_map='reversed')]))
def item_chosen(self, button):
response = urwid.Text([u' You chose ', self.caption, u'\n'])
done = MenuButton(u'Ok', exit_program)
response_box = urwid.Filler(urwid.Pile([response, done]))
top.open_box(urwid.AttrMap(response_box, 'options'))
def item_chosen(button):
response = urwid.Text([u'You chose ', button.label, u'\n'])
done = menu_button(u'Ok', exit_program)
top.open_box(urwid.Filler(urwid.Pile([response, done])))
def __init__(self):
close_button = urwid.Button("that's pretty cool")
urwid.connect_signal(close_button, 'click',
lambda button:self._emit("close"))
pile = urwid.Pile([urwid.Text(
"^^ I'm attached to the widget that opened me. "
"Try resizing the window!\n"), close_button])
fill = urwid.Filler(pile)
self.__super.__init__(urwid.AttrWrap(fill, 'popbg'))
def __init__(self):
close_button = urwid.Button("that's pretty cool")
urwid.connect_signal(close_button, 'click',
lambda button:self._emit("close"))
pile = urwid.Pile([urwid.Text(
"^^ I'm attached to the widget that opened me. "
"Try resizing the window!\n"), close_button])
fill = urwid.Filler(pile)
self.__super.__init__(urwid.AttrWrap(fill, 'popbg'))
def __init__(self, text, height, width, body=None):
width = int(width)
if width <= 0:
width = ('relative', 80)
height = int(height)
if height <= 0:
height = ('relative', 80)
self.body = body
if body is None:
# fill space with nothing
body = urwid.Filler(urwid.Divider(),'top')
self.frame = urwid.Frame( body, focus_part='footer')
if text is not None:
self.frame.header = urwid.Pile( [urwid.Text(text),
urwid.Divider()] )
w = self.frame
# pad area around listbox
w = urwid.Padding(w, ('fixed left',2), ('fixed right',2))
w = urwid.Filler(w, ('fixed top',1), ('fixed bottom',1))
w = urwid.AttrWrap(w, 'body')
# "shadow" effect
w = urwid.Columns( [w,('fixed', 2, urwid.AttrWrap(
urwid.Filler(urwid.Text(('border',' ')), "top")
,'shadow'))])
w = urwid.Frame( w, footer =
urwid.AttrWrap(urwid.Text(('border',' ')),'shadow'))
# outermost border area
w = urwid.Padding(w, 'center', width )
w = urwid.Filler(w, 'middle', height )
w = urwid.AttrWrap( w, 'border' )
self.view = w
def test_box_column(self):
c = urwid.Columns([urwid.Filler(urwid.Edit()),urwid.Text('')],
box_columns=[0])
c.keypress((10,), 'x')
c.get_cursor_coords((10,))
c.move_cursor_to_coords((10,), 0, 0)
c.mouse_event((10,), 'foo', 1, 0, 0, True)
c.get_pref_col((10,))
def test_filler(self):
self.wstest(urwid.Filler(urwid.Text("hello")))
def ftest(self, desc, valign, height, maxrow, top, bottom,
min_height=None):
f = urwid.Filler(None, valign, height, min_height)
t, b = f.filler_values((20,maxrow), False)
assert (t,b)==(top,bottom), "%s expected %s but got %s"%(
desc, (top,bottom), (t,b))
def fetest(self, desc, valign, height):
self.assertRaises(urwid.FillerError, lambda:
urwid.Filler(None, valign, height))
def test_repr(self):
repr(urwid.Filler(urwid.Text(u'hai')))
def __init__(self):
title = urwid.AttrWrap(urwid.Text('Help'), 'body')
body = urwid.Text(HelpView.__doc__)
pile = urwid.Pile([title, body])
filler = urwid.Filler(pile)
urwid.Frame.__init__(self, filler)
def select_project(project_list, path_callback):
max_width = len(max(project_list, key=len))
f = ProjectSelector(project_list, 'normal', 'highlighted', 'selected')
def refresh_list(key=''):
if key:
if key in ('delete', 'backspace'):
f.remove_key()
else:
if key in 'abcdefghijklmnopqrstuvwxyz- .0123456789':
f.add_key(key)
s = f.render()
txt.set_text(s)
def exit_on_q(key):
if key.__class__ is not str:
return
if key in ('Q',):
raise urwid.ExitMainLoop()
if key == 'up':
f.up()
if key == 'down':
f.down()
if key == 'enter':
path_callback(f.select())
raise urwid.ExitMainLoop()
key = key.lower()
refresh_list(key)
palette = [
('normal', 'light gray', ''),
('selected', 'yellow, bold', ''),
('highlighted', 'black, bold', 'yellow'),
('quit button', 'light red, bold', ''),
('enter button', 'light green, bold', '')
]
txt = urwid.Text('', align='left')
fill = urwid.Filler(txt)
pad = urwid.Padding(fill, align='center', width=max_width+4)
box = urwid.LineBox(pad, title="Projects")
footer = urwid.Text(['Start typing to search. Use arrow keys to navigate. Press (', ('enter button', 'Enter'), ') to select project. ', 'Press (', ('quit button', 'Q'), ') to exit.'])
frame = urwid.Frame(body=box, footer=footer)
loop = urwid.MainLoop(frame, palette, unhandled_input=exit_on_q)
refresh_list()
loop.run()
def __init__(self, discord_client):
self.discord = discord_client
self.tabs = {}
self.w_tabs = TabSelector(self)
self.frame = urwid.Frame(
urwid.Filler(
urwid.Text(
"????????????????????????????????????\n"
"????????????????????????????????????\n"
"????????????????????????????????????\n"
" v0.2.4\n"
" \n"
" \n"
" < Logging in... Hang tight! > \n"
" --------------------------- \n"
" \ ^__^ \n"
" \ (oo)\_______ \n"
" (__)\ )\/\ \n"
" ||----w | \n"
" || || \n"
" \n"
" \n"
" \n",
align=urwid.CENTER)),
header=self.w_tabs)
HasModal.__init__(self, self.frame)
self.urwid_loop = urwid.MainLoop(
self.w_placeholder,
palette=MainUI.palette,
unhandled_input=lambda key: self._keypress(None, key),
event_loop=urwid.AsyncioEventLoop(loop=self.discord.loop),
pop_ups=True)
def refresh(_loop, _data):
_loop.draw_screen()
_loop.set_alarm_in(2, refresh)
self.urwid_loop.set_alarm_in(0.2, refresh)
self.urwid_loop.start()
def summon():
"""summons the classic bsod"""
sys_info = " {} {} ".format(platform.system(), platform.release())
error2 = "{:02x}".format(random.randint(0, 17)).upper()
error4 = "{:04x}".format(random.randint(0, 4095)).upper()
error8 = "{:08x}".format(random.randint(0, 68719476736)).upper()
message = """
An error has occurred. To continue:
Press Enter to return to {}, or
Press CTRL+ALT+DEL to restart your computer. If you do this,
you will lose any unsaved information in all open applications.
Error: {} : {} : {}
""".format(platform.system(), error2, error4, error8)
end = "Press any key to continue "
bg_map = urwid.AttrMap(urwid.SolidFill(' '), 'bg')
body = urwid.Filler(
urwid.AttrMap(
urwid.Text(message, align='left'),
'text'))
body_text = urwid.Overlay(
body, bg_map,
'center', 63,
'middle', 10,
63, 10)
continue_ln = urwid.AttrMap(
urwid.Edit(end, align='center'),
'text')
title_txt = urwid.AttrMap(
urwid.Text(sys_info, align='center'),
'title')
fill_scrn = urwid.Overlay(
urwid.Filler(title_txt), bg_map,
'center', len(sys_info),
'middle', 1,
len(sys_info), 1)
text_stack = urwid.Filler(urwid.Pile([(1, fill_scrn),
(10, body_text),
('pack', continue_ln)]))
bg_fill = urwid.AttrMap(text_stack, 'bg')
loop = urwid.MainLoop(bg_fill, PALETTE, input_filter=exitscreen)
loop.screen.set_terminal_properties(colors=256)
loop.run()
def setup_view(self):
fonts = urwid.get_all_fonts()
# setup mode radio buttons
self.font_buttons = []
group = []
utf8 = urwid.get_encoding_mode() == "utf8"
for name, fontcls in fonts:
font = fontcls()
if font.utf8_required and not utf8:
rb = self.create_disabled_radio_button(name)
else:
rb = self.create_radio_button(group, name, font,
self.set_font_event)
if fontcls == urwid.Thin6x6Font:
chosen_font_rb = rb
exit_font = font
self.font_buttons.append( rb )
# Create BigText
self.bigtext = urwid.BigText("", None)
bt = SwitchingPadding(self.bigtext, 'left', None)
bt = urwid.AttrWrap(bt, 'bigtext')
bt = urwid.Filler(bt, 'bottom', None, 7)
bt = urwid.BoxAdapter(bt, 7)
# Create chars_avail
cah = urwid.Text("Characters Available:")
self.chars_avail = urwid.Text("", wrap='any')
ca = urwid.AttrWrap(self.chars_avail, 'chars')
chosen_font_rb.set_state(True) # causes set_font_event call
# Create Edit widget
edit = self.create_edit("", "Urwid "+urwid.__version__,
self.edit_change_event)
# ListBox
chars = urwid.Pile([cah, ca])
fonts = urwid.Pile([urwid.Text("Fonts:")] + self.font_buttons,
focus_item=1)
col = urwid.Columns([('fixed',16,chars), fonts], 3,
focus_column=1)
bt = urwid.Pile([bt, edit], focus_item=1)
l = [bt, urwid.Divider(), col]
w = urwid.ListBox(urwid.SimpleListWalker(l))
# Frame
w = urwid.AttrWrap(w, 'body')
hdr = urwid.Text("Urwid BigText example program - F8 exits.")
hdr = urwid.AttrWrap(hdr, 'header')
w = urwid.Frame(header=hdr, body=w)
# Exit message
exit = urwid.BigText(('exit'," Quit? "), exit_font)
exit = urwid.Overlay(exit, w, 'center', None, 'middle', None)
return w, exit
def setup_view(self):
fonts = urwid.get_all_fonts()
# setup mode radio buttons
self.font_buttons = []
group = []
utf8 = urwid.get_encoding_mode() == "utf8"
for name, fontcls in fonts:
font = fontcls()
if font.utf8_required and not utf8:
rb = self.create_disabled_radio_button(name)
else:
rb = self.create_radio_button(group, name, font,
self.set_font_event)
if fontcls == urwid.Thin6x6Font:
chosen_font_rb = rb
exit_font = font
self.font_buttons.append( rb )
# Create BigText
self.bigtext = urwid.BigText("", None)
bt = SwitchingPadding(self.bigtext, 'left', None)
bt = urwid.AttrWrap(bt, 'bigtext')
bt = urwid.Filler(bt, 'bottom', None, 7)
bt = urwid.BoxAdapter(bt, 7)
# Create chars_avail
cah = urwid.Text("Characters Available:")
self.chars_avail = urwid.Text("", wrap='any')
ca = urwid.AttrWrap(self.chars_avail, 'chars')
chosen_font_rb.set_state(True) # causes set_font_event call
# Create Edit widget
edit = self.create_edit("", "Urwid "+urwid.__version__,
self.edit_change_event)
# ListBox
chars = urwid.Pile([cah, ca])
fonts = urwid.Pile([urwid.Text("Fonts:")] + self.font_buttons,
focus_item=1)
col = urwid.Columns([('fixed',16,chars), fonts], 3,
focus_column=1)
bt = urwid.Pile([bt, edit], focus_item=1)
l = [bt, urwid.Divider(), col]
w = urwid.ListBox(urwid.SimpleListWalker(l))
# Frame
w = urwid.AttrWrap(w, 'body')
hdr = urwid.Text("Urwid BigText example program - F8 exits.")
hdr = urwid.AttrWrap(hdr, 'header')
w = urwid.Frame(header=hdr, body=w)
# Exit message
exit = urwid.BigText(('exit'," Quit? "), exit_font)
exit = urwid.Overlay(exit, w, 'center', None, 'middle', None)
return w, exit