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

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

项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def main():
    palette = [
        ('body','black','dark cyan', 'standout'),
        ('foot','light gray', 'black'),
        ('key','light cyan', 'black', 'underline'),
        ('title', 'white', 'black',),
        ]

    footer_text = [
        ('title', "Fibonacci Set Viewer"), "    ",
        ('key', "UP"), ", ", ('key', "DOWN"), ", ",
        ('key', "PAGE UP"), " and ", ('key', "PAGE DOWN"),
        " move view  ",
        ('key', "Q"), " exits",
        ]

    def exit_on_q(input):
        if input in ('q', 'Q'):
            raise urwid.ExitMainLoop()

    listbox = urwid.ListBox(FibonacciWalker())
    footer = urwid.AttrMap(urwid.Text(footer_text), 'foot')
    view = urwid.Frame(urwid.AttrWrap(listbox, 'body'), footer=footer)
    loop = urwid.MainLoop(view, palette, unhandled_input=exit_on_q)
    loop.run()
项目: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 []
项目:wsstat    作者:Fitblip    | 项目源码 | 文件源码
def __init__(self, client):
        self.client = client

        self.screen = urwid.raw_display.Screen()
        # self.screen = self.DummyScreen()

        self.frame = urwid.Frame(
            client.default_view,
            footer=urwid.Text("", align='center'),
        )

        self.client.frame = self.frame

        self.urwid_loop = urwid.MainLoop(
            self.frame,
            screen=self.screen,
            palette=palette,
            event_loop=self.FixedAsyncLoop(loop=client.loop),
            unhandled_input=client.handle_keypresses,
            pop_ups=True
        )
项目:scum    作者:CCareaga    | 项目源码 | 文件源码
def display(self):
        # this method starts the main loop and such
        self.loop = urwid.MainLoop(self.pile,
                                   self.palette,
                                   handle_mouse = False,
                                   unhandled_input = self.keypress,
                                   pop_ups = True)
        self.loop.screen.set_terminal_properties(colors=256)
        self.register_palette()

        self.term.main_loop = self.loop
        try:
            self.loop.run()
        except:
            return 'failure'

        with open(TABS_PATH, 'a') as f:
            f.write(str(self.layout))

        return 'exit'
项目:screeps_console    作者:screepers    | 项目源码 | 文件源码
def __init__(self, connection_name):
        try:
            self.connection_name = connection_name
            frame = self.getFrame()
            comp = self.getCommandProcessor()
            self.loop = urwid.MainLoop(urwid.AttrMap(frame, 'bg'),
                                        unhandled_input=comp.onInput,
                                        palette=themes['dark'])

            self.consoleMonitor = ScreepsConsoleMonitor(connection_name,
                                                        self.consoleWidget,
                                                        self.listWalker,
                                                        self.loop)

            comp.setDisplayWidgets(self.loop,
                                   frame,
                                   self.getConsole(),
                                   self.getConsoleListWalker(),
                                   self.getEdit(),
                                   self.consoleMonitor)
            self.loop.run()
        except KeyboardInterrupt:
            exit(0)
项目:bbj    作者:desvox    | 项目源码 | 文件源码
def __init__(self):
        self.prefs = bbjrc("load")

        self.mode = None
        self.thread = None
        self.usermap = {}
        self.window_split = False
        self.last_pos = None

        # these can be changed and manipulated by other methods
        self.walker = urwid.SimpleFocusListWalker([])
        self.box = ActionBox(self.walker)
        self.body = urwid.AttrMap(
            urwid.LineBox(
                self.box,
                title=self.prefs["frame_title"],
                **frame_theme()),
            "default"
        )

        self.loop = urwid.MainLoop(
            urwid.Frame(self.body),
            palette=colormap,
            handle_mouse=self.prefs["mouse_integration"])
