-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from nucleic/feature-focus-events
Add focus api
- Loading branch information
Showing
10 changed files
with
511 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#------------------------------------------------------------------------------ | ||
# Copyright (c) 2014, Nucleic Development Team. | ||
# | ||
# Distributed under the terms of the Modified BSD License. | ||
# | ||
# The full license is in the file COPYING.txt, distributed with this software. | ||
#------------------------------------------------------------------------------ | ||
from enaml.widgets.focus_tracker import ProxyFocusTracker | ||
|
||
from .QtGui import QApplication | ||
|
||
from .qt_toolkit_object import QtToolkitObject | ||
|
||
|
||
class QtFocusTracker(QtToolkitObject, ProxyFocusTracker): | ||
""" A Qt implementation of an Enaml ProxyFocusTracker. | ||
""" | ||
def create_widget(self): | ||
""" Create the underlying widget. | ||
""" | ||
# A focus tracker does not have a widget representation. | ||
self.widget = None | ||
|
||
def init_widget(self): | ||
""" Initialize the underlying widget. | ||
""" | ||
super(QtFocusTracker, self).init_widget() | ||
QApplication.instance().focusChanged.connect(self._on_focus_changed) | ||
self._update_focus_widget() | ||
|
||
def destroy(self): | ||
""" A reimplemented destructor. | ||
""" | ||
QApplication.instance().focusChanged.disconnect(self._on_focus_changed) | ||
super(QtFocusTracker, self).destroy() | ||
|
||
def _on_focus_changed(self, old, new): | ||
""" Handle the application 'focusChanged' signal. | ||
""" | ||
self._update_focus_widget() | ||
|
||
def _update_focus_widget(self): | ||
""" Update the tracker with currently focused widget. | ||
""" | ||
fw = QApplication.focusWidget() | ||
fp = fw and getattr(fw, '_d_proxy', None) | ||
fd = fp and fp.declaration | ||
self.declaration.focused_widget = fd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#------------------------------------------------------------------------------ | ||
# Copyright (c) 2014, Nucleic Development Team. | ||
# | ||
# Distributed under the terms of the Modified BSD License. | ||
# | ||
# The full license is in the file COPYING.txt, distributed with this software. | ||
#------------------------------------------------------------------------------ | ||
from atom.api import ForwardTyped, Typed | ||
|
||
from enaml.core.declarative import d_ | ||
|
||
from .toolkit_object import ToolkitObject, ProxyToolkitObject | ||
from .widget import Widget | ||
|
||
|
||
class ProxyFocusTracker(ProxyToolkitObject): | ||
""" The abstract definition of a proxy FocusTracker object. | ||
""" | ||
#: A reference to the FocusTracker declaration. | ||
declaration = ForwardTyped(lambda: FocusTracker) | ||
|
||
|
||
class FocusTracker(ToolkitObject): | ||
""" An object which tracks the global application focus widget. | ||
""" | ||
#: The application widget with the current input focus. This will | ||
#: be None if no widget in the application has focus, or if the | ||
#: focused widget does not directly correspond to an Enaml widget. | ||
focused_widget = d_(Typed(Widget), writable=False) | ||
|
||
#: A reference to the ProxyFocusTracker object. | ||
proxy = Typed(ProxyFocusTracker) |
Oops, something went wrong.