Python kivy.base.EventLoop.ensure_window() Examples

The following are 23 code examples of kivy.base.EventLoop.ensure_window(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module kivy.base.EventLoop , or try the search function .
Example #1
Source File: node.py    From kivy3dgui with MIT License 6 votes vote down vote up
def populate_fbo(self, fbo):
        if not self.has_gui:
            return
        EventLoop.ensure_window()
        if self._update_fbo < 2:
            for obj in self.objs:
                if self.texture_size[0] == -1:
                    self.fbo_widget.size = canvas3d.PICKING_BUFFER_SIZE
                    #self.fbo_widget.size = (512, 512)
                else:
                    self.fbo_widget.size = self.texture_size
                    #self.fbo_widget.size = (512, 512)

                if self.texture_size[0] == -1:
                    self.fbo_widget.fbo.size = canvas3d.PICKING_BUFFER_SIZE
                    #self.fbo_widget.fbo.size  = (512, 512)
                else:
                    self.fbo_widget.fbo.size = self.texture_size
                    #self.fbo_widget.fbo.size = (512, 512)
                obj.texture = self.fbo_widget.fbo.texture
                with self.fbo_widget.fbo:
                    ClearColor(1, 1, 1, 1)
        self.flip_coords = False 
Example #2
Source File: test_codeplace.py    From kivystudio with MIT License 6 votes vote down vote up
def test_tabState(self):
        from kivystudio.components.codeplace import CodePlace, get_tab_from_group

        code_place = CodePlace()
        filename1 = 'test_codeplace.py'
        filename2 = 'test_codeplace1.py'
        code_place.add_code_tab(filename=filename1)
        code_place.add_code_tab(filename=filename2)
        self.render(code_place)

        # ensure widow safely
        EventLoop.ensure_window()

        tab1 = get_tab_from_group(filename1)
        tab2 = get_tab_from_group(filename2)

        self.assertEqual(tab1.state, 'normal')
        self.assertEqual(tab2.state, 'down') 
Example #3
Source File: metrics.py    From Tickeys-linux with MIT License 6 votes vote down vote up
def dpi(self):
        '''Return the DPI of the screen. Depending on the platform, the DPI can
        be taken from the Window provider (Desktop mainly) or from a
        platform-specific module (like android/ios).
        '''
        custom_dpi = environ.get('KIVY_DPI')
        if custom_dpi:
            return float(custom_dpi)

        if platform == 'android':
            import android
            return android.get_dpi()
        elif platform == 'ios':
            import ios
            return ios.get_dpi()

        # for all other platforms..
        from kivy.base import EventLoop
        EventLoop.ensure_window()
        return EventLoop.window.dpi 
Example #4
Source File: metrics.py    From Tickeys-linux with MIT License 6 votes vote down vote up
def density(self):
        '''Return the density of the screen. This value is 1 by default
        on desktops but varies on android depending on the screen.
        '''
        custom_density = environ.get('KIVY_METRICS_DENSITY')
        if custom_density:
            return float(custom_density)

        if platform == 'android':
            import jnius
            Hardware = jnius.autoclass('org.renpy.android.Hardware')
            return Hardware.metrics.scaledDensity
        elif platform == 'ios':
            # 0.75 is for mapping the same density as android tablet
            import ios
            return ios.get_scale() * 0.75
        elif platform == 'macosx':
            from kivy.base import EventLoop
            EventLoop.ensure_window()
            return  EventLoop.window.dpi / 96.

        return 1.0 
Example #5
Source File: metrics.py    From Tickeys-linux with MIT License 6 votes vote down vote up
def dpi(self):
        '''Return the DPI of the screen. Depending on the platform, the DPI can
        be taken from the Window provider (Desktop mainly) or from a
        platform-specific module (like android/ios).
        '''
        custom_dpi = environ.get('KIVY_DPI')
        if custom_dpi:
            return float(custom_dpi)

        if platform == 'android':
            import android
            return android.get_dpi()
        elif platform == 'ios':
            import ios
            return ios.get_dpi()

        # for all other platforms..
        from kivy.base import EventLoop
        EventLoop.ensure_window()
        return EventLoop.window.dpi 
Example #6
Source File: tex_atlas.py    From kb with MIT License 5 votes vote down vote up
def build(self):
        EventLoop.ensure_window()
        return GlslDemo() 
Example #7
Source File: main.py    From kivy-2014 with MIT License 5 votes vote down vote up
def build(self):
        EventLoop.ensure_window()
        EventLoop.window.title = self.title = 'Rockivy | Kivy App Contest 2014'

        if EventLoop.window.__class__.__name__.endswith('Pygame'):
            try:
                # because pygame hates nice cursors
                pygame_set_cursor()
            except:
                pass

        game = Game()
        self.on_start = game.on_start
        return init_ui(game) 
Example #8
Source File: view.py    From pydelhi_mobile with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, **kwargs):
        from kivy.base import EventLoop
        EventLoop.ensure_window()
        self._invalid_scale = True
        self._tiles = []
        self._tiles_bg = []
        self._tilemap = {}
        self._layers = []
        self._default_marker_layer = None
        self._need_redraw_all = False
        self._transform_lock = False
        self.trigger_update(True)
        self.canvas = Canvas()
        self._scatter = MapViewScatter()
        self.add_widget(self._scatter)
        with self._scatter.canvas:
            self.canvas_map = Canvas()
            self.canvas_layers = Canvas()
        with self.canvas:
            self.canvas_layers_out = Canvas()
        self._scale_target_anim = False
        self._scale_target = 1.
        self._touch_count = 0
        self.map_source.cache_dir = self.cache_dir
        Clock.schedule_interval(self._animate_color, 1 / 60.)
        self.lat = kwargs.get("lat", self.lat)
        self.lon = kwargs.get("lon", self.lon)
        super(MapView, self).__init__(**kwargs) 
