def input_filter(self, input, raw_input):
if 'q' in input or 'Q' in input:
raise urwid.ExitMainLoop()
# handle other keystrokes
for k in input:
try:
self.wrap_keypress(k)
self.event = None
self.view.footer = None
except CalcEvent, e:
# display any message
self.event = e
self.view.footer = e.widget()
# remove all input from further processing by MainLoop
return []
python类ExitMainLoop()的实例源码
def on_save(self, button):
"""
Save and exit.
"""
vcal = icalendar.Calendar()
event = icalendar.Event()
event['uid'] = self.calendar + str(uuid.uuid1())
# event['dtstart'] = self._datetime_to_ical(datetime.datetime(2016,5,15))
# event['dtend'] = self._datetime_to_ical(datetime.datetime(2016,5,15))
event['summary'] = self.msg.edit_text
vcal.add_component(event)
logging.debug("EventWidget:on_save:vcal: {}".format(vcal.to_ical()))
r = self.server.add_event(vcal.to_ical(), self.calendar)
logging.debug("EventWidget:on_save:add_event: {}".format(r))
raise urwid.ExitMainLoop()
def on_line_entered(self,line):
if self._cmd:
try:
res = self._cmd(line)
except Exception,e:
self.output('Error: %s'%e, 'error')
return
if res==Commander.Exit:
raise urwid.ExitMainLoop()
elif res:
# self.output(str(res))
self.output(res)
else:
if line in ('q','quit','exit'):
raise urwid.ExitMainLoop()
else:
self.output(line)
def on_line_entered(self,line):
if self._cmd:
try:
res = self._cmd(line)
except Exception,e:
self.output('Error: %s'%e, 'error')
return
if res==Commander.Exit:
raise urwid.ExitMainLoop()
elif res:
# self.output(str(res))
self.output(res)
else:
if line in ('q','quit','exit'):
raise urwid.ExitMainLoop()
else:
self.output(line)
def display(self, f):
def handle_input(key):
if key in ('q', 'Q'):
raise urwid.ExitMainLoop()
elif key in ('right', 'j', ' '):
if self.slide_id < len(self.sd) - 1:
self.slide_id += 1
elif key in ('left', 'k'):
if self.slide_id > 0:
self.slide_id -= 1
self.update_display()
self.load_charset()
self.sd = list(yaml.load_all(f))
self.slide_id = 0
self.update_display()
txt = urwid.Text(u"Presenting...")
fill = urwid.Filler(txt, 'bottom')
urwid.MainLoop(fill, unhandled_input=handle_input).run()
def on_line_entered(self, line):
if self._cmd:
try:
res = self._cmd(line)
except Exception, e:
self.output('Error: %s' % e, 'error')
return
if res == Commander.Exit:
raise urwid.ExitMainLoop()
elif res:
self.output(str(res))
else:
if line in ('q', 'quit', 'exit'):
raise urwid.ExitMainLoop()
else:
self.output(line)
def Down_aria(button,choice): ### called when user select download using aria ## it modifys flags which are further used to decide which loop to enter ### modifies "folename" "url" and "comp_command"(command to be executed with aria)
global filename
global comp_command
global downSeconloop
global downThirdloop
global downurl
comp_command = basecommand + "-o " + filename
if str(choice.mediatype) == "normal" :
downSeconloop=1
filename = title + str(choice.resolution)+"." + str(choice.extension)
elif str(choice.mediatype) == "video" :
filename = title + choice.resolution+"." + choice.extension
downThirdloop=1
elif str(choice.mediatype) == "audio" :
filename = title + "." + choice.extension
downThirdloop=1
downurl = urllib.unquote(str(choice.url))
raise urwid.ExitMainLoop()
############################# print basic video info######################## 1st Loop info #################333#####can be done in a function too
rosbag-record-param-generator.py 文件源码
项目:my_ros_tools
作者: groundmelon
项目源码
文件源码
阅读 34
收藏 0
点赞 0
评论 0
def unhandled(self, key):
if key == 'esc' or key == 'q':
raise urwid.ExitMainLoop()
elif key == 'tab':
self.frame.focus_position = self.frame_focus_table[self.frame.focus]
elif key == 'f2':
self.start_save()
elif key == 'f3':
self.do_set_all(True)
elif key == 'f4':
self.do_set_all(False)
elif key == 'f5':
self.do_refresh()
else:
# self.show_msg("Pressed: {}".format(key))
pass
# functional functions
def key_handler(key):
if key in ('q', 'Q', 'esc'):
raise urwid.ExitMainLoop()
elif key == 'ctrl r':
python = sys.executable
os.execl(python, python, *sys.argv)
def exit_on_q(key):
if key in ('q', 'Q', 'esc'):
raise urwid.ExitMainLoop()
def update_urwid(self):
interval = .1
status_line = "{hostname} | Connections: [{current}/{total}] | Total Messages: {message_count} | Messages/Second: {msgs_per_second}/s"
while True:
if self._exiting:
return True
#raise urwid.ExitMainLoop
# Only update things a max of 10 times/second
yield from asyncio.sleep(interval)
# Get the current global message count
global_message_count = int(repr(self.global_message_counter)[6:-1])
self.ring_buffer.append(global_message_count)
currently_connected_sockets = len([x for x in self.sockets.values() if x and not isinstance(x, BaseException) and x.ws.state == OPEN])
self.logger.update_graph_data([self.messages_per_second,])
# Get and update our blinkboard widget
self.blinkboard.generate_blinkers(self.sockets)
# Make the status message
status_message = status_line.format(
hostname=self.websocket_url.netloc,
current=currently_connected_sockets,
total=self.total_connections,
message_count=global_message_count,
msgs_per_second=self.messages_per_second
)
self.frame.footer.set_text(status_message)
def button_press(self, button, data):
"""Generic callback method for buttons (not key-presses!).
@button - button object instance that called the method,
@data - (string) additional data provided by calling button
instance, used to define what action should be taken.
"""
if data in self.config.get_boardlist().keys():
# Board button was pressed.
# If the board was entered from any view other than MOTD
# (e.g. other board view), pop the widget from stack, so
# pressing ESC will return to MOTD.
if not self.motd_flag:
del self.loop.Widget
self.motd_flag = False
self.help_flag = False
self.board.name = data
# Transfer control to BoardView instance.
BoardView(self.loop, self.config, self.board, self)
elif data == "back":
# Clear the help flag, to avoid bugs.
self.help_flag = False
# Go back, restore saved widgets from previous screen.
del self.loop.Widget
# Check if we're on the main screen to avoid bugs.
if self.loop.stack_len == 1:
self.motd_flag = True
elif data == "quit":
# Bai
raise ur.ExitMainLoop()
def keypress(self, size, key):
"""
Leave without saving, if pressing Esc.
"""
if key == "esc":
raise urwid.ExitMainLoop()
super(EventWidget, self).keypress(size, key)
def exit_on_q(key):
if key in ('q', 'Q'):
raise urwid.ExitMainLoop()
def quit(self):
self.pipe_semaphore.set()
if self.runner_process and self.runner_process.is_alive():
self.runner_process.terminate()
logger.log(DEBUG_B, 'releasing semaphore')
raise urwid.ExitMainLoop()
def keypress(self, size, key):
raise urwid.ExitMainLoop()
if key == 'esc':
self.escape_method()
return None
def keypress(self, size, key):
print 'here'
raise urwid.ExitMainLoop()
if key == 'esc':
self.escape_method()
return key
def handle_input(key):
if key in ('q', 'Q'):
print 'exiting on q'
raise urwid.ExitMainLoop()
elif key in ('1'):
main_loop.widget = urwid.LineBox(urwid.Filler(urwid.Text('The second top window', align='right')))
def quit_client(*args):
"""Quit the game"""
raise urwid.ExitMainLoop()
def quit(button):
"""End the game"""
raise urwid.ExitMainLoop()
def _quit(self, widget=None):
raise urwid.ExitMainLoop()
def quit(widget, size, key):
widget.urwid_loop.stop()
raise urwid.ExitMainLoop()
def key_handler(key):
if key in ('q', 'Q', 'esc'):
raise urwid.ExitMainLoop()
elif key == 'ctrl r':
python = sys.executable
os.execl(python, python, *sys.argv)
def _exception_handler(self, loop, context):
exc = context.get('exception')
if exc:
loop.stop()
if not isinstance(exc, urwid.ExitMainLoop):
self._exc_info = exc
else:
loop.default_exception_handler(context)
def run(self):
"""
Start the event loop. Exit the loop when any callback raises
an exception. If ExitMainLoop is raised, exit cleanly.
"""
self._loop.set_exception_handler(self._exception_handler)
self._loop.run_forever()
if self._exc_info:
raise self._exc_info
def run(self):
import urwid
raise urwid.ExitMainLoop()
def exit(self, comp):
raise urwid.ExitMainLoop()
def exitscreen(*_):
"""quits the program with a keypress"""
raise urwid.ExitMainLoop()
def keypress(self, size, key):
global loop
if key is 'enter':
loop.data = self.listbox.get_focus()[0].data
raise urwid.ExitMainLoop()
return urwid.Frame.keypress(self, size, key)
def exit_on_q(key):
if key in ('q', 'Q'):
raise urwid.ExitMainLoop()