From 39b20143750ea923fc44ff51de1a1b950fb4f8c0 Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Thu, 31 Dec 2020 14:10:00 -0500 Subject: [PATCH] remove orientation method from supportsOrientation --- magicgui/widgets/_bases.py | 23 +++++++++++++++++++++-- magicgui/widgets/_protocols.py | 15 +-------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/magicgui/widgets/_bases.py b/magicgui/widgets/_bases.py index e51657011..55b2b48af 100644 --- a/magicgui/widgets/_bases.py +++ b/magicgui/widgets/_bases.py @@ -631,7 +631,26 @@ def max(self, value: float): self.value = prev -class SliderWidget(RangedWidget): +class _OrientationMixin: + """Properties for classes wrapping widgets that support orientation.""" + + _widget: _protocols.SupportsOrientation + + @property + def orientation(self) -> str: + """Orientation of the widget.""" + return self._widget._mgui_get_orientation() + + @orientation.setter + def orientation(self, value: str) -> None: + if value not in {"horizontal", "vertical"}: + raise ValueError( + "Only horizontal and vertical orientation are currently supported" + ) + self._widget._mgui_set_orientation(value) + + +class SliderWidget(RangedWidget, _OrientationMixin): """Widget with a contstrained value and orientation. Wraps SliderWidgetProtocol. Parameters @@ -751,7 +770,7 @@ def choices(self, choices: ChoicesType): return self._widget._mgui_set_choices(_choices) -class ContainerWidget(Widget, MutableSequence[Widget]): +class ContainerWidget(Widget, _OrientationMixin, MutableSequence[Widget]): """Widget that can contain other widgets. Wraps a widget that implements diff --git a/magicgui/widgets/_protocols.py b/magicgui/widgets/_protocols.py index 7ee0bc2db..32f93dadb 100644 --- a/magicgui/widgets/_protocols.py +++ b/magicgui/widgets/_protocols.py @@ -209,21 +209,8 @@ class ButtonWidgetProtocol(ValueWidgetProtocol, SupportsText, Protocol): class SupportsOrientation(Protocol): """Widget that can be reoriented.""" - @property - def orientation(self) -> str: - """Orientation of the widget.""" - return self._mgui_get_orientation() - - @orientation.setter - def orientation(self, value: str) -> None: - if value not in {"horizontal", "vertical"}: - raise ValueError( - "Only horizontal and vertical orientation are currently supported" - ) - self._mgui_set_orientation(value) - @abstractmethod - def _mgui_set_orientation(self, value) -> None: + def _mgui_set_orientation(self, value: str) -> None: """Set orientation, value will be 'horizontal' or 'vertical'.""" raise NotImplementedError()