项目: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()
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def connection_made(self, transport):
        print("Got a client!")
        self.transport = transport

        # StreamReader is super convenient here; it has a regular method on our
        # end (feed_data), and a coroutine on the other end that will
        # faux-block until there's data to be read.  We could also just call a
        # method directly on the screen, but this keeps the screen somewhat
        # separate from the protocol.
        self.reader = asyncio.StreamReader(loop=loop)
        screen = AsyncScreen(self.reader, transport)

        main_widget = build_widgets()
        self.urwid_loop = urwid.MainLoop(
            main_widget,
            event_loop=urwid.AsyncioEventLoop(loop=loop),
            screen=screen,
            unhandled_input=unhandled,
        )

        self.urwid_loop.start()
项目:ChatMaster3000    作者:pkrll    | 项目源码 | 文件源码
def __init__(self):
        """
            Initializes the application and starts the event loop.

            Note:
                Before anything else, the __preliminaries() method will be called,
                setting up the client factory.
        """
        self.__preliminaries()
        # Initiate the main loop with a splash screen as the first widget.
        # Use defaultPalette defined in globals, and the Twisted reactor loop.
        self.mainLoop = urwid.MainLoop(EmptyFrame("Welcome to ChatMaster 3000", self), defaultPalette, event_loop=urwid.TwistedEventLoop())
        # Put the screen into 256-color mode
        self.mainLoop.screen.set_terminal_properties(colors=256)
        # Show the login screen
        self.__transitionToFrame(LoginFrame, 1)
        self.mainLoop.run()
项目:fuzzinator    作者:renatahodovan    | 项目源码 | 文件源码
def __init__(self, controller, style):
        # Shared objects to help event handling.
        self.events = Queue()
        self.lock = Lock()

        self.view = MainWindow(controller)
        self.screen = raw_display.Screen()
        self.screen.set_terminal_properties(256)

        self.loop = MainLoop(widget=self,
                             palette=style,
                             screen=self.screen,
                             unhandled_input=Tui.exit_handler,
                             pop_ups=True)

        self.pipe = self.loop.watch_pipe(self.update_ui)
        self.loop.set_alarm_in(0.1, Tui.update_timer, self.view.logo.timer)
        super(Tui, self).__init__(self.view)

        connect_signal(self.view.issues_table, 'refresh', lambda source: self.loop.draw_screen())
        connect_signal(self.view.stat_table, 'refresh', lambda source: self.loop.draw_screen())
项目:mongoaudit    作者:Exploit-install    | 项目源码 | 文件源码
def setup_view(self):
        placeholder = urwid.SolidFill()
        self.loop = urwid.MainLoop(
            placeholder, PALETTE, unhandled_input=self.key_handler)
        self.loop.widget = urwid.AttrMap(placeholder, 'bg')
        #self.loop.widget._command_map['tab'] = 'cursor down'
        #self.loop.widget._command_map['shift tab'] = 'cursor up'
        self.loop.screen.set_terminal_properties(colors=256)
        self.cards.welcome()
项目:usolitaire    作者:eliasdorneles    | 项目源码 | 文件源码
def main():
    import argparse
    parser = argparse.ArgumentParser(description=__doc__)
    parser.parse_args()

    app = GameApp()
    loop = urwid.MainLoop(
        urwid.Filler(app.main_layout, valign='top'),
        PALETTE,
        unhandled_input=exit_on_q,
    )
    loop.run()
项目:shirleytoolate    作者:trobanga    | 项目源码 | 文件源码
def run(calendar, server):

    top  = EventWidget(valign='top', calendar=calendar, server=server)    
    loop = urwid.MainLoop(top)
    loop.run()
项目:shirleytoolate    作者:trobanga    | 项目源码 | 文件源码
def start_tui(args):
    txt = urwid.Text(u"Hello World")
    fill = urwid.Filler(txt, "top")
    loop =urwid.MainLoop(fill, unhandled_input=exit_on_q)
    loop.run()
项目:pytest-ui    作者:martinsmid    | 项目源码 | 文件源码
def run(self):
        self.main_loop = urwid.MainLoop(self.w_main, palette=self.palette,
                       unhandled_input=self.unhandled_keypress)
        self.child_pipe = self.main_loop.watch_pipe(self.received_output)

        self.init_test_data()
        logger.debug('Running main urwid loop')
        self.main_loop.run()