Example #9
Source File: widget.py    From Tickeys-linux with MIT License 5 votes vote down vote up
def __init__(self, **kwargs):
        # Before doing anything, ensure the windows exist.
        EventLoop.ensure_window()

        # Assign the default context of the widget creation.
        if not hasattr(self, '_context'):
            self._context = get_current_context()

        super(Widget, self).__init__(**kwargs)

        # Create the default canvas if it does not exist.
        if self.canvas is None:
            self.canvas = Canvas(opacity=self.opacity)

        # Apply all the styles.
        if '__no_builder' not in kwargs:
            #current_root = Builder.idmap.get('root')
            #Builder.idmap['root'] = self
            Builder.apply(self)
            #if current_root is not None:
            #    Builder.idmap['root'] = current_root
            #else:
            #    Builder.idmap.pop('root')

        # Bind all the events.
        for argument in kwargs:
            if argument[:3] == 'on_':
                self.bind(**{argument: kwargs[argument]}) 
Example #10
Source File: effectwidget.py    From Tickeys-linux with MIT License 5 votes vote down vote up
def __init__(self, **kwargs):
        # Make sure opengl context exists
        EventLoop.ensure_window()

        self.canvas = RenderContext(use_parent_projection=True,
                                    use_parent_modelview=True)

        with self.canvas:
            self.fbo = Fbo(size=self.size)

        with self.fbo.before:
            PushMatrix()
        with self.fbo:
            ClearColor(0, 0, 0, 0)
            ClearBuffers()
            self._background_color = Color(*self.background_color)
            self.fbo_rectangle = Rectangle(size=self.size)
        with self.fbo.after:
            PopMatrix()

        super(EffectWidget, self).__init__(**kwargs)

        Clock.schedule_interval(self._update_glsl, 0)

        self.bind(size=self.refresh_fbo_setup,
                  effects=self.refresh_fbo_setup,
                  background_color=self._refresh_background_color)

        self.refresh_fbo_setup()
        self._refresh_background_color()  # In case thi was changed in kwargs 
