Python kivy.core.window.Window.size() Examples

The following are 30 code examples of kivy.core.window.Window.size(). 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.core.window.Window , or try the search function .
Example #1
Source File: ui.py    From kivy-2014 with MIT License 7 votes vote down vote up
def init_ui(game):
    view = Widget()

    _heading(game, view)
    _notes(game, view)
    _scales(game, view)
    _tuning(game, view)

    view.add_widget(game)

    if platform in ('android', 'ios'):
        from kivy.core.window import Window
        from kivy.uix.scrollview import ScrollView

        app_view = view
        app_view.size = (960, 540)
        app_view.size_hint = (None, None)

        view = ScrollView(size=Window.size)
        view.effect_cls = ScrollEffect
        view.add_widget(app_view)

    return view 
Example #2
Source File: main.py    From kivy-smoothie-host with GNU General Public License v3.0 6 votes vote down vote up
def _list_sdcard_results(self, l):
        # dismiss waiting dialog
        fl = {}
        for f in l:
            f = '/sd/{}'.format(f)
            # if f.endswith('/'):
            #     fl[f[:-1]] = {'size': 0, 'isdir': True}
            # else:
            #     fl[f] = {'size': 0, 'isdir': False}

            # as we can't handle subdirectories yet we do not list them
            if not f.endswith('/'):
                fl[f] = {'size': 0, 'isdir': False}

        # get file to print
        f = FileDialog()
        f.open(title='SD File to print', file_list=fl, cb=self._start_sd_print) 
Example #3
Source File: utils.py    From garden.mapview with MIT License 6 votes vote down vote up
def get_zoom_for_radius(radius_km, lat=None, tile_size=256.):
    """See: https://wiki.openstreetmap.org/wiki/Zoom_levels"""
    radius = radius_km * 1000.
    if lat is None:
        lat = 0.  # Do not compensate for the latitude

    # Calculate the equatorial circumference based on the WGS-84 radius
    earth_circumference = 2. * pi * 6378137. * cos(lat * pi / 180.)

    # Check how many tiles that are currently in view
    nr_tiles_shown = min(Window.size) / dp(tile_size)

    # Keep zooming in until we find a zoom level where the circle can fit inside the screen
    zoom = 1
    while earth_circumference / (2 << (zoom - 1)) * nr_tiles_shown > 2 * radius:
        zoom += 1
    return zoom - 1  # Go one zoom level back 
Example #4
Source File: canvas3d.py    From kivy3dgui with MIT License 6 votes vote down vote up
def get_fixed_points(self, x, y, move=False):
        # _size = EventLoop.window.system_size
        _size = Window.size
        _size = self.size
        if move:
            _x = x / _size[0]
            _y = y / _size[1]
            return _x * self.MPICKING_BUFFER_SIZE[0], _y * self.MPICKING_BUFFER_SIZE[1]

        #_x = x / _size[0]
        #_y = y / _size[1]
        pos = self.parent.pos
        if x < pos[0] or x > pos[0]+_size[0] or y < pos[1] or y > pos[1]+_size[1]:
            return -1, -1

        _x = (x-pos[0]) / _size[0]
        _y = (y-pos[1]) / _size[1]

        return _x * self.MPICKING_BUFFER_SIZE[0], _y * self.MPICKING_BUFFER_SIZE[1] 
Example #5
Source File: main.py    From nowallet with MIT License 6 votes vote down vote up
def show_dialog(self, title, message, qrdata=None, cb=None):
        if qrdata:
            dialog_height = 300
            content = QRCodeWidget(data=qrdata,
                                   size=(dp(150), dp(150)),
                                   size_hint=(None, None))
        else:
            dialog_height = 200
            content = MDLabel(font_style='Body1',
                              theme_text_color='Secondary',
                              text=message,
                              size_hint_y=None,
                              valign='top')
            content.bind(texture_size=content.setter('size'))
        self.dialog = MDDialog(title=title,
                               content=content,
                               size_hint=(.8, None),
                               height=dp(dialog_height),
                               auto_dismiss=False)

        self.dialog.add_action_button(
            "Dismiss", action=cb if cb else lambda *x: self.dialog.dismiss())
        self.dialog.open() 