项目:stellarmagnate    作者:abadger    | 项目源码 | 文件源码
def __init__(self, pubpen, cli_args):
        super().__init__(pubpen, cli_args)

        # Note: We don't have any extra command line args

        # Windows

        self.title_card = TitleScreen(pubpen)
        self.login_screen = LoginScreen(pubpen)
        self.main_window = MainScreen(pubpen)
        self.root_win = urwid.Frame(urwid.SolidFill(' '))

        # Arrange the widgets

        self.show_title_card()

        # Connect to UI events

        urwid.connect_signal(self.title_card, 'close_title_card', self.show_login_screen)
        urwid.connect_signal(self.login_screen, 'logged_in', self.show_main_window)

        # Setup the main loop

        self.urwid_loop = urwid.MainLoop(self.root_win,
                                         event_loop=urwid.AsyncioEventLoop(loop=self.pubpen.loop),
                                         palette=(('reversed', 'standout', ''),),)
项目:astlog    作者:slsolucije    | 项目源码 | 文件源码
def run(self):
        self.loop = urwid.MainLoop(self.frame, palette, handle_mouse=False,
                                   unhandled_input=self.unhandled_keypress)
        self.loop.set_alarm_in(0, lambda loop, data: self.reload_file())
        try:
            self.loop.run()
        except Exception as e:
            self.loop.stop()
            print(traceback.format_exc())
项目:mongoaudit    作者:stampery    | 项目源码 | 文件源码
def setup_view(self):
        placeholder = urwid.SolidFill()
        self.loop = urwid.MainLoop(
            placeholder, PALETTE, unhandled_input=self.key_handler)
        self.loop.widget = urwid.AttrMap(placeholder, 'bg')
        #self.loop.widget._command_map['tab'] = 'cursor down'
        #self.loop.widget._command_map['shift tab'] = 'cursor up'
        self.loop.screen.set_terminal_properties(colors=256)
        self.cards.welcome()
项目:douban-movie    作者:chishui    | 项目源码 | 文件源码
def run(movies):
    global loop
    list_view = ListView(movies)
    loop = urwid.MainLoop(list_view, palette, unhandled_input=exit_on_q)
    loop.screen.set_terminal_properties(colors=256)
    loop.run()
    return loop.data if hasattr(loop, 'data') else None
项目:Drogo    作者:csrgxtu    | 项目源码 | 文件源码
def loop(self, handle_mouse=False):
        self.eloop=urwid.MainLoop(self, self.PALLETE, handle_mouse=handle_mouse)
        self._eloop_thread=threading.current_thread()
        self.eloop.run()
项目:Drogo    作者:csrgxtu    | 项目源码 | 文件源码
def loop(self, handle_mouse=False):
        self.eloop=urwid.MainLoop(self, self.PALLETE, handle_mouse=handle_mouse)
        self._eloop_thread=threading.current_thread()
        self.eloop.run()
项目:bbj    作者:desvox    | 项目源码 | 文件源码
def wipe_screen(*_):
    """
    A crude hack to repaint the whole screen. I didnt immediately
    see anything to acheive this in the MainLoop methods so this
    will do, I suppose.
    """
    app.loop.stop()
    call("clear", shell=True)
    app.loop.start()
项目:ecs_explorer    作者:firemanphil    | 项目源码 | 文件源码
def __main__():
    MAIN_LOOP = urwid.MainLoop(LAYOUT, PALETTE, unhandled_input=exit_on_cr)
    MAIN_LOOP.run()