Example #11
Source File: widget.py    From Tickeys-linux with MIT License 5 votes vote down vote up
def __init__(self, **kwargs):
        # Before doing anything, ensure the windows exist.
        EventLoop.ensure_window()

        # Assign the default context of the widget creation.
        if not hasattr(self, '_context'):
            self._context = get_current_context()

        super(Widget, self).__init__(**kwargs)

        # Create the default canvas if it does not exist.
        if self.canvas is None:
            self.canvas = Canvas(opacity=self.opacity)

        # Apply all the styles.
        if '__no_builder' not in kwargs:
            #current_root = Builder.idmap.get('root')
            #Builder.idmap['root'] = self
            Builder.apply(self)
            #if current_root is not None:
            #    Builder.idmap['root'] = current_root
            #else:
            #    Builder.idmap.pop('root')

        # Bind all the events.
        for argument in kwargs:
            if argument[:3] == 'on_':
                self.bind(**{argument: kwargs[argument]}) 
Example #12
Source File: effectwidget.py    From Tickeys-linux with MIT License 5 votes vote down vote up
def __init__(self, **kwargs):
        # Make sure opengl context exists
        EventLoop.ensure_window()

        self.canvas = RenderContext(use_parent_projection=True,
                                    use_parent_modelview=True)

        with self.canvas:
            self.fbo = Fbo(size=self.size)

        with self.fbo.before:
            PushMatrix()
        with self.fbo:
            ClearColor(0, 0, 0, 0)
            ClearBuffers()
            self._background_color = Color(*self.background_color)
            self.fbo_rectangle = Rectangle(size=self.size)
        with self.fbo.after:
            PopMatrix()

        super(EffectWidget, self).__init__(**kwargs)

        Clock.schedule_interval(self._update_glsl, 0)

        self.bind(size=self.refresh_fbo_setup,
                  effects=self.refresh_fbo_setup,
                  background_color=self._refresh_background_color)

        self.refresh_fbo_setup()
        self._refresh_background_color()  # In case thi was changed in kwargs 
Example #13
Source File: view.py    From garden.mapview with MIT License 5 votes vote down vote up
def __init__(self, **kwargs):
        from kivy.base import EventLoop
        EventLoop.ensure_window()
        self._invalid_scale = True
        self._tiles = []
        self._tiles_bg = []
        self._tilemap = {}
        self._layers = []
        self._default_marker_layer = None
        self._need_redraw_all = False
        self._transform_lock = False
        self.trigger_update(True)
        self.canvas = Canvas()
        self._scatter = MapViewScatter()
        self.add_widget(self._scatter)
        with self._scatter.canvas:
            self.canvas_map = Canvas()
            self.canvas_layers = Canvas()
        with self.canvas:
            self.canvas_layers_out = Canvas()
        self._scale_target_anim = False
        self._scale_target = 1.
        self._touch_count = 0
        self.map_source.cache_dir = self.cache_dir
        Clock.schedule_interval(self._animate_color, 1 / 60.)
        self.lat = kwargs.get("lat", self.lat)
        self.lon = kwargs.get("lon", self.lon)
        super(MapView, self).__init__(**kwargs) 
Example #14
Source File: main.py    From kb with MIT License 5 votes vote down vote up
def build(self):
        EventLoop.ensure_window()
        if EventLoop.window.__class__.__name__.endswith('Pygame'):
            try:
                from pygame import mouse

                a, b = pygame_compile_cursor()
                mouse.set_cursor((24, 24), (9, 9), a, b)
            except:
                pass

        self.canvas_widget = CanvasWidget()
        self.canvas_widget.set_color(
            get_color_from_hex('#2980b9'))
        return self.canvas_widget 
Example #15
Source File: backend_kivyagg.py    From garden.matplotlib with MIT License 5 votes vote down vote up
def build(self):
        EventLoop.ensure_window()
        layout = FloatLayout()
        if self.figure:
            self.figure.size_hint_y = 0.9
            layout.add_widget(self.figure)
        if self.toolbar:
            self.toolbar.size_hint_y = 0.1
            layout.add_widget(self.toolbar)
        return layout 
Example #16
Source File: main.py    From kb with MIT License 5 votes vote down vote up
def build(self):
        EventLoop.ensure_window()
        return Starfield() 
Example #17
Source File: tex_image.py    From kb with MIT License 5 votes vote down vote up
def build(self):
        EventLoop.ensure_window()
        return GlslDemo() 
