Skip to content

Commit a38976c

Browse files
aaronayres35Poruri Sai Rahul
andauthored
Convert otc decorators to observe decorators (#864)
* update otc decorators to be observe decorators in guiapplication.py and tasks_application.py because it calls a super on one of the handlers so they needed to be updated togeter. Also specify comparaison mode to avoid warning (is this correct?) * use observe decorator in palce of otc decorator in action/action_item.py * same for tasks/task_window.py * fix update to task window (needed a : not a .) * remove specification of identity comparison_mode as it is no longer needed with traits 6.2 * decorator updates for tasks/action/dock_pane_toggle_group.py * update decorators in tasks/action/task_toggle_group.py (seems untested, be careful) * same for task_window_toggle_group.py (also seems unttested? be careful) * replace decorator in test_gui_application.py * replace decorators in application_window.py * update decorrators for ui/qt4/tasks/advanced_editor_area_pane.py (note changes may be untested) * update decorators for ui/qt4/tasks/dock_pane.py (note handlers were called independently of change handling so I pass None as the event) * update decorators for both toolkits editor_area_pane.py files * same for ui/qt4/tasks/split_editor_area_pane.py * more of the same this time for wx dock_pane.py * update decorators in qt workbench_window_layout.py and update corresponding test * update wx application_window.py * update workbench_window.py * update decorators for workbench/action/perspective_menu_manager.py * update decorators for workbench/action/set_active_perspective_action.py * update for workbench/action/user_perspective_action.py * update for workbench/action/view_menu_manager.py * update for workbench/debug/debug_view.py * update to use observe decorators in examples * if event isn't actually needed, define the argument as _=None instead * Apply suggestions from code review Co-authored-by: Poruri Sai Rahul <[email protected]> * more suggested changes for code readability * Apply suggestions from code review Co-authored-by: Poruri Sai Rahul <[email protected]> * Apply suggestions from code review Co-authored-by: Poruri Sai Rahul <[email protected]> * pass event=None where needed * missed a few Co-authored-by: Poruri Sai Rahul <[email protected]>
1 parent f3683d0 commit a38976c

29 files changed

+182
-186
lines changed

examples/application/python_editor/python_editor_task.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
Property,
5555
Str,
5656
cached_property,
57-
on_trait_change,
57+
observe,
5858
)
5959

6060
from python_browser_pane import PythonBrowserPane
@@ -333,15 +333,16 @@ def _prompt_for_save(self):
333333

334334
# Trait change handlers --------------------------------------------------
335335

336-
@on_trait_change("window:closing")
336+
@observe("window:closing")
337337
def _prompt_on_close(self, event):
338338
""" Prompt the user to save when exiting.
339339
"""
340340
close = self._prompt_for_save()
341-
event.veto = not close
341+
window = event.new
342+
window.veto = not close
342343

343-
@on_trait_change("active_editor.name")
344-
def _change_title(self):
344+
@observe("active_editor.name")
345+
def _change_title(self, event):
345346
""" Update the window title when the active editor changes.
346347
"""
347348
if self.window.active_task == self:
@@ -350,8 +351,8 @@ def _change_title(self):
350351
else:
351352
self.window.title = self.name
352353

353-
@on_trait_change("active_editor.[line,column,selection_length]")
354-
def _update_status(self):
354+
@observe("active_editor.[line,column,selection_length]")
355+
def _update_status(self, event):
355356
if self.active_editor is not None:
356357
editor = self.active_editor
357358
if editor.selection_length:

examples/tasks/advanced/example_task.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
OK,
2222
CANCEL,
2323
)
24-
from traits.api import on_trait_change, Property, Instance
24+
from traits.api import observe, Property, Instance
2525

2626

2727
from example_panes import PythonScriptBrowserPane
@@ -185,12 +185,13 @@ def _prompt_for_save(self):
185185

186186
# Trait change handlers ------------------------------------------------
187187

188-
@on_trait_change("window:closing")
188+
@observe("window:closing")
189189
def _prompt_on_close(self, event):
190190
""" Prompt the user to save when exiting.
191191
"""
192192
close = self._prompt_for_save()
193-
event.veto = not close
193+
window = event.new
194+
window.veto = not close
194195

195196
# Trait property getter/setters ----------------------------------------
196197