项目:papis    作者:alejandrogallo    | 项目源码 | 文件源码
def __init__(self, db=None, cmd=None):
        self.db = papis.database.Database()

        self.header_string = "Papis"
        self.status_string = "q: quit buffer, Q: quit Papis, ?: help"

        self.view = urwid.Frame(urwid.SolidFill())
        self.set_header()
        self.set_status()

        if not cmd:
            cmd = ['search', '']

        if cmd[0] == 'search':
            query = ' '.join(cmd[1:])
            self.buffer = Search(self, query)
        elif cmd[0] == 'bibview':
            query = ' '.join(cmd[1:])
            self.buffer = Bibview(self, query)
        elif cmd[0] == 'help':
            target = None
            if len(cmd) > 1:
                target = cmd[1]
            if isinstance(target, str):
                target = None
            self.buffer = Help(self, target)
        else:
            self.buffer = Help(self)
            self.set_status("Unknown command '%s'." % (cmd[0]))

        self.merge_palette(self.buffer)

        self.view.body = urwid.AttrMap(self.buffer, 'body')

        self.mainloop = urwid.MainLoop(
            self.view,
            self.palette,
            unhandled_input=self.keypress,
            handle_mouse=False,
        )
项目:PyAlertMe    作者:jamesleesaunders    | 项目源码 | 文件源码
def loop(self, handle_mouse=False):
        self.eloop = urwid.MainLoop(self, self.PALLETE, handle_mouse=handle_mouse)
        self._eloop_thread = threading.current_thread()
        self.eloop.run()
项目: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()
项目:mccurse    作者:khardix    | 项目源码 | 文件源码
def select_mod(
    choices: Sequence[Mod],
    header: Optional[str] = None,
    footer: Optional[str] = None,
) -> Optional[Mod]:
    """Present user with a TUI menu and return his choice.

    Keyword arguments:
        choices: The :class:`Mod`s to choose from.
        header: Optional menu heading.
        footer: Optional menu footing.

    Returns:
        The selected mod.
    """

    menu = ModMenu(choices)

    head = urwid.Text(('title', header), align='center') if header else None
    foot = urwid.Text(('description', footer), align='center') if footer else None  # noqa: E501

    if head or foot:
        top = urwid.Frame(menu, head, foot)
    else:
        top = menu

    try:
        colors = curses.tigetnum('colors')
    except curses.error:  # Uninitialized terminal
        colors = 16

    event_loop = urwid.MainLoop(
        top,
        palette=ModMenu.palette,
        unhandled_input=exit_loop_on_q_esc,
    )
    event_loop.screen.set_terminal_properties(colors=colors)
    event_loop.run()

    return menu.chosen
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def main(self):
        self.view, self.exit_view = self.setup_view()
        self.loop = urwid.MainLoop(self.view, self.palette,
            unhandled_input=self.unhandled_input)
        self.loop.run()
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def main(self):
        """Run the program."""

        self.loop = urwid.MainLoop(self.view, self.palette,
            unhandled_input=self.unhandled_input)
        self.loop.run()

        # on exit, write the flagged filenames to the console
        names = [escape_filename_sh(x) for x in get_flagged_names()]
        print " ".join(names)
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def main(self):
        self.loop = urwid.MainLoop(self.view, self.view.palette)
        self.loop.run()
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def main(self):
        self.loop = urwid.MainLoop(self.view, self.palette,
            unhandled_input=self.unhandled_keypress)
        self.loop.run()
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def main(self):
        self.loop = urwid.MainLoop(self.view, self.palette,
            unhandled_input=self.unhandled_keypress)
        self.loop.run()
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def main(self):
        self.loop = urwid.MainLoop(self.view, self.palette, screen=Screen(),
            input_filter=self.input_filter)
        self.loop.run()

        # on exit write the formula and the result to the console
        expression, result = self.get_expression_result()
        print "Paste this expression into a new Column Calculator session to continue editing:"
        print expression
        print "Result:", result
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def create_urwid_mainloop(self):
        evl = urwid.TwistedEventLoop(manage_reactor=False)
        loop = urwid.MainLoop(self.toplevel, screen=self.screen,
                              event_loop=evl,
                              unhandled_input=self.mind.unhandled_key,
                              palette=self.palette)
        self.screen.loop = loop
        loop.run()
        return loop
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def main(self):
        self.view, self.exit_view = self.setup_view()
        self.loop = urwid.MainLoop(self.view, self.palette,
            unhandled_input=self.unhandled_input)
        self.loop.run()
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def main(self):
        """Run the program."""

        self.loop = urwid.MainLoop(self.view, self.palette,
            unhandled_input=self.unhandled_input)
        self.loop.run()

        # on exit, write the flagged filenames to the console
        names = [escape_filename_sh(x) for x in get_flagged_names()]
        print " ".join(names)
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def main(self):
        self.loop = urwid.MainLoop(self.view, self.view.palette)
        self.loop.run()
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def main(self):
        """Run the program."""

        self.loop = urwid.MainLoop(self.view, self.palette,
            unhandled_input=self.unhandled_input)
        self.loop.run()
