Saving and Restoring Window size and position

175 views
Skip to first unread message

Elliot Garbus

unread,
Apr 4, 2019, 11:45:23 PM4/4/19
to Kivy users support
I wanted my program to save its size and position on close, and reopen with the same size and position.
I've learned a few things along the way.  Here is the my sample code, to test this capability: https://github.com/ElliotGarbus/KivyWindowSize

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
Note: This is a simple test program.  There are 2 text input fields, I have not done any validation 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.

I hope this helps somebody.

elvis ian omondi

unread,
Apr 5, 2019, 3:46:08 AM4/5/19
to kivy-...@googlegroups.com

Look at my code on comments .... https://github.com/elvis124/Ask-doctor to see how I have updated my window size ...so that it opens in the same size and position

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+unsubscribe@googlegroups.com.
To post to this group, send email to kivy-...@googlegroups.com.
Visit this group at https://groups.google.com/group/kivy-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/83283f7d-6fbc-4c99-a0c9-b311b6742c90%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Глеб Самойлов

unread,
Apr 5, 2019, 3:52:18 AM4/5/19
to kivy-...@googlegroups.com
OSError: [Errno 49] Can't assign requested address

пт, 5 апр. 2019 г. в 10:46, elvis ian omondi <elvisia...@gmail.com>:

Look at my code on comments .... https://github.com/elvis124/Ask-doctor to see how I have updated my window size ...so that it opens in the same size and position

On 5 Apr 2019 06:45, "Elliot Garbus" <elli...@cox.net> wrote:
I wanted my program to save its size and position on close, and reopen with the same size and position.
I've learned a few things along the way.  Here is the my sample code, to test this capability: https://github.com/ElliotGarbus/KivyWindowSize

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
Note: This is a simple test program.  There are 2 text input fields, I have not done any validation 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.

I hope this helps somebody.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

To post to this group, send email to kivy-...@googlegroups.com.
Visit this group at https://groups.google.com/group/kivy-users.

Elliot Garbus

unread,
Apr 5, 2019, 7:58:01 AM4/5/19
to Kivy users support
Thanks Elvis... looks like your simply going fullscreen!  


On Friday, April 5, 2019 at 12:46:08 AM UTC-7, elvis ian omondi wrote:

Look at my code on comments .... https://github.com/elvis124/Ask-doctor to see how I have updated my window size ...so that it opens in the same size and position

On 5 Apr 2019 06:45, "Elliot Garbus" <elli...@cox.net> wrote:
I wanted my program to save its size and position on close, and reopen with the same size and position.
I've learned a few things along the way.  Here is the my sample code, to test this capability: https://github.com/ElliotGarbus/KivyWindowSize

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
Note: This is a simple test program.  There are 2 text input fields, I have not done any validation 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.

I hope this helps somebody.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

On Friday, April 5, 2019 at 12:46:08 AM UTC-7, elvis ian omondi wrote:

Look at my code on comments .... https://github.com/elvis124/Ask-doctor to see how I have updated my window size ...so that it opens in the same size and position

On 5 Apr 2019 06:45, "Elliot Garbus" <elli...@cox.net> wrote:
I wanted my program to save its size and position on close, and reopen with the same size and position.
I've learned a few things along the way.  Here is the my sample code, to test this capability: https://github.com/ElliotGarbus/KivyWindowSize

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
Note: This is a simple test program.  There are 2 text input fields, I have not done any validation 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.

I hope this helps somebody.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

On Friday, April 5, 2019 at 12:46:08 AM UTC-7, elvis ian omondi wrote:

Look at my code on comments .... https://github.com/elvis124/Ask-doctor to see how I have updated my window size ...so that it opens in the same size and position

On 5 Apr 2019 06:45, "Elliot Garbus" <elli...@cox.net> wrote:
I wanted my program to save its size and position on close, and reopen with the same size and position.
I've learned a few things along the way.  Here is the my sample code, to test this capability: https://github.com/ElliotGarbus/KivyWindowSize

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
Note: This is a simple test program.  There are 2 text input fields, I have not done any validation 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.

I hope this helps somebody.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Elliot Garbus

unread,
Apr 6, 2019, 11:00:36 AM4/6/19
to Kivy users support
@elvis It looks like a minor issue in your code, you have to following in health.py:
Config.set('postproc','desktop','1')
This should be:
Config.set('kivy','desktop','1')



On Friday, April 5, 2019 at 12:46:08 AM UTC-7, elvis ian omondi wrote:

Look at my code on comments .... https://github.com/elvis124/Ask-doctor to see how I have updated my window size ...so that it opens in the same size and position

On 5 Apr 2019 06:45, "Elliot Garbus" <elli...@cox.net> wrote:
I wanted my program to save its size and position on close, and reopen with the same size and position.
I've learned a few things along the way.  Here is the my sample code, to test this capability: https://github.com/ElliotGarbus/KivyWindowSize

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
Note: This is a simple test program.  There are 2 text input fields, I have not done any validation 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.

I hope this helps somebody.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Elliot Garbus

unread,
Apr 6, 2019, 11:11:25 AM4/6/19
to Kivy users support
New learning:
The windows size is automatically adjusted on high density macOS machines.  When saving the window size to the .ini file, the Window.size must be divided by Metrics.density or with window will double in size each time it is opened.
Reply all
Reply to author
Forward
0 new messages