Skip to content

Commit 4e429de

Browse files
committed
Merge pull request kivy#3890 from kivy/window_focus
turn Window.focus into a read-only property
2 parents 56cff85 + 6656df6 commit 4e429de

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

kivy/core/window/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ class WindowBase(EventDispatcher):
295295
_modifiers = ListProperty([])
296296
_rotation = NumericProperty(0)
297297
_clearcolor = ObjectProperty([0, 0, 0, 1])
298+
_focus = BooleanProperty(True)
298299

299300
children = ListProperty([])
300301
'''List of the children of this window.
@@ -599,12 +600,15 @@ def _get_effective_size(self):
599600
defaults to True.
600601
'''
601602

602-
focus = BooleanProperty(True)
603-
'''Set whether or not the window currently has focus.
603+
def _get_focus(self):
604+
return self._focus
604605

605-
.. versionadded::1.9.1
606+
focus = AliasProperty(_get_focus, None, bind=('_focus',))
607+
'''Check whether or not the window currently has focus.
606608
607-
:attr:`focus` is a :class:`~kivy.properties.BooleanProperty and
609+
.. versionadded:: 1.9.1
610+
611+
:attr:`focus` is a read-only :class:`~kivy.properties.AliasProperty and
608612
defaults to True.
609613
'''
610614

kivy/core/window/window_sdl2.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,12 @@ def _mainloop(self):
472472
if Config.getboolean('kivy', 'pause_on_minimize'):
473473
self.do_pause()
474474

475+
elif action == 'windowfocusgained':
476+
self._focus = True
477+
478+
elif action == 'windowfocuslost':
479+
self._focus = False
480+
475481
elif action == 'windowenter':
476482
self.dispatch('on_cursor_enter')
477483

@@ -559,12 +565,6 @@ def _mainloop(self):
559565
text = args[0]
560566
self.dispatch('on_textinput', text)
561567

562-
elif action == 'windowfocusgained':
563-
self.focus = True
564-
565-
elif action == 'windowfocuslost':
566-
self.focus = False
567-
568568
# unhandled event !
569569
else:
570570
Logger.trace('WindowSDL: Unhandled event %s' % str(event))

0 commit comments

Comments
 (0)