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

InstanceEditor with droppable=True crashes on Qt #1478

Closed
corranwebster opened this issue Jan 14, 2021 · 1 comment · Fixed by #1733
Closed

InstanceEditor with droppable=True crashes on Qt #1478

corranwebster opened this issue Jan 14, 2021 · 1 comment · Fixed by #1733
Labels
component: core Issues related to the core functionality, ui composition and life cycle. toolkit: Qt type: bug

Comments

@corranwebster
Copy link
Contributor

corranwebster commented Jan 14, 2021

Setting droppable=True on an InstanceEditor when running under Qt crashes with the following error:

Traceback (most recent call last):
  File "/Users/cwebster/src/experiments/internal/cwebster/instance_editor/instance_choice_editor.py", line 122, in <module>
    analysis_view.configure_traits(kind='live')
  File "/Users/cwebster/.edm/envs/edm/lib/python3.6/site-packages/traitsui/handler.py", line 477, in configure_traits
    **args
  File "/Users/cwebster/.edm/envs/edm/lib/python3.6/site-packages/traits/has_traits.py", line 2015, in configure_traits
    args,
  File "/Users/cwebster/.edm/envs/edm/lib/python3.6/site-packages/traitsui/qt4/toolkit.py", line 233, in view_application
    context, view, kind, handler, id, scrollable, args
  File "/Users/cwebster/.edm/envs/edm/lib/python3.6/site-packages/traitsui/qt4/view_application.py", line 84, in view_application
    context, view, kind, handler, id, scrollable, args
  File "/Users/cwebster/.edm/envs/edm/lib/python3.6/site-packages/traitsui/qt4/view_application.py", line 126, in __init__
    args=self.args,
  File "/Users/cwebster/.edm/envs/edm/lib/python3.6/site-packages/traitsui/view.py", line 462, in ui
    ui.ui(parent, kind)
  File "/Users/cwebster/.edm/envs/edm/lib/python3.6/site-packages/traitsui/ui.py", line 244, in ui
    self.rebuild(self, parent)
  File "/Users/cwebster/.edm/envs/edm/lib/python3.6/site-packages/traitsui/qt4/toolkit.py", line 163, in ui_live
    ui_live.ui_live(ui, parent)
  File "/Users/cwebster/.edm/envs/edm/lib/python3.6/site-packages/traitsui/qt4/ui_live.py", line 43, in ui_live
    _ui_dialog(ui, parent, BaseDialog.NONMODAL)
  File "/Users/cwebster/.edm/envs/edm/lib/python3.6/site-packages/traitsui/qt4/ui_live.py", line 65, in _ui_dialog
    BaseDialog.display_ui(ui, parent, style)
  File "/Users/cwebster/.edm/envs/edm/lib/python3.6/site-packages/traitsui/qt4/ui_base.py", line 286, in display_ui
    ui.owner.init(ui, parent, style)
  File "/Users/cwebster/.edm/envs/edm/lib/python3.6/site-packages/traitsui/qt4/ui_live.py", line 225, in init
    self.add_contents(panel(ui), bbox)
  File "/Users/cwebster/.edm/envs/edm/lib/python3.6/site-packages/traitsui/qt4/ui_panel.py", line 259, in panel
    panel = _GroupPanel(content[0], ui).control
  File "/Users/cwebster/.edm/envs/edm/lib/python3.6/site-packages/traitsui/qt4/ui_panel.py", line 615, in __init__
    layout = self._add_groups(content, inner)
  File "/Users/cwebster/.edm/envs/edm/lib/python3.6/site-packages/traitsui/qt4/ui_panel.py", line 696, in _add_groups
    panel = _GroupPanel(subgroup, self.ui).control
  File "/Users/cwebster/.edm/envs/edm/lib/python3.6/site-packages/traitsui/qt4/ui_panel.py", line 617, in __init__
    layout = self._add_items(content, inner)
  File "/Users/cwebster/.edm/envs/edm/lib/python3.6/site-packages/traitsui/qt4/ui_panel.py", line 891, in _add_items
    editor.prepare(inner)
  File "/Users/cwebster/.edm/envs/edm/lib/python3.6/site-packages/traitsui/editor.py", line 236, in prepare
    self.init(parent)
  File "/Users/cwebster/.edm/envs/edm/lib/python3.6/site-packages/traitsui/qt4/instance_editor.py", line 127, in init
    self.control.installEventFilter(drop_event_filter)
AttributeError: 'NoneType' object has no attribute 'installEventFilter'

The proximate cause seems to be that this code:

if droppable:
# Install EventFilter on control to handle DND events.
drop_event_filter = _DropEventFilter(self.control)
self.control.installEventFilter(drop_event_filter)

occurs before self.control is set, so the fix may be as simple as moving the code further down the method. It is also possible that the code should read self._choice instead of self.control.

@corranwebster corranwebster added component: core Issues related to the core functionality, ui composition and life cycle. toolkit: Qt type: bug labels Jan 14, 2021
@aaronayres35
Copy link
Contributor

In order for this to occur, control needs to have not been set. It will however be set by this line

if factory.editable:
self.control = self._panel = parent = QtGui.QWidget()

As long as editable is True. My understanding is that droppable would not make sense being True if editable is false? I guess the selected object may not editable (just selectable), but we can edit the list of selectable objects by dropping.

Of the two solutions proposed (moving code down, or using _choice), I think both will work, but I prefer the first (as it better preserves the original code).

@rahulporuri rahulporuri added this to To be considered in Enthought OSS Q3 2021 via automation Jul 20, 2021
@rahulporuri rahulporuri moved this from To be considered to In progress in Enthought OSS Q3 2021 Jul 20, 2021
@rahulporuri rahulporuri moved this from In progress to Done in Enthought OSS Q3 2021 Jul 21, 2021
@rahulporuri rahulporuri moved this from Done to Sprint 2 (19 July - 30 July 2021) in Enthought OSS Q3 2021 Jul 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: core Issues related to the core functionality, ui composition and life cycle. toolkit: Qt type: bug
Projects
No open projects
Enthought OSS Q3 2021
  
Sprint 2 (19 July - 30 July 2021)
Development

Successfully merging a pull request may close this issue.

2 participants