Example #6
Source File: ui.py    From kivy-2014 with MIT License 6 votes vote down vote up
def _heading(game, view):
    heading = Label(font_name='DroidSans-Regular.ttf', font_size=18,
                    color=HEADING_COLOR, markup=False)
    heading.pos = (ANIM_TOGGLE_SIZE, 500 - PADDING)
    heading.size = (960 - ANIM_TOGGLE_SIZE * 2, HEIGHT)
    view.add_widget(heading)

    def state_change(btn, state):
        game.set_animooted(state == 'down')

    anim_toggle = ToggleButton(background_normal='media/chkbox.png',
                               background_down='media/chkbox_a.png',
                               border=(0, 0, 0, 20), font_size=15,
                               text='Display Animations', state='down',
                               color=HEADING_COLOR, markup=False)
    anim_toggle.pos = (965 - ANIM_TOGGLE_SIZE, 510 - PADDING)
    anim_toggle.size = (ANIM_TOGGLE_SIZE, 30)
    anim_toggle.bind(state=state_change)
    view.add_widget(anim_toggle)

    game._heading = heading
    game.update_heading() 
Example #7
Source File: backend_kivy.py    From garden.matplotlib with MIT License 6 votes vote down vote up
def get_text_width_height_descent(self, s, prop, ismath):
        '''This method is needed specifically to calculate text positioning
           in the canvas. Matplotlib needs the size to calculate the points
           according to their layout
        '''
        if ismath:
            ftimage, depth = self.mathtext_parser.parse(s, self.dpi, prop)
            w = ftimage.get_width()
            h = ftimage.get_height()
            return w, h, depth
        font = resource_find(prop.get_name() + ".ttf")
        if font is None:
            plot_text = CoreLabel(font_size=prop.get_size_in_points())
        else:
            plot_text = CoreLabel(font_size=prop.get_size_in_points(),
                            font_name=prop.get_name())
        plot_text.text = six.text_type("{}".format(s))
        plot_text.refresh()
        return plot_text.texture.size[0], plot_text.texture.size[1], 1 
Example #8
Source File: backend_kivy.py    From garden.matplotlib with MIT License 6 votes vote down vote up
def draw_mathtext(self, gc, x, y, s, prop, angle):
        '''Draw the math text using matplotlib.mathtext. The position
           x,y is given in Kivy coordinates.
        '''
        ftimage, depth = self.mathtext_parser.parse(s, self.dpi, prop)
        w = ftimage.get_width()
        h = ftimage.get_height()
        texture = Texture.create(size=(w, h))
        if _mpl_ge_1_5:
            texture.blit_buffer(ftimage.as_rgba_str()[0][0], colorfmt='rgba',
                                bufferfmt='ubyte')
        else:
            texture.blit_buffer(ftimage.as_rgba_str(), colorfmt='rgba',
                                bufferfmt='ubyte')
        texture.flip_vertical()
        with self.widget.canvas:
            Rectangle(texture=texture, pos=(x, y), size=(w, h)) 
Example #9
Source File: viewer.py    From kivy-smoothie-host with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, comms=None, **kwargs):
        super(GcodeViewerScreen, self).__init__(**kwargs)
        self.app = App.get_running_app()
        self.last_file_pos = None
        self.canv = InstructionGroup()
        self.bind(pos=self._redraw, size=self._redraw)
        self.last_target_layer = 0
        self.tx = 0
        self.ty = 0
        self.scale = 1.0
        self.comms = comms
        self.twod_mode = self.app.is_cnc
        self.rval = 0.0 