Example #18
Source File: basic.py    From kb with MIT License 5 votes vote down vote up
def build(self):
        EventLoop.ensure_window()
        return GlslDemo() 
Example #19
Source File: color.py    From kb with MIT License 5 votes vote down vote up
def build(self):
        EventLoop.ensure_window()
        return GlslDemo() 
Example #20
Source File: test_emulator.py    From kivystudio with MIT License 5 votes vote down vote up
def setUp(self):
        from kivystudio.parser import emulate_file
        from kivystudio.components.emulator_area import emulator_area
        EventLoop.ensure_window()
        self.emulate_file = emulate_file
        self.emulator_area = emulator_area 
Example #21
Source File: view.py    From PyCon-Mobile-App with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, **kwargs):
        from kivy.base import EventLoop
        EventLoop.ensure_window()
        self._invalid_scale = True
        self._tiles = []
        self._tiles_bg = []
        self._tilemap = {}
        self._layers = []
        self._default_marker_layer = None
        self._need_redraw_all = False
        self._transform_lock = False
        self.trigger_update(True)
        self.canvas = Canvas()
        self._scatter = MapViewScatter()
        self.add_widget(self._scatter)
        with self._scatter.canvas:
            self.canvas_map = Canvas()
            self.canvas_layers = Canvas()
        with self.canvas:
            self.canvas_layers_out = Canvas()
        self._scale_target_anim = False
        self._scale_target = 1.
        self._touch_count = 0
        self.map_source.cache_dir = self.cache_dir
        Clock.schedule_interval(self._animate_color, 1 / 60.)
        self.lat = kwargs.get("lat", self.lat)
        self.lon = kwargs.get("lon", self.lon)
        super(MapView, self).__init__(**kwargs) 
Example #22
Source File: backend_kivy.py    From garden.matplotlib with MIT License 5 votes vote down vote up
def build(self):
        EventLoop.ensure_window()
        layout = FloatLayout()
        if self.figure:
            self.figure.size_hint_y = 0.9
            layout.add_widget(self.figure)
        if self.toolbar:
            self.toolbar.size_hint_y = 0.1
            layout.add_widget(self.toolbar)
        return layout 
Example #23
Source File: effectwidget.py    From kivy3dgui with MIT License 4 votes vote down vote up
def __init__(self, **kwargs):
        # Make sure opengl context exists
        EventLoop.ensure_window()
        self.mask_effect = kwargs.get("mask_effect", None)
        self.motion_effect = kwargs.get("motion_effect", None)
        self.fbo_canvas = kwargs.get("motion_effect", None)

        self.canvas = RenderContext(use_parent_projection=True,
                                    use_parent_modelview=True,
                                    with_depthbuffer=True)

        self.size = C_SIZE
        with self.canvas:
            #self._viewport = Rectangle(size=(800,600), pos=self.pos)
            self.fbo = Fbo(size=C_SIZE, with_depthbuffer=True,  compute_normal_mat=True,
                           clear_color=(0.3, 0.3, 0.7, 1))

        with self.fbo.before:
            #Rectangle(size=(800, 600))
            PushMatrix()
            self.fbo_translation = Translate(-self.x, -self.y, 0)
            BindTexture(texture=self.fbo_canvas.texture, index=1)
            BindTexture(texture=self.mask_effect.texture, index=4)
            BindTexture(texture=self.motion_effect.texture, index=5)

        with self.fbo:
            Color(0, 0, 0)
            BindTexture(texture=self.fbo_canvas.texture, index=1)
            BindTexture(texture=self.mask_effect.texture, index=4)
            BindTexture(texture=self.motion_effect.texture, index=5)
            self.fbo_rectangle = Rectangle(size=C_SIZE)
            self._instructions = InstructionGroup()

        with self.fbo.after:
            PopMatrix()
            self.cbs = Callback(self.reset_gl_context)


        super(EffectWidget, self).__init__(**kwargs)
        self.size = C_SIZE

        Clock.schedule_interval(self.update_glsl, 0)

        self._instructions.add(Callback(self.setup_gl_context))

        self.refresh_fbo_setup()
        Clock.schedule_interval(self.update_fbos, 0)