Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace some _anytrait_changed methods #625

Merged
merged 6 commits into from
Jun 1, 2021
Merged

Conversation

aaronayres35
Copy link
Contributor

@aaronayres35 aaronayres35 commented Apr 5, 2021

closes #624

Note there are still a few examples using _anytrait_changed methods that can be addressed in a different PR. I ended up not using metadata in the legend.py and just went with the straight forward conversion to observe. We can come back to this if we want to be a little more clever later.

@aaronayres35
Copy link
Contributor Author

The occurrence in chaco/legend.py is a bit trickier as there we check for _items traits. I am unsure on the cleanest way to do this using metadata like we do for the axis.py case. It may be that we just add those things explicitly in the expression passed to observe (e.g observe("plots.items, labels.items, +needs_layout") or something like this)

However, this may lead to some confusion. Additionally, the metadata use in chaco/axis.py may already be a little confusing. For example the title trait does not have is_visual set to True, because currently it is handled differently with its own change handler (we effectively do the same as calling _invalidate but we do not set self._cache_valid = False). Likewise there is a bgcolor trait that currently does not have is_visual set because it was not previously listed in the _anytrait_changed method, but this certainly seems to be a visual attribute. Perhaps it should trigger _invalidate when it changes? Or perhaps there was some reason for it not being included?

@aaronayres35 aaronayres35 changed the title [WIP] Replace _anytrrait_changed methods [WIP] Replace _anytrait_changed methods Apr 5, 2021
@aaronayres35 aaronayres35 changed the title [WIP] Replace _anytrait_changed methods Replace some _anytrait_changed methods Apr 16, 2021
@aaronayres35
Copy link
Contributor Author

looks like the intermittent failure on test_dont_crash_on_click is not windows specific... 😞

On linux/pyqt

======================================================================
ERROR: test_dont_crash_on_click (chaco.tests.test_plot.TestEmptyPlot)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/.edm/envs/chaco-test-3.6-pyqt/lib/python3.6/site-packages/chaco/tests/test_plot.py", line 148, in test_dont_crash_on_click
    [(1, 1), (2, 2), (3, 3), (4, 4)],
  File "/home/travis/.edm/envs/chaco-test-3.6-pyqt/lib/python3.6/contextlib.py", line 88, in __exit__
    next(self.gen)
  File "/home/travis/.edm/envs/chaco-test-3.6-pyqt/lib/python3.6/site-packages/traitsui/testing/tester/ui_tester.py", line 106, in create_ui
    process_cascade_events()
  File "/home/travis/.edm/envs/chaco-test-3.6-pyqt/lib/python3.6/contextlib.py", line 88, in __exit__
    next(self.gen)
  File "/home/travis/.edm/envs/chaco-test-3.6-pyqt/lib/python3.6/site-packages/traitsui/testing/_exception_handling.py", line 74, in reraise_exceptions
    raise RuntimeError(msg)
RuntimeError: Uncaught exceptions found.
=== Exception (type: <class 'AttributeError'>, value: '_QtWindow' object has no attribute 'handler') ===
Traceback (most recent call last):
  File "/home/travis/.edm/envs/chaco-test-3.6-pyqt/lib/python3.6/site-packages/enable/qt4/base_window.py", line 255, in enterEvent
    self.handler.enterEvent(event)
AttributeError: '_QtWindow' object has no attribute 'handler'
=== Exception (type: <class 'AttributeError'>, value: '_QtWindow' object has no attribute 'handler') ===
Traceback (most recent call last):
  File "/home/travis/.edm/envs/chaco-test-3.6-pyqt/lib/python3.6/site-packages/enable/qt4/base_window.py", line 264, in mouseMoveEvent
    self.handler.mouseMoveEvent(event)
AttributeError: '_QtWindow' object has no attribute 'handler'
=== Exception (type: <class 'AttributeError'>, value: '_QtWindow' object has no attribute 'handler') ===
Traceback (most recent call last):
  File "/home/travis/.edm/envs/chaco-test-3.6-pyqt/lib/python3.6/site-packages/enable/qt4/base_window.py", line 264, in mouseMoveEvent
    self.handler.mouseMoveEvent(event)
AttributeError: '_QtWindow' object has no attribute 'handler'
=== Exception (type: <class 'AttributeError'>, value: '_QtWindow' object has no attribute 'handler') ===
Traceback (most recent call last):
  File "/home/travis/.edm/envs/chaco-test-3.6-pyqt/lib/python3.6/site-packages/enable/qt4/base_window.py", line 258, in leaveEvent
    self.handler.leaveEvent(event)
AttributeError: '_QtWindow' object has no attribute 'handler'
----------------------------------------------------------------------

chaco/axis.py Outdated
]
if name in invalidate_traits:
self._invalidate()
@observe("+is_visual")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I prefer listing out the various traits that need to be observed here - instead of introducing new trait metadata. If we can make do without adding anything new, we should persue that option imo. I feel like introducing new trait metadata introduces a new maintenance/cognitive overhead.

"max_y",
]:
self.compute_model()
@observe("+needs_compute")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as before - i'd prefer verbosely listing out all of the traits that we want to listen to - instead of introducing new trait metadata.

aaronayres35 and others added 3 commits May 11, 2021 07:26
Co-authored-by: Poruri Sai Rahul <rporuri@enthought.com>
@aaronayres35 aaronayres35 requested a review from rahulporuri May 11, 2021 16:41
Copy link
Contributor

@rahulporuri rahulporuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aaronayres35 aaronayres35 merged commit 220af3d into master Jun 1, 2021
@aaronayres35 aaronayres35 deleted the remove-anytrait_changed branch June 1, 2021 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deal with _anytrait_changed handlers
2 participants