-
Notifications
You must be signed in to change notification settings - Fork 55
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
Deprecate __init__
methods which create the widget
#993
Changes from all commits
0ec774b
c26fb65
0fe3113
92ac9b2
17f7a87
b078c89
6bab475
89cc59c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,14 +12,15 @@ | |
""" A simple progress bar intended to run in the UI thread | ||
""" | ||
|
||
import warnings | ||
|
||
import wx | ||
import time | ||
|
||
|
||
from traits.api import Bool, Enum, Instance, Int, Property, Str | ||
|
||
from traits.api import Bool, Instance, Int, Property, Str | ||
|
||
from pyface.i_progress_dialog import MProgressDialog | ||
from pyface.ui_traits import Orientation | ||
from .widget import Widget | ||
from .window import Window | ||
|
||
|
@@ -34,7 +35,7 @@ class ProgressBar(Widget): | |
control = Instance(wx.Gauge) | ||
|
||
#: The orientation of the progress bar. | ||
direction = Enum("horizontal", "horizontal", "vertical") | ||
direction = Orientation("horizontal") | ||
|
||
#: The maximum value for the progress bar. | ||
_max = Int() | ||
|
@@ -46,20 +47,39 @@ def __init__( | |
maximum=100, | ||
direction="horizontal", | ||
size=(200, -1), | ||
**traits, | ||
): | ||
""" | ||
Constructs a progress bar which can be put into a panel, or optionaly, | ||
its own window | ||
""" | ||
self._max = maximum | ||
self.parent = parent | ||
create = traits.pop("create", True) | ||
|
||
# XXX minimum is ignored - it either should be deprecated or supported | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have an issue please - to remove it outright for the next major release? I don't think we have the resources to figure out how to support |
||
super().__init__( | ||
parent=parent, | ||
_max=maximum, | ||
direction=direction, | ||
size=size, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue created for this and |
||
**traits, | ||
) | ||
|
||
if create: | ||
self.create() | ||
warnings.warn( | ||
"automatic widget creation is deprecated and will be removed " | ||
"in a future Pyface version, use create=False and explicitly " | ||
"call create() for future behaviour", | ||
PendingDeprecationWarning, | ||
) | ||
|
||
def _create_control(self, parent): | ||
style = wx.GA_HORIZONTAL | ||
if direction == "vertical": | ||
if self.direction == "vertical": | ||
style = wx.GA_VERTICAL | ||
|
||
self.control = wx.Gauge(parent, -1, maximum, style=style, size=size) | ||
return wx.Gauge(parent, -1, self._max, style=style, size=self.size) | ||
|
||
def update(self, value): | ||
""" Update the progress bar to the desired value. """ | ||
|
@@ -306,7 +326,8 @@ def _create_label(self, dialog, parent_sizer, text): | |
return label | ||
|
||
def _create_gauge(self, dialog, parent_sizer): | ||
self.progress_bar = ProgressBar(dialog, self.min, self.max) | ||
self.progress_bar = ProgressBar(dialog, self.min, self.max, create=False) | ||
self.progress_bar.create() | ||
parent_sizer.Add( | ||
self.progress_bar.control, 0, wx.CENTER | wx.ALL, self.margin | ||
) | ||
|
@@ -388,7 +409,6 @@ def _create_control(self, parent): | |
sizer = wx.BoxSizer(wx.VERTICAL) | ||
dialog.SetSizer(sizer) | ||
dialog.SetAutoLayout(True) | ||
dialog.SetBackgroundColour(wx.NullColour) | ||
|
||
self.dialog_size = wx.Size() | ||
|
||
|
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.
nit-picky comment - in an earlier case, we didn't
self.control
in the_create_control
method and instead chose to simply return it instead - whereas in this method, we're setting and returningself.control
. Can i ask if there is a specific reason?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.
There were some widgets with methods called in
_create_control
that expectself.control
to not be populated. These widgets need their create methods to be untangled and have some code moved to_add_event_listeners
and other code moved to post-creation initialization.For example, in this class, all of the binding methods should really be in
_add_event_listenrs
.Since this PR is all about deprecating auto-creation, I wanted to make the smallest changes to achieve the required results. I'll add an issue about untangling creation and initialization.
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.
Issue created: #995