我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用urwid.ExitMainLoop()。
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 []
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 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
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 _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_program(button): raise urwid.ExitMainLoop()
def exit_on_cr(key): if isinstance(key, basestring) and key in 'Q': raise urwid.ExitMainLoop()
def kill_buffer(self): """Kill current buffer""" raise urwid.ExitMainLoop()
def end_loop(self, *unused) -> None: """End main event loop. Raises: urwid.ExitMainLoop: Every time it is called. """ raise urwid.ExitMainLoop()
def exit_loop_on_q_esc(key: str): """End urwid.MainLoop on keypress of 'q' or 'esc'.""" if key in {'q', 'Q', 'esc'}: raise urwid.ExitMainLoop()
def on_clicked_cont(button): ##to call when continue pressed raise urwid.ExitMainLoop()
def menuVAOnly(button): #called when user selects video/audio only in second loop raise urwid.ExitMainLoop()
def keypress(self, size, key): key = super(ConversationListBox, self).keypress(size, key) if key != 'enter': return key name = self.focus[0].edit_text if not name: raise urwid.ExitMainLoop() # replace or add response self.focus.contents[1:] = [(answer(name), self.focus.options())] pos = self.focus_position # add a new question self.body.insert(pos + 1, question()) self.focus_position = pos + 1
def on_exit_clicked(button): raise urwid.ExitMainLoop()
def exit_program(key): raise urwid.ExitMainLoop()
def show_or_exit(key): if key in ('q', 'Q'): raise urwid.ExitMainLoop() txt.set_text(repr(key))
def unhandled_input(self, key): if key == 'f8': self.loop.widget = self.exit_view return True if self.loop.widget != self.exit_view: return if key in ('y', 'Y'): raise urwid.ExitMainLoop() if key in ('n', 'N'): self.loop.widget = self.view return True
def unhandled_input(self, k): # update display of focus directory if k in ('q','Q'): raise urwid.ExitMainLoop()
def exit_program(self, w): raise urwid.ExitMainLoop()
def unhandled_keypress(self, k): """Last resort for keypresses.""" if k == "f5": self.save_file() elif k == "f8": raise urwid.ExitMainLoop() elif k == "delete": # delete at end of line self.walker.combine_focus_with_next() elif k == "backspace": # backspace at beginning of line self.walker.combine_focus_with_prev() elif k == "enter": # start new line self.walker.split_focus() # move the cursor to the new line and reset pref_col self.loop.process_input(["down", "home"]) elif k == "right": w, pos = self.walker.get_focus() w, pos = self.walker.get_next(pos) if w: self.listbox.set_focus(pos, 'above') self.loop.process_input(["home"]) elif k == "left": w, pos = self.walker.get_focus() w, pos = self.walker.get_prev(pos) if w: self.listbox.set_focus(pos, 'below') self.loop.process_input(["end"]) else: return return True