Example #10
Source File: main.py    From kivy-smoothie-host with GNU General Public License v3.0 6 votes vote down vote up
def window_request_close(self, win):
        if self.desktop_changed:
            # if the desktop changed we reset the window size and pos
            if self.config.get('UI', 'screen_size') != 'none':
                self.config.set('UI', 'screen_size', 'auto')
            if self.config.get('UI', 'screen_pos') != 'none':
                self.config.set('UI', 'screen_pos', 'auto')

            self.config.write()

        elif self.is_desktop == 2 or self.is_desktop == 3:
            if self.config.get('UI', 'screen_size') != 'none':
                # Window.size is automatically adjusted for density, must divide by density when saving size
                self.config.set('UI', 'screen_size', "{}x{}".format(int(Window.size[0] / Metrics.density), int(Window.size[1] / Metrics.density)))

            if self.config.get('UI', 'screen_pos') != 'none':
                self.config.set('UI', 'screen_pos', "{},{}".format(Window.top, Window.left))
                Logger.info('SmoothieHost: close Window.size: {}, Window.top: {}, Window.left: {}'.format(Window.size, Window.top, Window.left))

            self.config.write()

        return False 
Example #11
Source File: MapCanvas.py    From hexTap with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def add_tile_map(self, tile_map):
        for tile in tile_map.tiles:
            if tile.player:
                px = tile.player.x
                py = tile.player.y
                break
        self.tile_map = tile_map
        self.tile_map.pos = (-px + Window.size[0] / 2, -py + Window.size[1] / 2)
        self.add_widget(self.tile_map) 
Example #12
Source File: theming.py    From Blogs-Posts-Tutorials with MIT License 5 votes vote down vote up
def __init__(self, **kwargs):
        super(ThemeManager, self).__init__(**kwargs)
        self.rec_shadow = Atlas('{}rec_shadow.atlas'.format(images_path))
        self.rec_st_shadow = Atlas('{}rec_st_shadow.atlas'.format(images_path))
        self.quad_shadow = Atlas('{}quad_shadow.atlas'.format(images_path))
        self.round_shadow = Atlas('{}round_shadow.atlas'.format(images_path))
        Clock.schedule_once(lambda x: self.on_theme_style(0, self.theme_style))
        self._determine_device_orientation(None, Window.size)
        Window.bind(size=self._determine_device_orientation) 
Example #13
Source File: generalelements.py    From Snu-Photo-Manager with GNU Lesser General Public License v3.0 5 votes vote down vote up
def get_converted_frame(self):
        if self.first_frame:
            frame = self.first_frame
            self.first_frame = None
        else:
            self.player.set_pause(False)
            frame = None
            while not frame:
                frame, value = self.player.get_frame(force_refresh=False)
                if value == 'eof':
                    return None
            self.player.set_pause(True)
        self.frame_number = self.frame_number + 1
        if self.max_frames:
            if self.frame_number > self.max_frames:
                return None
        frame_image = frame[0]
        frame_size = frame_image.get_size()
        frame_converter = SWScale(frame_size[0], frame_size[1], frame_image.get_pixel_format(), ofmt='rgb24')
        new_frame = frame_converter.scale(frame_image)
        image_data = bytes(new_frame.to_bytearray()[0])
        image = Image.frombuffer(mode='RGB', size=(frame_size[0], frame_size[1]), data=image_data, decoder_name='raw')
        #for some reason, video frames are read upside-down? fix it here...
        image = image.transpose(PIL.Image.FLIP_TOP_BOTTOM)
        if image.mode != 'RGB':
            image = image.convert('RGB')
        image = self.adjust_image(image, preview=False)
        return [image, frame[1]] 
