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

Fix droppable instance editor #1733

Merged
merged 7 commits into from Jul 21, 2021
Merged

Conversation

aaronayres35
Copy link
Contributor

@aaronayres35 aaronayres35 commented Jul 19, 2021

closes #1478

Checklist

  • Add a news fragment if this PR is news-worthy for end users. (see docs/releases/README.rst)

… fix an observe error by adding an observer in the droppable but not selectable case
Comment on lines 422 to 428
with tester.create_ui(obj, {'view': non_editable_droppable_view}) as ui:
pass

with tester.create_ui(
obj_with_list, {'view': non_editable_droppable_selectable_view}
) as ui:
pass
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We previously both of these caused a failure / crash.

Comment on lines 101 to 110
Item(
"inst",
editor=InstanceEditor(
editable=False,
droppable=True
),
style='custom',
),
buttons=["OK"],
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have no idea why one would want to do this... but it is a possible configuration one could make. This would be when you are "editing" a single instance, but the single instance itself is not editable, so all that is displayed in a QLineEdit displaying the current instance. The instance can be changed by dragging and dropping a different instance. The user can not select a different instance as theoretically there is no list to select from.

Comment on lines 125 to 127
self.factory.observe(
self.rebuild_items, "values.items", dispatch="ui"
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The more I think about this it doesn't really make sense. This was added because without it we were getting a NotifierNotFound error in the non_editable_droppable_view case. However, the only time this occurs is the use case described here: https://github.com/enthought/traitsui/pull/1733/files#r672368160

In which case values.items should never change. (There isn't a list of instances, just the one!).

Thinking about this more I think it probably makes more sense to check for this case when we arer removing the listener (and not try to remove it), rather than just adding it here to avoid the failure.

This code path is rather confusing. Using _choice in this case doesn't really make sense. At least not to me anyway, as we are not really choosing an instance from a list of options...

@rahulporuri
Copy link
Contributor

@aaronayres35 is this PR ready for review?

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 with a couple of nitpicky suggestions and one question about another observer that we might want to unhook.

"values.items",
remove=True,
dispatch="ui"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we also want to remove the other observer hooked up if factory.name != ""? Ref

if factory.name != "":
self._object.observe(
self.rebuild_items, self._name + ".items", dispatch="ui"
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this is already getting unhooked above

EDIT: However looking closer, the conditionals for hooking it up don't seem to match the conditionals for unhooking. unhooking we check for self._object, which only gets set in this code:

if factory.name != "":
    self._object, self._name, self._value = self.parse_extended_name(
        factory.name
    )

so that at least is effecitvely the same though. It is set up in the if selectable block though so that unhooking could probably be wrapped in an if isinstance(self._choice, QtGui.QComboBox): as well...

traitsui/tests/editors/test_instance_editor.py Outdated Show resolved Hide resolved
traitsui/tests/editors/test_instance_editor.py Outdated Show resolved Hide resolved
aaronayres35 and others added 2 commits July 21, 2021 03:52
Co-authored-by: Poruri Sai Rahul <rporuri@enthought.com>
@aaronayres35
Copy link
Contributor Author

@rahulporuri does the latest change with unhooking the observer still look okay?

@rahulporuri
Copy link
Contributor

still LGTM but this PR doesn't have a news fragment

@aaronayres35 aaronayres35 merged commit 508a2a5 into master Jul 21, 2021
@aaronayres35 aaronayres35 deleted the fix-droppable-InstanceEditor branch July 21, 2021 14:41
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.

InstanceEditor with droppable=True crashes on Qt
2 participants