Python urwid 模块,ExitMainLoop() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用urwid.ExitMainLoop()

项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
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 []
项目:shirleytoolate    作者:trobanga    | 项目源码 | 文件源码
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()
项目:Drogo    作者:csrgxtu    | 项目源码 | 文件源码
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)
项目:Drogo    作者:csrgxtu    | 项目源码 | 文件源码
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)
项目:bmii    作者:psurply    | 项目源码 | 文件源码
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()
项目:PyAlertMe    作者:jamesleesaunders    | 项目源码 | 文件源码
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)
项目:YtbDwn    作者:praneet95    | 项目源码 | 文件源码
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
项目:my_ros_tools    作者:groundmelon    | 项目源码 | 文件源码
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
项目:mongoaudit    作者:Exploit-install    | 项目源码 | 文件源码
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)
项目:usolitaire    作者:eliasdorneles    | 项目源码 | 文件源码
def exit_on_q(key):
    if key in ('q', 'Q', 'esc'):
        raise urwid.ExitMainLoop()
项目:wsstat    作者:Fitblip    | 项目源码 | 文件源码
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)
项目:sshchan    作者:einchan    | 项目源码 | 文件源码
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()
项目:shirleytoolate    作者:trobanga    | 项目源码 | 文件源码
def keypress(self, size, key):
        """
        Leave without saving, if pressing Esc.
        """
        if key == "esc":
            raise urwid.ExitMainLoop()
        super(EventWidget, self).keypress(size, key)
项目:shirleytoolate    作者:trobanga    | 项目源码 | 文件源码
def exit_on_q(key):
    if key in ('q', 'Q'):
        raise urwid.ExitMainLoop()
项目:pytest-ui    作者:martinsmid    | 项目源码 | 文件源码
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()
项目:pytest-ui    作者:martinsmid    | 项目源码 | 文件源码
def keypress(self, size, key):
        raise urwid.ExitMainLoop()
        if key == 'esc':
            self.escape_method()

        return None
项目:pytest-ui    作者:martinsmid    | 项目源码 | 文件源码
def keypress(self, size, key):
        print 'here'
        raise urwid.ExitMainLoop()
        if key == 'esc':
            self.escape_method()

        return key
项目:pytest-ui    作者:martinsmid    | 项目源码 | 文件源码
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')))
项目:stellarmagnate    作者:abadger    | 项目源码 | 文件源码
def quit_client(*args):
        """Quit the game"""
        raise urwid.ExitMainLoop()
项目:stellarmagnate    作者:abadger    | 项目源码 | 文件源码
def quit(button):
        """End the game"""
        raise urwid.ExitMainLoop()
项目:boartty    作者:openstack    | 项目源码 | 文件源码
def _quit(self, widget=None):
        raise urwid.ExitMainLoop()
项目:Discurses    作者:topisani    | 项目源码 | 文件源码
def quit(widget, size, key):
        widget.urwid_loop.stop()
        raise urwid.ExitMainLoop()
项目:mongoaudit    作者:stampery    | 项目源码 | 文件源码
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)
项目:stig    作者:rndusr    | 项目源码 | 文件源码
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)
项目:stig    作者:rndusr    | 项目源码 | 文件源码
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
项目:stig    作者:rndusr    | 项目源码 | 文件源码
def run(self):
        import urwid
        raise urwid.ExitMainLoop()
项目:screeps_console    作者:screepers    | 项目源码 | 文件源码
def exit(self, comp):
        raise urwid.ExitMainLoop()
项目:bsod    作者:mobyte0    | 项目源码 | 文件源码
def exitscreen(*_):
    """quits the program with a keypress"""
    raise urwid.ExitMainLoop()
项目:douban-movie    作者:chishui    | 项目源码 | 文件源码
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)
项目:douban-movie    作者:chishui    | 项目源码 | 文件源码
def exit_on_q(key):
    if key in ('q', 'Q'):
        raise urwid.ExitMainLoop()
项目:swarm    作者:3drobotics    | 项目源码 | 文件源码
def exit_program(button):
    raise urwid.ExitMainLoop()
项目:ecs_explorer    作者:firemanphil    | 项目源码 | 文件源码
def exit_on_cr(key):
    if isinstance(key, basestring) and key in 'Q':
        raise urwid.ExitMainLoop()
项目:papis    作者:alejandrogallo    | 项目源码 | 文件源码
def kill_buffer(self):
        """Kill current buffer"""
        raise urwid.ExitMainLoop()
项目:mccurse    作者:khardix    | 项目源码 | 文件源码
def end_loop(self, *unused) -> None:
        """End main event loop.

        Raises:
            urwid.ExitMainLoop: Every time it is called.
        """

        raise urwid.ExitMainLoop()
项目:mccurse    作者:khardix    | 项目源码 | 文件源码
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()
项目:YtbDwn    作者:praneet95    | 项目源码 | 文件源码
def on_clicked_cont(button):            ##to call when continue pressed
        raise urwid.ExitMainLoop()
项目:YtbDwn    作者:praneet95    | 项目源码 | 文件源码
def menuVAOnly(button):         #called when user selects video/audio only in second loop
        raise urwid.ExitMainLoop()
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
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
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def exit_program(button):
    raise urwid.ExitMainLoop()
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def on_exit_clicked(button):
    raise urwid.ExitMainLoop()
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def exit_on_q(key):
    if key in ('q', 'Q'):
        raise urwid.ExitMainLoop()
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def exit_program(button):
    raise urwid.ExitMainLoop()
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def exit_program(key):
    raise urwid.ExitMainLoop()
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def exit_on_q(key):
    if key in ('q', 'Q'):
        raise urwid.ExitMainLoop()
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def exit_program(button):
    raise urwid.ExitMainLoop()
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def show_or_exit(key):
    if key in ('q', 'Q'):
        raise urwid.ExitMainLoop()
    txt.set_text(repr(key))
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
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
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def unhandled_input(self, k):
        # update display of focus directory
        if k in ('q','Q'):
            raise urwid.ExitMainLoop()
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def exit_program(self, w):
        raise urwid.ExitMainLoop()
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
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