Example #14
Source File: generalelements.py    From Snu-Photo-Manager with GNU Lesser General Public License v3.0 5 votes vote down vote up
def reset_cropper(self, setup=False):
        """Updates the position and size of the cropper overlay object."""

        if self.cropper:
            texture_size = self.get_texture_size()
            texture_top_edge = texture_size[0]
            texture_right_edge = texture_size[1]
            texture_bottom_edge = texture_size[2]
            texture_left_edge = texture_size[3]

            texture_width = (texture_right_edge - texture_left_edge)
            #texture_height = (texture_top_edge - texture_bottom_edge)

            divisor = self.original_width / texture_width
            top_edge = texture_top_edge - (self.crop_top / divisor)
            bottom_edge = texture_bottom_edge + (self.crop_bottom / divisor)
            left_edge = texture_left_edge + (self.crop_left / divisor)
            right_edge = texture_right_edge - (self.crop_right / divisor)
            width = right_edge - left_edge
            height = top_edge - bottom_edge

            self.cropper.pos = [left_edge, bottom_edge]
            self.cropper.size = [width, height]
            if setup:
                self.cropper.max_resizable_width = width
                self.cropper.max_resizable_height = height 
Example #15
Source File: generalelements.py    From Snu-Photo-Manager with GNU Lesser General Public License v3.0 5 votes vote down vote up
def get_texture_size(self):
        """Returns a list of the texture size coordinates.
        Returns:
            List of numbers: [Top edge, Right edge, Bottom edge, Left edge]
        """

        left_edge = (self.size[0] / 2) - (self.norm_image_size[0] / 2)
        right_edge = left_edge + self.norm_image_size[0]
        bottom_edge = (self.size[1] / 2) - (self.norm_image_size[1] / 2)
        top_edge = bottom_edge + self.norm_image_size[1]
        return [top_edge, right_edge, bottom_edge, left_edge] 
Example #16
Source File: generalelements.py    From Snu-Photo-Manager with GNU Lesser General Public License v3.0 5 votes vote down vote up
def on_texture(self, instance, value):
        if value is not None:
            self.texture_size = list(value.size)
        if self.mirror:
            self.texture.flip_horizontal() 
Example #17
Source File: generalelements.py    From Snu-Photo-Manager with GNU Lesser General Public License v3.0 5 votes vote down vote up
def _load_fullsize(self):
        app = App.get_running_app()
        if not self.lowmem:
            low_memory = to_bool(app.config.get("Settings", "lowmem"))
        else:
            low_memory = True
        if not low_memory:
            #load a screen-sized image instead of full-sized to save memory
            if os.path.splitext(self.source)[1].lower() == '.bmp':
                #default image loader messes up bmp files, use pil instead
                self._coreimage = ImageLoaderPIL(self.source)
            else:
                self._coreimage = KivyImage(source=self.source)
        else:
            #load and rescale image
            original_image = Image.open(self.source)
            image = original_image.copy()
            original_image.close()
            resize_width = Window.size[0]
            if image.size[0] > resize_width:
                width = int(resize_width)
                height = int(resize_width * (image.size[1] / image.size[0]))
                if width < 10:
                    width = 10
                if height < 10:
                    height = 10
                image = image.resize((width, height))
            if image.mode != 'RGB':
                image = image.convert('RGB')
            image_bytes = BytesIO()
            image.save(image_bytes, 'jpeg')
            image_bytes.seek(0)
            self._coreimage = CoreImage(image_bytes, ext='jpg')

        self.texture = self._coreimage.texture
        if self.mirror:
            self.texture.flip_horizontal() 
Example #18
Source File: main.py    From hexTap with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def new_game(self):
        if use_ads:
            revmob.show_popup()
        self.content.clear_widgets()
        self.content.add_widget(Image(source='assets/graphics/ui/loading.png', size=Window.size, allow_stretch=True))
        Clock.schedule_once(self.post_splash) 
Example #19
Source File: ui.py    From kivy-2014 with MIT License 5 votes vote down vote up
def _add_widgets(view, label, widgets, line, size):
    y = line * HEIGHT + (line + 1) * PADDING

    label.pos = (PADDING, y)
    label.size = (LABEL_SIZE, HEIGHT)
    view.add_widget(label)

    for i, w in enumerate(widgets):
        w.pos = (LABEL_SIZE + i * size + (i + 1) * PADDING, y)
        w.size = (size, HEIGHT)
        view.add_widget(w) 