项目:doubanfm-py    作者:nekocode    | 项目源码 | 文件源码
def _setup_ui(self):
        email = input('???? (Email??): ')
        password = getpass.getpass('????: ')

        api = DoubanFMApi()
        api.login(email, password)
        songs = api.get_redheart_songs()

        # ??
        self.title = urwid.Text('')
        self._update_title()
        divider = urwid.Divider()
        header = urwid.Padding(urwid.Pile([divider, self.title, divider]), left=4, right=4)

        # ????
        index = 0
        for song in songs:
            self.btns.append(SongButton(song, self._on_item_pressed, index))
            index += 1
        self.song_listbox = SongListBox(self.btns)

        # ??
        self.main = urwid.Padding(
            urwid.Frame(self.song_listbox, header=header, footer=divider),
            left=4, right=4)

        # ??????
        urwid.register_signal(
            SongListBox, ['exit', 'stop', 'next_song', 'change_mode'])
        urwid.connect_signal(self.song_listbox, 'exit', self._on_exit)
        urwid.connect_signal(self.song_listbox, 'stop', self.stop_song)
        urwid.connect_signal(self.song_listbox, 'next_song', self.next_song)
        urwid.connect_signal(self.song_listbox, 'change_mode', self.change_mode)

        self.loop = urwid.MainLoop(self.main, palette=self.palette)
        self.loop.screen.set_terminal_properties(colors=256)
项目:terminal-leetcode    作者:chishui    | 项目源码 | 文件源码
def run(self):
        self.loop = urwid.MainLoop(None, palette, unhandled_input=self.keystroke)
        self.show_loading('Log In', 12)
        self.t = Thread(target=self.run_retrieve_home)
        self.t.start()
        try:
            self.loop.run()
        except KeyboardInterrupt:
            self.logger.info('Keyboard interrupt')
        except Exception,e:
            self.logger.exception("Fatal error in main loop")
        finally:
            self.clear_thread()
            sys.exit()
项目:GitChat    作者:shubhodeep9    | 项目源码 | 文件源码
def loop(self, handle_mouse=False):
        self.eloop = urwid.MainLoop(
            self, self.PALLETE, handle_mouse=handle_mouse)
        self._eloop_thread = threading.current_thread()
        self.eloop.run()
项目:s-tui    作者:amanusk    | 项目源码 | 文件源码
def main(self):
        self.loop = MainLoop(self.view, DEFAULT_PALETTE, handle_mouse = self.handle_mouse)
        self.animate_graph()
        try:
            self.loop.run()
        except (ZeroDivisionError):
            logging.debug("Some stat caused divide by zero exception. Exiting")
            self.exit_program()
