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

SplitWidget fixes #977

Merged
merged 3 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions pyface/i_split_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
""" Mix-in class for split widgets. """


from traits.api import Callable, Enum, Float, HasTraits, Interface
from traits.api import Callable, Float, HasTraits, Interface

from pyface.ui_traits import Orientation


class ISplitWidget(Interface):
Expand All @@ -28,7 +30,7 @@ class ISplitWidget(Interface):
#: Splitting vertically means there will be a left hand panel and a right
#: hand panel, splitting horizontally means there will be a top panel and
#: a bottom panel.
direction = Enum("vertical", "vertical", "horizontal")
direction = Orientation()

#: The ratio of the size of the left/top pane to the right/bottom pane.
ratio = Float(0.5)
Expand Down Expand Up @@ -90,3 +92,51 @@ class MSplitWidget(HasTraits):
""" The mixin class that contains common code for toolkit specific
implementations of the ISplitWidget interface.
"""

# 'ISplitWidget' interface ---------------------------------------------

#: The direction in which the widget is split.
#
#: Splitting vertically means there will be a left hand panel and a right
#: hand panel, splitting horizontally means there will be a top panel and
#: a bottom panel.
direction = Orientation()

#: The ratio of the size of the left/top pane to the right/bottom pane.
ratio = Float(0.5)

#: An optional callable that provides the left hand/top panel.
lhs = Callable

#: An optional callable that provides the right hand/bottom panel.
rhs = Callable

def _create_lhs(self, parent):
""" Creates the left hand/top panel depending on the direction.

Parameters
----------
parent : toolkit control
The splitter's toolkit control.

Returns
-------
lhs : toolkit control
The toolkit control for the lhs.
"""
raise NotImplementedError()

def _create_rhs(self, parent):
""" Creates the right hand/bottom panel depending on the direction.

Parameters
----------
parent : toolkit control
The splitter's toolkit control.

Returns
-------
rhs : toolkit control
The toolkit control for the rhs.
"""
raise NotImplementedError()
24 changes: 19 additions & 5 deletions pyface/split_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

""" A panel that is split in two either horizontally or vertically. """

import warnings

from pyface.split_widget import SplitWidget
from pyface.widget import Widget
Expand All @@ -22,11 +23,24 @@ class SplitPanel(Widget, SplitWidget):
# 'object' interface.
# ------------------------------------------------------------------------

def __init__(self, parent, **traits):
def __init__(self, parent=None, **traits):
""" Creates a new panel. """

# Base class constructor.
super().__init__(**traits)
create = traits.pop("create", True)

# Create the widget's toolkit-specific control.
self.control = self._create_splitter(parent)
# Base class constructor.
super().__init__(parent=parent, **traits)

if create:
# Create the widget's toolkit-specific control.
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,
)
Comment on lines +37 to +42
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment here regarding an issue to handle this deprecation - looks like a single issue will suffice to handle all such deprecations related to the create method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same reply as before - I've updated #729 to add the sequence around this.

Actually, should probably add #729 to the 8.0 milestone.


def _create_control(self, parent):
""" Create the toolkit control """
return self._create_splitter(parent)
21 changes: 20 additions & 1 deletion pyface/tests/test_split_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,26 @@ def tearDown(self):
def test_lifecycle(self):
# test that destroy works
with self.event_loop():
self.widget = SplitPanel(self.window.control)
with self.assertWarns(PendingDeprecationWarning):
self.widget = SplitPanel(self.window.control)

self.assertIsNotNone(self.widget.control)

with self.event_loop():
self.widget.destroy()

def test_two_stage_create(self):
# test that create=False works
self.widget = SplitPanel(create=False)

self.assertIsNone(self.widget.control)

with self.event_loop():
self.widget.parent = self.window.control
self.widget.create()

self.assertIsNotNone(self.widget.control)

with self.event_loop():
self.widget.destroy()

Expand Down
18 changes: 2 additions & 16 deletions pyface/ui/qt4/split_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,21 @@
# This software is provided without warranty under the terms of the BSD license.
# However, when used with the GPL version of PyQt the additional terms described in the PyQt GPL exception also apply


""" Mix-in class for split widgets. """


from pyface.qt import QtCore, QtGui


from traits.api import Callable, Enum, Float, HasTraits, provides

from traits.api import provides

from pyface.i_split_widget import ISplitWidget, MSplitWidget


@provides(ISplitWidget)
class SplitWidget(MSplitWidget, HasTraits):
class SplitWidget(MSplitWidget):
""" The toolkit specific implementation of a SplitWidget. See the
ISPlitWidget interface for the API documentation.
"""

# 'ISplitWidget' interface ---------------------------------------------

direction = Enum("vertical", "vertical", "horizontal")

ratio = Float(0.5)

lhs = Callable

rhs = Callable

# ------------------------------------------------------------------------
# Protected 'ISplitWidget' interface.
# ------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion pyface/ui/wx/image_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from traits.api import Bool, Str, Range, Enum, Instance, Event

from pyface.ui_traits import Orientation
from .widget import Widget
from .image_resource import ImageResource

Expand Down Expand Up @@ -69,7 +70,7 @@ class ImageButton(Widget):
style = Enum("button", "radio", "toolbar", "checkbox")

# Orientation of the text relative to the image:
orientation = Enum("vertical", "horizontal")
orientation = Orientation()

# Is the control selected ('radio' or 'checkbox' style)?
selected = Bool(False)
Expand Down
17 changes: 2 additions & 15 deletions pyface/ui/wx/split_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,19 @@
""" Mix-in class for split widgets.
"""


import wx


from traits.api import Callable, Enum, Float, HasTraits, provides

from traits.api import provides

from pyface.i_split_widget import ISplitWidget, MSplitWidget


@provides(ISplitWidget)
class SplitWidget(MSplitWidget, HasTraits):
class SplitWidget(MSplitWidget):
""" The toolkit specific implementation of a SplitWidget. See the
ISPlitWidget interface for the API documentation.
"""

# 'ISplitWidget' interface ---------------------------------------------

direction = Enum("vertical", "vertical", "horizontal")

ratio = Float(0.5)

lhs = Callable

rhs = Callable

# ------------------------------------------------------------------------
# Protected 'ISplitWidget' interface.
# ------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions pyface/ui_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,6 @@ class HasBorder(HasMargin):

#: The alignment of text within a control.
Alignment = Enum("default", "left", "center", "right")

#: Whether the orientation of a widget's contents is horizontal or vertical.
Orientation = Enum("vertical", "horizontal")