Esempio n. 1
0
    async def __aenter__(self):
        self.set_kivy_config()

        from kivy.core.window import Window
        from kivy.context import Context
        from kivy.clock import ClockBase
        from kivy.factory import FactoryBase, Factory
        from kivy.lang.builder import BuilderBase, Builder

        kivy_eventloop = self.async_lib
        if kivy_eventloop == 'asyncio':
            try:
                import pytest_asyncio
            except ImportError as e:
                raise TypeError(
                    'KIVY_EVENTLOOP is asyncio but "pytest_asyncio" is not '
                    'installed') from e
            async_lib = 'asyncio'
        elif kivy_eventloop == 'trio':
            try:
                import pytest_trio
            except ImportError as e:
                raise TypeError(
                    'KIVY_EVENTLOOP is trio but "pytest_trio" is not '
                    'installed') from e
            async_lib = 'trio'
        else:
            raise TypeError(f'unknown event loop {kivy_eventloop}')

        self._context = context = Context(init=False)
        context['Clock'] = ClockBase(async_lib=async_lib)
        # have to make sure all global kv files are loaded before this because
        # globally read kv files (e.g. on module import) will not be loaded
        # again in the new builder, except if manually loaded, which we don't
        # context['Factory'] = FactoryBase.create_from(Factory)
        # context['Builder'] = BuilderBase.create_from(Builder)
        context.push()

        Window.create_window()
        Window.register()
        Window.initialized = True
        Window.canvas.clear()
        Window.size = self.width, self.height

        from kivy.clock import Clock
        Clock._max_fps = 0
        Clock.init_async_lib(async_lib)
        return self
 def set_async_lib(self, async_lib):
     from kivy.clock import Clock
     if async_lib is not None:
         Clock.init_async_lib(async_lib)
     self.async_sleep = Clock._async_lib.sleep
Esempio n. 3
0
 async def async_run(self, async_lib=None):
     from kivy.clock import Clock
     if async_lib is not None:
         Clock.init_async_lib(async_lib)
     self.async_sleep = Clock._async_lib.sleep
     return await super(UnitKivyApp, self).async_run(async_lib=async_lib)
Esempio n. 4
0
                self.transition.direction = 'down'
            self.current = 'menu'

        elif signal == 'settings':
            self.transition.direction = 'up'
            self.current = 'settings'

    def change_player_name(self, player_id, name):
        if player_id == 0:
            self.get_screen('game').player_1_label.text = name
        else:
            self.get_screen('game').player_2_label.text = name


class WukonGoApp(App):
    controller = Controller()

    def build(self):
        Window.size = (400, 600)
        return self.controller

    async def run(self):
        await self.controller.initialize()
        await self.async_run()


if __name__ == "__main__":
    Clock.init_async_lib('asyncio')
    app = WukonGoApp()
    asyncio.run(app.run())