examples/tasks/basic/example_task.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
OK,
1515
CANCEL,
1616
)
17-
from traits.api import on_trait_change
17+
from traits.api import observe
1818

1919

2020
from example_panes import PythonEditorPane, PythonScriptBrowserPane
@@ -148,9 +148,10 @@ def _prompt_for_save(self):
148148
return self._prompt_for_save()
149149
return True
150150

151-
@on_trait_change("window:closing")
151+
@observe("window:closing")
152152
def _prompt_on_close(self, event):
153153
""" Prompt the user to save when exiting.
154154
"""
155+
window = event.new
155156
if not self._prompt_for_save():
156-
event.veto = True
157+
window.veto = True

pyface/action/action_item.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
""" An action manager item that represents an actual action. """
1212

1313

14-
from traits.api import Any, Instance, List, Property, Str, on_trait_change
14+
from traits.api import Any, Instance, List, Property, Str, observe
1515

1616

1717
from pyface.action.action import Action
@@ -72,11 +72,11 @@ def _enabled_changed(self, trait_name, old, new):
7272
def _visible_changed(self, trait_name, old, new):
7373
self.action.visible = new
7474

75-
@on_trait_change("_wrappers.control")
76-
def _on_destroy(self, object, name, old, new):
75+
@observe("_wrappers:items:control")
76+
def _on_destroy(self, event):
7777
""" Handle the destruction of the wrapper. """
78-
if name == "control" and new is None:
79-
self._wrappers.remove(object)
78+
if event.new is None:
79+
self._wrappers.remove(event.object)
8080

8181
# ------------------------------------------------------------------------
8282
# 'ActionItem' interface.

pyface/data_view/data_models/row_table_data_model.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"""
1515
from collections.abc import Sequence
1616

17-
from traits.api import ComparisonMode, Instance, List, observe
17+
from traits.api import Instance, List, observe
1818
from traits.observation.api import trait
1919

2020
from pyface.data_view.abstract_data_model import (
@@ -35,20 +35,13 @@ class RowTableDataModel(AbstractDataModel):
3535
"""
3636

3737
#: A sequence of objects to display as rows.
38-
data = Instance(
39-
Sequence,
40-
comparison_mode=ComparisonMode.identity,
41-
allow_none=False,
42-
)
38+
data = Instance(Sequence, allow_none=False)
4339

4440
#: An object which describes how to map data for the row headers.
4541
row_header_data = Instance(AbstractDataAccessor, allow_none=False)
4642

4743
#: An object which describes how to map data for each column.
48-
column_data = List(
49-
Instance(AbstractDataAccessor, allow_none=False),
50-
comparison_mode=ComparisonMode.identity,
51-
)
44+
column_data = List(Instance(AbstractDataAccessor, allow_none=False))
5245

5346
#: The index manager that helps convert toolkit indices to data view
5447
#: indices.

pyface/data_view/i_data_view_widget.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import logging
1313

1414
from traits.api import (
15-
Bool, ComparisonMode, Enum, HasStrictTraits, Instance, List, Property,
15+
Bool, Enum, HasStrictTraits, Instance, List, Property,
1616
TraitError, Tuple, cached_property,
1717
)
1818

@@ -53,10 +53,7 @@ class IDataViewWidget(IWidget):
5353
selection = List(Tuple)
5454

5555
#: Exporters available for the DataViewWidget.
56-
exporters = List(
57-
Instance(AbstractDataExporter),
58-
comparison_mode=ComparisonMode.identity,
59-
)
56+
exporters = List(Instance(AbstractDataExporter))
6057

6158

6259
class MDataViewWidget(HasStrictTraits):
@@ -81,10 +78,7 @@ class MDataViewWidget(HasStrictTraits):
8178
selection = Property(depends_on='_selection[]')
8279

8380
#: Exporters available for the DataViewWidget.
84-
exporters = List(
85-
Instance(AbstractDataExporter),
86-
comparison_mode=ComparisonMode.identity,
87-
)
81+
exporters = List(Instance(AbstractDataExporter))
8882

8983
# Private traits --------------------------------------------------------
9084

@@ -93,7 +87,7 @@ class MDataViewWidget(HasStrictTraits):
9387

9488
#: The selected indices in the view. This should never be mutated, any
9589
#: changes should be by replacement of the entire list.
96-
_selection = List(Tuple, comparison_mode=ComparisonMode.identity)
90+
_selection = List(Tuple)
9791

