Skip to content

Commit

Permalink
add a tooltip kwarg to LED, ToggleSwitch and (Double)SpinBox
Browse files Browse the repository at this point in the history
  • Loading branch information
jborbely committed Oct 5, 2019
1 parent 83d4e7f commit a220884
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
8 changes: 7 additions & 1 deletion msl/qt/widgets/led.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class LED(QtWidgets.QWidget):
toggled = Signal(bool)
"""Emitted when the LED turns on :math:`\\rightarrow` off or off :math:`\\rightarrow` on."""

def __init__(self, *, parent=None, shape=Circle, on_color='#0F6900', off_color='grey', clickable=False):
def __init__(self, *, parent=None, shape=Circle, on_color='#0F6900', off_color='grey',
clickable=False, tooltip=None):
"""An LED widget, |led_widget|
.. |led_widget| image:: ../../docs/_static/led_widget.gif
Expand All @@ -57,6 +58,8 @@ def __init__(self, *, parent=None, shape=Circle, on_color='#0F6900', off_color='
about the different data types that are supported.
clickable : :class:`bool`
Whether the state of the :class:`LED` can be changed by clicking on it.
tooltip : :class:`str`, optional
The tooltip to use for the :class:`LED`.
Example
-------
Expand All @@ -78,6 +81,9 @@ def __init__(self, *, parent=None, shape=Circle, on_color='#0F6900', off_color='
self.set_clickable(clickable)
self.set_shape(shape)

if tooltip:
self.setToolTip(tooltip)

@property
def is_on(self):
""":class:`bool`: Whether the :class:`LED` is on or off."""
Expand Down
12 changes: 10 additions & 2 deletions msl/qt/widgets/spinboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

class DoubleSpinBox(QtWidgets.QDoubleSpinBox):

def __init__(self, *, parent=None, minimum=0, maximum=100, step=1, decimals=2):
def __init__(self, *, parent=None, minimum=0, maximum=100, step=1, decimals=2, tooltip=None):
"""A :class:`~QtWidgets.QDoubleSpinBox` that emits
:meth:`~QtWidgets.QAbstractSpinBox.editingFinished` after a
:meth:`~QtWidgets.QAbstractSpinBox.stepBy` signal.
Expand All @@ -44,12 +44,16 @@ def __init__(self, *, parent=None, minimum=0, maximum=100, step=1, decimals=2):
The step-by size.
decimals : :class:`int`, optional
The number of digits after the decimal place to use to show the value.
tooltip : :class:`str`, optional
The tooltip to use for the :class:`DoubleSpinBox`.
"""
super(DoubleSpinBox, self).__init__(parent=parent)
self.setMinimum(minimum)
self.setMaximum(maximum)
self.setSingleStep(step)
self.setDecimals(decimals)
if tooltip:
self.setToolTip(tooltip)

def stepBy(self, step):
"""Overrides :meth:`QtWidgets.QAbstractSpinBox.stepBy`.
Expand All @@ -64,7 +68,7 @@ def stepBy(self, step):

class SpinBox(QtWidgets.QSpinBox):

def __init__(self, *, parent=None, minimum=0, maximum=100, step=1):
def __init__(self, *, parent=None, minimum=0, maximum=100, step=1, tooltip=None):
"""A :class:`~QtWidgets.QSpinBox` that emits
:meth:`~QtWidgets.QAbstractSpinBox.editingFinished` after a
:meth:`~QtWidgets.QAbstractSpinBox.stepBy` signal.
Expand All @@ -79,11 +83,15 @@ def __init__(self, *, parent=None, minimum=0, maximum=100, step=1):
The maximum value.
step : :class:`int`, optional
The step-by size.
tooltip : :class:`str`, optional
The tooltip to use for the :class:`SpinBox`.
"""
super(SpinBox, self).__init__(parent=parent)
self.setMinimum(minimum)
self.setMaximum(maximum)
self.setSingleStep(step)
if tooltip:
self.setToolTip(tooltip)

def stepBy(self, step):
"""Overrides :meth:`QtWidgets.QAbstractSpinBox.stepBy`.
Expand Down
6 changes: 5 additions & 1 deletion msl/qt/widgets/toggle_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class ToggleSwitch(QtWidgets.QAbstractButton):

def __init__(self, *, parent=None, height=None, on_color='#009688', off_color='#B4B4B4'):
def __init__(self, *, parent=None, height=None, on_color='#009688', off_color='#B4B4B4', tooltip=None):
"""Constructs a toggle switch, |toggle_switch|
.. |toggle_switch| image:: ../../docs/_static/toggle_switch.gif
Expand All @@ -30,6 +30,8 @@ def __init__(self, *, parent=None, height=None, on_color='#009688', off_color='#
off_color
The color when the :class:`ToggleSwitch` is off. See :func:`~msl.qt.utils.to_qcolor`
for details about the different data types that are supported.
tooltip : :class:`str`, optional
The tooltip to use for the :class:`ToggleSwitch`.
Example
-------
Expand All @@ -49,6 +51,8 @@ def __init__(self, *, parent=None, height=None, on_color='#009688', off_color='#
self.setCheckable(True)
self.set_on_color(on_color)
self.set_off_color(off_color)
if tooltip:
self.setToolTip(tooltip)

@property
def is_on(self):
Expand Down

0 comments on commit a220884

Please sign in to comment.