项目:projects    作者:tiborsimon    | 项目源码 | 文件源码
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()
项目:Discurses    作者:topisani    | 项目源码 | 文件源码
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()
项目:bsod    作者:mobyte0    | 项目源码 | 文件源码
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()
项目:my_ros_tools    作者:groundmelon    | 项目源码 | 文件源码
def __init__(self, output_prefix=None):
        self.exit_message = None

        self.output_prefix = output_prefix

        text_header = (u"Command Generation for 'rosbag record' ")
        buttons = OrderedDict()
        buttons['quit'] = urwid.Button(u"Quit(ESC/q)", self.on_quit)
        buttons['save'] = dialog.PopUpButton(u"Save(F2)",
                                             self.on_save,
                                             prompt_text=u"Input file name:",
                                             default_text=u"record.sh")
        buttons['mark'] = urwid.Button(u"Mark all(F3)", self.on_mark_all)
        buttons['unmark'] = urwid.Button(u"Unmark all(F4)", self.on_unmark_all)
        buttons['refresh'] = urwid.Button(u"Refresh(F5)", self.on_refresh)
        self.buttons = buttons

        # blank = urwid.Divider()

        header = urwid.AttrWrap(urwid.Text(text_header, align='center'), 'header')

        button_bar = urwid.GridFlow(
            [urwid.AttrWrap(btn, 'buttn', 'buttnf')
             for (key, btn) in buttons.iteritems()], 18, 3, 1, 'left')
        status_bar = urwid.AttrWrap(urwid.Text(u""), 'footer')
        footer = urwid.Pile([button_bar, status_bar])

        self.listwalker = urwid.SimpleListWalker(self.create_listbox_from_ros())
        listbox = urwid.ListBox(self.listwalker)
        body = urwid.AttrWrap(listbox, 'body')

        self.frame = urwid.Frame(body=body, header=header, footer=footer)

        self.frame_focus_table = dict()
        self.frame_focus_table[body] = 'footer'
        self.frame_focus_table[footer] = 'body'

        palette = [
            ('body', 'white', 'black', 'standout'),
            ('reverse', 'light gray', 'black'),
            ('header', 'white', 'dark blue', 'bold'),
            ('footer', 'black', 'light gray'),
            ('important', 'dark blue', 'light gray', ('standout', 'underline')),
            ('editfc', 'white', 'dark blue', 'bold'),
            ('editbx', 'light gray', 'dark blue'),
            ('editcp', 'black', 'light gray', 'standout'),
            ('bright', 'dark gray', 'light gray', ('bold', 'standout')),
            ('buttn', 'black', 'light cyan'),
            ('buttnf', 'white', 'dark blue', 'bold'),
            ('popbg', 'white', 'dark gray'),
        ]

        self.show_msg = status_bar.set_text

        screen = urwid.raw_display.Screen()

        self.mainloop = urwid.MainLoop(self.frame, palette, screen,
                                       unhandled_input=self.unhandled, pop_ups=True)

    # UI functions
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def key_test():
    screen = Screen()
    header = urwid.Text("Values from get_input(). Q exits.")
    header = urwid.AttrWrap(header,'header')
    lw = urwid.SimpleListWalker([])
    listbox = urwid.ListBox(lw)
    listbox = urwid.AttrWrap(listbox, 'listbox')
    top = urwid.Frame(listbox, header)

    def input_filter(keys, raw):
        if 'q' in keys or 'Q' in keys:
            raise urwid.ExitMainLoop

        t = []
        a = []
        for k in keys:
            if type(k) == tuple:
                out = []
                for v in k:
                    if out:
                        out += [', ']
                    out += [('key',repr(v))]
                t += ["("] + out + [")"]
            else:
                t += ["'",('key',k),"' "]

        rawt = urwid.Text(", ".join(["%d"%r for r in raw]))

        if t:
            lw.append(
                urwid.Columns([
                    ('weight',2,urwid.Text(t)),
                    rawt])
                )
            listbox.set_focus(len(lw)-1,'above')
        return keys

    loop = urwid.MainLoop(top, [
        ('header', 'black', 'dark cyan', 'standout'),
        ('key', 'yellow', 'dark blue', 'bold'),
        ('listbox', 'light gray', 'black' ),
        ], screen, input_filter=input_filter)

    try:
        old = screen.tty_signal_keys('undefined','undefined',
            'undefined','undefined','undefined')
        loop.run()
    finally:
        screen.tty_signal_keys(*old)
