-
Notifications
You must be signed in to change notification settings - Fork 52
Convert dynamic on_trait_change to observe part 2 #880
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
Conversation
… does not even have an image trait so setting up observers for it doesn't make sense
pyface/ui/wx/grid/grid.py
Outdated
smobs(self._on_model_content_changed, "content_changed", remove=True) | ||
smobs( | ||
self._on_model_structure_changed, "structure_changed", remove=True | ||
) | ||
smobs(self._on_row_sort, "row_sorted", remove=True) | ||
smobs(self._on_column_sort, "column_sorted", remove=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
although these are observers on the model not the grid itself I assume they should still be removed when the grid is disposed (notably because the handlers are methods on a mid disposal grid object)
@@ -134,7 +134,7 @@ def _create_tree(self, parent): | |||
content_provider=DefaultTreeContentProvider(), | |||
) | |||
|
|||
tree_viewer.on_trait_change(self._on_selection_changed, "selection") | |||
tree_viewer.observe(self._on_selection_changed, "selection") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't comment on the line itself, but this file has from pyface.ui.wx.split_dialog import SplitDialog
but there is no split_dialog
module in pyface/ui/wx
...
And that imported SplitDialog
is used as the base class for the PreferenceDialog
class defined in this module.
@@ -136,7 +136,7 @@ def _qt4_add_tools(self, parent, tool_bar, controller): | |||
# Is a separator required? | |||
if previous_non_empty_group is not None and group.separator: | |||
separator = tool_bar.addSeparator() | |||
group.on_trait_change( | |||
group.observe( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: I don't think these are getting removed
…ually hooked up before trying to remove them)
if old: | ||
old.observe(method, trait(name, optional=True), remove=True) | ||
if new: | ||
new.observe(method, trait(name, optional=True)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commenting on this to draw attention to a reviewer. Previously the observer was never getting hooked up if name
was None
. This caused pyface/action/tests/test_listening_action/TestListeningAction/test_destroy
to fail because we ultimately tried to unhook it in the destroy call.
The previous commit fixed this issue as well, but this seemed like the more correct way to go about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm not entirely sure under what circumstances Ohh. Wait. Never mind. name is None
will be True
here.if name
will be False
if name
is an empty string - which is possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost LGTM
pyface/action/listening_action.py
Outdated
if self.enabled_name: | ||
self.object.observe( | ||
self._enabled_update, | ||
trait(self.enabled_name, optional=True), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this line warrants a comment - we already have a conditional so im not sure why we use the optional=True
in the call to trait
- and i'm not even sure what trait
does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah i meant to delete the conditionals, they are no longer needed once we have the optional=True
pyface/action/listening_action.py
Outdated
if self.visible_name: | ||
self.object.observe( | ||
self._visible_update, | ||
trait(self.visible_name, optional=True), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as above.
if old: | ||
old.observe(method, trait(name, optional=True), remove=True) | ||
if new: | ||
new.observe(method, trait(name, optional=True)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm not entirely sure under what circumstances Ohh. Wait. Never mind. name is None
will be True
here.if name
will be False
if name
is an empty string - which is possible.
# because wx is retarded we have to check this as well -- why | ||
# the blazes can't they come up with one Q#$%@$#% API to manage | ||
# selections??? makes me want to put the smack on somebody. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why'd you remove this 🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol 😆
Co-authored-by: Poruri Sai Rahul <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a few more suggestions.
Co-authored-by: Poruri Sai Rahul <[email protected]>
Still LGTM. Merge once green! |
self._visible_update, self.visible_name, remove=True | ||
self.object.observe( | ||
self._visible_update, | ||
trait(self.visible_name, optional=True), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trait
here assumes the first argument is a trait name (see doc), so an extended name like "child.is_visible"
is going to fail because "child.is_visible"
as a trait name is not defined on object
. The optional=True
may mask that lost behaviour?
closes #637
closes #732
This PR makes the last round of updates to replace use of
on_trait_change
withobserve
. With the changes in this PR,on_trait_change
is no longer present anywhere in the code base. This PR also makes an update to the documentation section ontimers
. Please confirm the changes made there are reasonable.Note to reviewer, be cautious: some of the code undergoing changes in this PR is not covered by the test suite. I made some knowingly broken changes and ran the test suite only to find everything still passing.
This PR also drive by removes some commented out code from the code base.