Skip to content

Commit

Permalink
rework WaiterOverlay with @vallsv.
Browse files Browse the repository at this point in the history
* register to ResizeWidget event
* remove text from constructor
* move background to 'semi transparent'
* if the wiget is a PlotWidget prefer center it to the `getWidgetHandle` instead of the plot itself
  • Loading branch information
payno committed Jul 10, 2023
1 parent f6ca34b commit 1f2c97f
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/silx/gui/utils/waiteroverlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,36 @@
from typing import Optional
from silx.gui.widgets.WaitingPushButton import WaitingPushButton
from silx.gui import qt
from silx.gui.plot import PlotWidget


class WaiterOverlay:
def __init__(self, underlying_widget: qt.QWidget, text: Optional[str]=None) -> None:
class WaiterOverlay(qt.QObject):
def __init__(self, underlying_widget: qt.QWidget) -> None:
"""
:param qt.QWidget underlying_widget: widget on top of which we want to displat the "processing/waiting wheel"
:param str waiting_text: text to apply near the processing wheel
"""
super().__init__()

# TO be checked with thomas
if isinstance(underlying_widget, PlotWidget):
underlying_widget = underlying_widget.getWidgetHandle()

if not isinstance(underlying_widget, qt.QWidget):
raise TypeError
raise TypeError(f"underlying_widget is expected to be an instance of QWidget. {type(underlying_widget)} provided.")
self._baseWidget = weakref.ref(underlying_widget)
self._waitingButton = WaitingPushButton(
parent=underlying_widget,
text=text,
)
self._waitingButton.setDown(True)
self._waitingButton.setVisible(False)
self._waitingButton.setStyleSheet("QPushButton { background-color: transparent; border: 0px }")
self.resize()
self._waitingButton.setStyleSheet("QPushButton { background-color: rgba(150, 150, 150, 40); border: 0px; border-radius: 10px; }")
self._resize()
# register to resize event
underlying_widget.installEventFilter(self)

def setText(self, text: str):
self._waitingButton.setText(text)

def getBaseWidget(self) -> Optional[qt.QWidget]:
return self._baseWidget()
Expand All @@ -29,8 +40,7 @@ def setWaiting(self, activate=True):
self._waitingButton.setWaiting(activate)
self._waitingButton.setVisible(activate)

def resize(self):
# should be called by the widget when resized to keep displaying it in the middle
def _resize(self):
parent = self.getBaseWidget()
if parent is None:
return
Expand All @@ -40,3 +50,8 @@ def resize(self):
position = (position - size) / 2
rect = qt.QRect(qt.QPoint(position.width(), position.height()), size)
self._waitingButton.setGeometry(rect)

def eventFilter(self, watched: qt.QWidget, event: qt.QEvent):
if event.type() == qt.QEvent.Resize:
self._resize()
return super().eventFilter(watched, event)

0 comments on commit 1f2c97f

Please sign in to comment.