9892
# ------------------------------------------------------------------------
9993
# MDataViewWidget Interface

pyface/gui_application.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
Tuple,
3232
Undefined,
3333
Vetoable,
34-
on_trait_change,
34+
observe,
3535
)
3636

3737
from .application import Application
@@ -280,22 +280,24 @@ def _about_dialog_default(self):
280280

281281
# Trait listeners --------------------------------------------------------
282282

283-
@on_trait_change("windows:activated")
284-
def _on_activate_window(self, window, trait, old, new):
283+
@observe("windows:items:activated")
284+
def _on_activate_window(self, event):
285285
""" Listener that tracks currently active window.
286286
"""
287+
window = event.object
287288
if window in self.windows:
288289
self.active_window = window
289290

290-
@on_trait_change("windows:deactivated")
291-
def _on_deactivate_window(self, window, trait, old, new):
291+
@observe("windows:items:deactivated")
292+
def _on_deactivate_window(self, event):
292293
""" Listener that tracks currently active window.
293294
"""
294295
self.active_window = None
295296

296-
@on_trait_change("windows:closed")
297-
def _on_window_closed(self, window, trait, old, new):
297+
@observe("windows:items:closed")
298+
def _on_window_closed(self, event):
298299
""" Listener that ensures window handles are released when closed.
299300
"""
301+
window = event.object
300302
if window in self.windows:
301303
self.windows.remove(window)

pyface/tasks/action/dock_pane_toggle_group.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
cached_property,
1616
Instance,
1717
List,
18-
on_trait_change,
18+
observe,
1919
Property,
2020
Str,
2121
)
@@ -66,13 +66,13 @@ def _get_name(self):
6666
def _get_tooltip(self):
6767
return "Toggles the visibility of the %s pane." % self.name
6868

69-
@on_trait_change("dock_pane.visible")
70-
def _update_checked(self):
69+
@observe("dock_pane.visible")
70+
def _update_checked(self, event):
7171
if self.dock_pane:
7272
self.checked = self.dock_pane.visible
7373

74-
@on_trait_change("dock_pane.closable")
75-
def _update_visible(self):
74+
@observe("dock_pane.closable")
75+
def _update_visible(self, event):
7676
if self.dock_pane:
7777
self.visible = self.dock_pane.closable
7878

@@ -119,8 +119,8 @@ def get_manager(self):
119119

120120
# Private interface ----------------------------------------------------
121121

122-
@on_trait_change("dock_panes[]")
123-
def _dock_panes_updated(self):
122+
@observe("dock_panes.items")
123+
def _dock_panes_updated(self, event):
124124
"""Recreate the group items when dock panes have been added/removed.
125125
"""
126126

pyface/tasks/action/task_toggle_group.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
from pyface.action.api import Action, ActionItem, Group
13-
from traits.api import Any, List, Instance, Property, Str, on_trait_change
13+
from traits.api import Any, List, Instance, Property, Str, observe
1414

1515

1616
from pyface.tasks.task import Task
@@ -65,8 +65,8 @@ def _get_name(self):
6565
def _get_tooltip(self):
6666
return "Switch to the %s task." % self.name
6767

68-
@on_trait_change("task.window.active_task")
69-
def _update_checked(self):
68+
@observe("task.window.active_task")
69+
def _update_checked(self, event):
7070
if self.task:
7171
window = self.task.window
7272
self.checked = (

pyface/tasks/action/task_window_toggle_group.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
from pyface.action.api import Action, ActionItem, Group
13-
from traits.api import Any, Instance, List, Property, Str, on_trait_change
13+
from traits.api import Any, Instance, List, Property, Str, observe
1414

1515

1616
class TaskWindowToggleAction(Action):
@@ -47,12 +47,12 @@ def _get_name(self):
4747
return self.window.title
4848
return ""
4949

50-
@on_trait_change("window:activated")
51-
def _window_activated(self):
50+
@observe("window:activated")
51+
def _window_activated(self, event):
5252
self.checked = True
5353

54-
@on_trait_change("window:deactivated")
55-
def _window_deactivated(self):
54+
@observe("window:deactivated")
55+
def _window_deactivated(self, event):
5656
self.checked = False
5757

5858

0 commit comments

Comments
 (0)