Example #20
Source File: MapCanvas.py    From hexTap with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def build_map_tiles(self):
        return HexScatter(self.hex_tiles, self.difficulty, self.soundsOption, self.musicOption,
                          size=[18 * 120 + 1080, 22 * 120 + 1920], pos=[0, 0],
                          auto_bring_to_front=False) 
Example #21
Source File: imuview.py    From RaceCapture_App with GNU General Public License v3.0 5 votes vote down vote up
def _setup_object(self):

        self.clear_widgets()
        if is_ios():  # TODO enable this when iOS bug is resolved
            return

        shader_file = resource_find(os.path.join('resource', 'models', 'shaders.glsl'))
        obj_path = resource_find(self.model_path)

        self.renderer = Renderer(shader_file=shader_file)
        scene = Scene()
        camera = PerspectiveCamera(15, 1, 1, 1000)
        loader = OBJLoader()
        obj = loader.load(obj_path)

        scene.add(*obj.children)
        for obj in scene.children:
            obj.pos.x = self.position_x
            obj.pos.y = self.position_y
            obj.pos.z = self.position_z
            obj.rotation.x = self.rotation_x
            obj.rotation.y = self.rotation_y
            obj.rotation.z = self.rotation_z
            obj.material.specular = .85, .85, .85
            obj.material.color = 1.0, 1.0, 1.0
            obj.material.diffuse = 0.5, 0.5, 0.5
            obj.material.transparency = 1.0
            obj.material.intensity = 0.5
            self.imu_obj = obj
            # obj.material.shininess = 1.0

        self.renderer.render(scene, camera)
        self.renderer.bind(size=self._adjust_aspect)
        Clock.schedule_once(lambda dt: self.add_widget(self.renderer)) 
Example #22
Source File: imuview.py    From RaceCapture_App with GNU General Public License v3.0 5 votes vote down vote up
def _adjust_aspect(self, instance, value):
        rsize = self.renderer.size
        width = max(1, rsize[0])
        height = max(1, rsize[1])
        if height == 0:
            return
        self.renderer.camera.aspect = width / float(height)
        self.size_scaling = 1 / float(dp(1))  # width /  (width * height) / (Window.size[0] * Window.size[1]) 
Example #23
Source File: kivytoast.py    From RaceCapture_App with GNU General Public License v3.0 5 votes vote down vote up
def on_texture_size(self, instance, size):
        self.size = map(lambda i: i * 1.3, size)
        if not self._bound:
            Window.bind(on_resize=self._align)
            self._bound = True
        self._align(None, Window.size[0], Window.size[1]) 
Example #24
Source File: kivytoast.py    From RaceCapture_App with GNU General Public License v3.0 5 votes vote down vote up
def _align(self, win, width, height):
        self.x = (width - self.width) / 2.0
        if self._center_on:
            self.y = self._center_on.y + self._center_on.size[1] * 0.1
        else:
            self.y = height * 0.1 
Example #25
Source File: main.py    From kivy-smoothie-host with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, **kwargs):
        super(MainWindow, self).__init__(**kwargs)
        self.app = App.get_running_app()
        self._trigger = Clock.create_trigger(self.async_get_display_data)
        self._q = queue.Queue()
        self.config = self.app.config
        self.last_path = self.config.get('General', 'last_gcode_path')
        self.paused = False
        self.last_line = 0

        # print('font size: {}'.format(self.ids.log_window.font_size))
        # Clock.schedule_once(self.my_callback, 2) # hack to overcome the page layout not laying out initially 
