pyface icon indicating copy to clipboard operation
pyface copied to clipboard

The _create method should be public

Open corranwebster opened this issue 3 years ago • 3 comments

The base Widget._create method is nominally private, but in practice tends to get used as:

w = Widget(parent=parent)
w._create()

although a few widgets perform the _create() call as part of their __init__.

Two-phase creation has an advantage in that it permits programmatic configuration of the widget beyond what is passed in at class creation time before the underlying toolkit control is created.

This issue proposes that:

  • [x] there is a public create method, which initially can be implemented to simple call _create (#735)
  • [x] that calls to _create are changed to calls to create
  • [x] that classes migrate the implementation of _create into create, and make _create call create
  • [ ] that _create is removed

Additionally:

  • [x] any classes which call _create or (worse) _create_control in their __init__ be modified to not do that
  • [ ] classes in Tasks which match the new IWidget interface (such as ITaskPane) should be modified to inherit from IWidget and their implementations to inherit from Widget.

corranwebster avatar Oct 10 '20 09:10 corranwebster

Strategy for removing create calls from __init__:

  • [x] initially:
    • add a keyword-only argument create which defaults to True initially (since create is a method name it will never conflict with a trait name)
    • if create is True then call the create method, but also issue a PendingDeprecationWarning
  • [ ] in the next a major release:
    • ignore the create argument other than indicate that it is deprecated if it is passed
  • [ ] at some later release, remove any handling for create (ideally, removing the entire __init__ method).

corranwebster avatar Jul 13 '21 12:07 corranwebster

I've added this to the 8.0 release - the next few steps in this should be done for that release, if time permits.

It will not be completed in the 8.0 release, however.

corranwebster avatar Jul 13 '21 12:07 corranwebster

Incremental progress in the 8.0 release, the rest pushed to 9.0

corranwebster avatar Mar 14 '23 14:03 corranwebster