python类AsyncioEventLoop()的实例源码

asyncio_socket_server.py 文件源码 项目:Adwear 作者: Uberi 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def demo1():
    """Plain old urwid app.  Just happens to be run atop asyncio as the event
    loop.

    Note that the clock is updated using the asyncio loop directly, not via any
    of urwid's facilities.
    """
    main_widget = build_widgets()

    urwid_loop = urwid.MainLoop(
        main_widget,
        event_loop=urwid.AsyncioEventLoop(loop=loop),
        unhandled_input=unhandled,
    )
    urwid_loop.run()


# -----------------------------------------------------------------------------
# Demo 2
asyncio_socket_server.py 文件源码 项目:Adwear 作者: Uberi 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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()
__init__.py 文件源码 项目:stellarmagnate 作者: abadger 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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', ''),),)
test_event_loops.py 文件源码 项目:Adwear 作者: Uberi 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def setUp(self):
            self.evl = urwid.AsyncioEventLoop()
main.py 文件源码 项目:Discurses 作者: topisani 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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()


问题


面经


文章

微信
公众号

扫码关注公众号