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

remove orientation method from supportsOrientation #77

Merged
merged 1 commit into from
Dec 31, 2020
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
23 changes: 21 additions & 2 deletions magicgui/widgets/_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 1 addition & 14 deletions magicgui/widgets/_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down