Example #26
Source File: tabs.py    From Blogs-Posts-Tutorials with MIT License 5 votes vote down vote up
def build(self):
            from kivy.core.window import Window
            Window.size = (540, 720)
            # self.theme_cls.theme_style = 'Dark'

            return Builder.load_string("""
#:import Toolbar kivymd.toolbar.Toolbar
BoxLayout:
    orientation:'vertical'
    Toolbar:
        id: toolbar
        title: 'Page title'
        background_color: app.theme_cls.primary_color
        left_action_items: [['menu', lambda x: '']]
        right_action_items: [['search', lambda x: ''],['more-vert',lambda x:'']]
    MDTabbedPanel:
        id: tab_mgr
        tab_display_mode:'icons'
        
        MDTab:
            name: 'music' 
            text: "Music" # Why are these not set!!!
            icon: "playlist-audio"
            MDLabel:
                font_style: 'Body1'
                theme_text_color: 'Primary'
                text: "Here is my music list :)"
                halign: 'center'
        MDTab:
            name: 'movies'
            text: 'Movies'
            icon: "movie"
             
            MDLabel:
                font_style: 'Body1'
                theme_text_color: 'Primary'
                text: "Show movies here :)"
                halign: 'center'
     
        
""") 
Example #27
Source File: canvas3d.py    From kivy3dgui with MIT License 5 votes vote down vote up
def create_picking_fbo(self):
        self.picking_fbo = Fbo(size=self.MPICKING_BUFFER_SIZE,
                               with_depthbuffer=True,
                               compute_normal_mat=True,
                               clear_color=(0.0, 0.0, 0.0, 0.0))


        self.picking_fbo.shader.source = resource_find('./kivy3dgui/gles2.0/shaders/selection.glsl') 
Example #28
Source File: viewer.py    From kivy-smoothie-host with GNU General Public License v3.0 5 votes vote down vote up
def start_cursor(self, x, y):
        tx, ty = self.transform_to_wpos(x, y)
        label = CoreLabel(text="{:1.2f},{:1.2f}".format(tx, ty))
        label.refresh()
        texture = label.texture
        px, py = (x, y)
        with self.ids.surface.canvas.after:
            Color(0, 0, 1, mode='rgb', group='cursor_group')
            self.crossx = [
                Rectangle(pos=(px, 0), size=(1, self.height), group='cursor_group'),
                Rectangle(pos=(0, py), size=(self.width, 1), group='cursor_group'),
                Line(circle=(px, py, 20), group='cursor_group'),
                Rectangle(texture=texture, pos=(px - texture.size[0] / 2, py - 40), size=texture.size, group='cursor_group')
            ] 
Example #29
Source File: viewer.py    From kivy-smoothie-host with GNU General Public License v3.0 5 votes vote down vote up
def build(self):
            Window.size = (1024, 768)
            self.sm = ScreenManager()
            self.sm.add_widget(StartScreen(name='start'))
            self.sm.add_widget(GcodeViewerScreen(name='gcode'))
            self.sm.add_widget(ExitScreen(name='main'))
            self.sm.current = 'gcode'

            level = LOG_LEVELS.get('debug') if len(sys.argv) > 2 else LOG_LEVELS.get('info')
            Logger.setLevel(level=level)
            # logging.getLogger().setLevel(logging.DEBUG)
            return self.sm 
Example #30
Source File: backend_kivy.py    From garden.matplotlib with MIT License 5 votes vote down vote up
def handle_clip_rectangle(self, gc, x, y):
        '''It checks whether the point (x,y) collides with any already
           existent stencil. If so it returns the index position of the
           stencil it collides with. if the new clip rectangle bounds are
           None it draws in the canvas otherwise it finds the correspondent
           stencil or creates a new one for the new graphics instructions.
           The point x,y is given in matplotlib coordinates.
        '''
        x = self.widget.x + x
        y = self.widget.y + y
        collides = self.collides_with_existent_stencil(x, y)
        if collides > -1:
            return collides
        new_bounds = gc.get_clip_rectangle()
        if new_bounds:
            x = self.widget.x + int(new_bounds.bounds[0])
            y = self.widget.y + int(new_bounds.bounds[1])
            w = int(new_bounds.bounds[2])
            h = int(new_bounds.bounds[3])
            collides = self.collides_with_existent_stencil(x, y)
            if collides == -1:
                cliparea = StencilView(pos=(x, y), size=(w, h))
                self.clip_rectangles.append(cliparea)
                self.widget.add_widget(cliparea)
                return len(self.clip_rectangles) - 1
            else:
                return collides
        else:
            return -2