GithubHelp home page GithubHelp logo

kivywindowsize's Introduction

KivyWindowSize

Method for using the config facility for saving and restoring the window size and position on Linux, Windows and Mac. The application will open initially at a default position. After closing the app the window position and size will be saved. The next time the application is started it will be in the previous size and location.

The App class provides the on_stop event. This is described as:

Event handler for the on_stop event which is fired when the application has 
finished running (i.e. the window is about to be closed).

On MSFT Windows, the values of Window.top and Window.left are NOT valid when the App.on_stop() event happens, but the size is valid.

The Kivy Window class instance has an event called, on_request_close(), this is called when the window close has been request, but prior to the window close.

Fired when the event loop wants to close the window, or if the escape key is pressed and exit_on_escape is True. 
If a function bound to this event returns True, the window will not be closed. 
If the the event is triggered because of the keyboard escape key, the keyword argument source is dispatched 
along with a value of keyboard to the bound functions.

The size and position values are valid here. I am capturing the size and position data at this event and writing them into the config file at App.on_stop().

Key Learnings: Windows Size and Position are not valid at on_stop(). The window size and position is not correct at this time so these value must be captured earlier. The Kivy Window object has an event, on_request_close, binding to this event I can consistently capture size and position. This has been verified on Windows and Linux.

Needed to use configparser and Config.set() prior to loading Kivy.app I needed to use python's config object to access the .ini file so I could set the Window Size and position prior to loading Kivy.app. Without doing this, a blank window would draw as defined by the Kivy settings, then jump to the place defined in on_start.

The Window event on_draw is called on resize and position change on Windows but not Linux. On Linux on_draw is only called on resize

Window size is effected by Metrics.density The window size is automatically adjusted based on Metrics.density on macOS machines. When saving the window size to the .ini file, the Window.size must be divided by Metrics.density. If this not done, and metrics.density == 2, for example, the window size will double each time the program is opened.

Note: This is a simple test program. There are 2 text input fields, no validation is done on the input. Integers must be entered for proper operation. Enter the desired window size and press the button, and the window will resize. On some machines the the kivy metric dp() will result in the same size, on other machines (Mac for example) the size will be different.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.