项目:selecta    作者:vindolin    | 项目源码 | 文件源码
def __init__(self, revert_order, remove_bash_prefix, remove_zsh_prefix, regexp, case_sensitive,
                 remove_duplicates, show_hits, infile):

        self.show_hits = show_hits
        self.regexp_modifier = regexp
        self.case_modifier = case_sensitive
        self.remove_bash_prefix = remove_bash_prefix

        self.list_items = []

        if revert_order:
            lines = reversed(infile.readlines())
        else:
            lines = infile

        for line in lines:
            if remove_bash_prefix:
                line = line.split(None, 1)[1].strip()

            if remove_zsh_prefix:
                line = re.split('\s+', line, maxsplit=4)[-1]

            if 'selecta <(history)' not in line:
                if not remove_duplicates or line not in self.list_items:
                    self.list_items.append(line)

        self.list_item_widgets = []

        self.line_count_display = LineCountWidget('')
        self.search_edit = SearchEdit(edit_text='')

        self.modifier_display = urwid.Text('')

        urwid.connect_signal(self.search_edit, 'done', self.edit_done)
        urwid.connect_signal(self.search_edit, 'toggle_case_modifier', self.toggle_case_modifier)
        urwid.connect_signal(self.search_edit, 'toggle_regexp_modifier', self.toggle_regexp_modifier)
        urwid.connect_signal(self.search_edit, 'change', self.edit_change)

        header = urwid.AttrMap(urwid.Columns([
            urwid.AttrMap(self.search_edit, 'input', 'input'),
            self.modifier_display,
            ('pack', self.line_count_display),
        ], dividechars=1, focus_column=0), 'head', 'head')

        self.item_list = urwid.SimpleListWalker(self.list_item_widgets)
        self.listbox = ResultList(self.item_list)

        urwid.connect_signal(self.listbox, 'resize', self.list_resize)

        self.view = urwid.Frame(body=self.listbox, header=header)

        self.loop = urwid.MainLoop(self.view, palette, unhandled_input=self.on_unhandled_input)
        self.loop.screen.set_terminal_properties(colors=256)

        self.line_count_display.update(self.listbox.last_size, len(self.item_list))

        # TODO workaround, when update_list is called directly, the linecount widget gets not updated
        self.loop.set_alarm_in(0.01, lambda *loop: self.update_list(''))

        self.loop.run()
项目:evmlab    作者:holiman    | 项目源码 | 文件源码
def setTrace(self, trace, contexts):
        self.operations = trace
        self.contexts = contexts

        ops_view   = urwid.Text(self.getOp())
        mem_view   = urwid.Text(self.getMem())
        stack_view = urwid.Text(self.getStack())
        trace_view = urwid.Text(self.getTrace())
        source_view = urwid.Text(self.getSource())
        help_view  = urwid.Text(self.getHelp())
        # palettes are currently not used
        palette = [
            ('banner', 'black', 'light gray'),
            ('streak', 'black', 'dark red'),
            ('bg', 'black', 'dark blue'),]
        palette=[
            ('headings', 'white,underline', 'black', 'bold,underline'), # bold text in monochrome mode
            ('body_text', 'dark cyan', 'light gray'),
            ('buttons', 'yellow', 'dark green', 'standout'),
            ('section_text', 'body_text'), # alias to body_text
            ]

        self.ops_view = ops_view
        self.mem_view = mem_view
        self.stack_view = stack_view
        self.trace_view = trace_view
        self.source_view = source_view
        self.help_view = help_view


        top = wrap(urwid.Columns([
                            urwid.Pile([
                                wrap(ops_view,"Op"),
                                wrap(trace_view, "Trace")]
                                ),
                            urwid.Pile([
                                wrap(mem_view,"Memory"),
                                wrap(stack_view, "Stack"),
                                wrap(source_view, "Source"),
                                ])
                    ]),"Retromix")

        horiz = urwid.Pile([top, wrap(help_view,"Help")])
        fill = urwid.Filler(horiz, 'top')

        #self.dbg("Loaded %d operations" % len(self.operations) )

        loop = urwid.MainLoop(fill, palette, unhandled_input=lambda input: self.show_or_exit(input))
        loop.run()