Skip to content

Commit

Permalink
add height options too
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Jan 20, 2021
1 parent d2e7a0b commit 5710b6a
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 9 deletions.
26 changes: 26 additions & 0 deletions magicgui/backends/_qtpy/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,32 @@ def _mgui_set_max_width(self, value: int) -> None:
self._qwidget.setMaximumWidth(value)
self._qwidget.resize(self._qwidget.sizeHint())

def _mgui_get_height(self) -> int:
"""Return the current height of the widget."""
return self._qwidget.height()

def _mgui_set_height(self, value: int) -> None:
"""Set the current height of the widget."""
self._qwidget.resize(self._qwidget.width(), value)

def _mgui_get_min_height(self) -> int:
"""Get the minimum allowable height of the widget."""
return self._qwidget.minimumHeight()

def _mgui_set_min_height(self, value: int) -> None:
"""Set the minimum allowable height of the widget."""
self._qwidget.setMinimumHeight(value)
self._qwidget.resize(self._qwidget.sizeHint())

def _mgui_get_max_height(self) -> int:
"""Get the maximum allowable height of the widget."""
return self._qwidget.maximumHeight()

def _mgui_set_max_height(self, value: int) -> None:
"""Set the maximum allowable height of the widget."""
self._qwidget.setMaximumHeight(value)
self._qwidget.resize(self._qwidget.sizeHint())

def _mgui_get_tooltip(self) -> str:
return self._qwidget.toolTip()

Expand Down
39 changes: 31 additions & 8 deletions magicgui/widgets/_bases/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,7 @@ def label(self, value):

@property
def width(self) -> int:
"""Return the current width of the widget.
The intention is to get the width of the widget after it is shown, for the
purpose of unifying widget width in a layout. Backends may do what they need to
accomplish this. For example, Qt can use ``sizeHint().width()``, since
``width()`` will return something large if the widget has not yet been painted
on screen.
"""
"""Return the current width of the widget."""
return self._widget._mgui_get_width()

@width.setter
Expand Down Expand Up @@ -216,6 +209,36 @@ def max_width(self, value: int) -> None:
"""Set the maximum width of the widget."""
self._widget._mgui_set_max_width(value)

@property
def height(self) -> int:
"""Return the current height of the widget."""
return self._widget._mgui_get_height()

@height.setter
def height(self, value: int) -> None:
"""Set the minimum allowable height of the widget."""
self._widget._mgui_set_height(value)

@property
def min_height(self) -> int:
"""Get the minimum height of the widget."""
return self._widget._mgui_get_min_height()

@min_height.setter
def min_height(self, value: int) -> None:
"""Set the minimum height of the widget."""
self._widget._mgui_set_min_height(value)

@property
def max_height(self) -> int:
"""Get the maximum height of the widget."""
return self._widget._mgui_get_max_height()

@max_height.setter
def max_height(self, value: int) -> None:
"""Set the maximum height of the widget."""
self._widget._mgui_set_max_height(value)

@property
def tooltip(self) -> Optional[str]:
"""Get the tooltip for this widget."""
Expand Down
46 changes: 45 additions & 1 deletion magicgui/widgets/_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ def _mgui_render(self) -> "np.ndarray":

@abstractmethod
def _mgui_get_width(self) -> int:
"""Get the width of the widget."""
"""Get the width of the widget.
The intention is to get the width of the widget after it is shown, for the
purpose of unifying widget width in a layout. Backends may do what they need to
accomplish this. For example, Qt can use ``sizeHint().width()``, since
``width()`` may return something large if the widget has not yet been painted
on screen.
"""
raise NotImplementedError()

@abstractmethod
Expand Down Expand Up @@ -127,6 +134,43 @@ def _mgui_set_max_width(self, value: int) -> None:
"""Set the maximum width of the widget."""
raise NotImplementedError()

@abstractmethod
def _mgui_get_height(self) -> int:
"""Get the height of the widget.
The intention is to get the height of the widget after it is shown, for the
purpose of unifying widget height in a layout. Backends may do what they need to
accomplish this. For example, Qt can use ``sizeHint().height()``, since
``height()`` may return something large if the widget has not yet been painted
on screen.
"""
raise NotImplementedError()

@abstractmethod
def _mgui_set_height(self, value: int) -> None:
"""Set the height of the widget."""
raise NotImplementedError()

@abstractmethod
def _mgui_get_min_height(self) -> int:
"""Get the minimum height of the widget."""
raise NotImplementedError()

@abstractmethod
def _mgui_set_min_height(self, value: int) -> None:
"""Set the minimum height of the widget."""
raise NotImplementedError()

@abstractmethod
def _mgui_get_max_height(self) -> int:
"""Get the maximum height of the widget."""
raise NotImplementedError()

@abstractmethod
def _mgui_set_max_height(self, value: int) -> None:
"""Set the maximum height of the widget."""
raise NotImplementedError()

@abstractmethod
def _mgui_get_tooltip(self) -> str:
"""Get the tooltip for this widget."""
Expand Down
6 changes: 6 additions & 0 deletions tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ def _mgui_get_min_width(self): ... # noqa
def _mgui_set_min_width(self, value: int): ... # noqa
def _mgui_get_max_width(self): ... # noqa
def _mgui_set_max_width(self, value: int): ... # noqa
def _mgui_get_height(self): ... # noqa
def _mgui_set_height(self, value: int): ... # noqa
def _mgui_get_min_height(self): ... # noqa
def _mgui_set_min_height(self, value: int): ... # noqa
def _mgui_get_max_height(self): ... # noqa
def _mgui_set_max_height(self, value: int): ... # noqa
def _mgui_get_value(self): ... # noqa
def _mgui_set_value(self, value): ... # noqa
def _mgui_bind_change_callback(self, callback): ... # noqa
Expand Down

0 comments on commit 5710b6a

Please sign in to comment.