Save/restore size and position of app

28 views
Skip to first unread message

John Anderson

unread,
Jun 15, 2017, 8:50:52 PM6/15/17
to Kivy users support
I have a kivy app that is not fullscreen. I would like to save the geometry (size and position of the app on the device screen) of the app when the user quits, and restore the app to the same size and position when it is next started. I know about the .ini file, but there is no mention in the documentation about size and position. Is this possible in a Kivy app?
     Thanks,
         John

ZenCODE

unread,
Jun 15, 2017, 10:46:51 PM6/15/17
to Kivy users support
Size is covered here: https://kivy.org/docs/api-kivy.config.html. You could save the size on closing and restore it on startup. 

As for the position, the Window (kivy.core.window.Window) has a position, so you could try saving and restoring that if needs be.

If you don't come right, please try posting a minimal code example that we can help you with...

Thanks

John Anderson

unread,
Jun 16, 2017, 1:31:43 PM6/16/17
to Kivy users support
I have attached a minimal example. The size part works using Window.size, stumbled across that, but cannot find any actual documentation for it.
Cannot figure out the position part. Trying to use "self.root_window.top" causes an Exception:

File "/home/jra/PycharmProjects/SizeAndLocationPlay/main.py", line 62, in on_stop
     print('top = ' + str(self.root_window.top) + '\n')
   File "kivy/properties.pyx", line 483, in kivy.properties.Property.__get__ (/tmp/pip-build-vf10dxpy/kivy/kivy/properties.c:5670)
   File "kivy/properties.pyx", line 1467, in kivy.properties.AliasProperty.get (/tmp/pip-build-vf10dxpy/kivy/kivy/properties.c:23970)
   File "/usr/local/lib/python3.6/site-packages/kivy/core/window/__init__.py", line 752, in _get_top
     return self._get_window_pos()[1]
 TypeError: 'NoneType' object is not subscriptable

The ini file contains a "top" and "left" in the "graphics" section, but they seem to just be copies from the systemwide kivy Config. Changing those values in the ini file seems to have no effect.

Any suggestions?
main.py

John Anderson

unread,
Jun 17, 2017, 2:28:23 AM6/17/17
to Kivy users support
Finally figured it out. There is a bug in the Ubuntu Kivy.  The attached code does exactly what I want under Windows, but throws exceptions under Ubuntu. When I try to access the 'left' property of the apps 'root_window', I get the following under Ubuntu:
   File "main.py", line 48, in on_stop
     print('setting left and top to ' + str(window.left) + ', ' + str(window.top) + '\n')
   File "kivy/properties.pyx", line 483, in kivy.properties.Property.__get__ (/tmp/pip-build-vf10dxpy/kivy/kivy/properties.c:5670)
   File "kivy/properties.pyx", line 1467, in kivy.properties.AliasProperty.get (/tmp/pip-build-vf10dxpy/kivy/kivy/properties.c:23970)
   File "/usr/local/lib/python3.6/site-packages/kivy/core/window/__init__.py", line 743, in _get_left
     return self._get_window_pos()[0]
 TypeError: 'NoneType' object is not subscriptable

Will report this to Kivy issues.
main.py
Reply all
Reply to author
Forward
0 new messages