diff --git a/bec_widgets/cli/client.py b/bec_widgets/cli/client.py index 8b8d3594..b04e182b 100644 --- a/bec_widgets/cli/client.py +++ b/bec_widgets/cli/client.py @@ -336,6 +336,13 @@ class BECDock(RPCBase): Detach the dock from the parent dock area. """ + @rpc_call + def close(self): + """ + Close the dock area and cleanup. + Has to be implemented to overwrite pyqtgraph event accept in Container close. + """ + class BECDockArea(RPCBase, BECGuiClientMixin): @property @@ -394,6 +401,7 @@ class BECDockArea(RPCBase, BECGuiClientMixin): name: "str" = None, position: "Literal['bottom', 'top', 'left', 'right', 'above', 'below']" = None, relative_to: "BECDock | None" = None, + temporary: "bool" = False, closable: "bool" = True, floating: "bool" = False, prefix: "str" = "dock", @@ -410,6 +418,7 @@ class BECDockArea(RPCBase, BECGuiClientMixin): name(str): The name of the dock to be displayed and for further references. Has to be unique. position(Literal["bottom", "top", "left", "right", "above", "below"]): The position of the dock. relative_to(BECDock): The dock to which the new dock should be added relative to. + temp(bool): Whether the dock is temporary. Upon closing the dock is not returned to the parent dock area. closable(bool): Whether the dock is closable. floating(bool): Whether the dock is detached after creating. prefix(str): The prefix for the dock name if no name is provided. diff --git a/bec_widgets/widgets/dock/dock.py b/bec_widgets/widgets/dock/dock.py index 6fef65ef..4625e2f7 100644 --- a/bec_widgets/widgets/dock/dock.py +++ b/bec_widgets/widgets/dock/dock.py @@ -11,7 +11,6 @@ from bec_widgets.cli.rpc_wigdet_handler import widget_handler from bec_widgets.utils import ConnectionConfig, GridLayoutManager from bec_widgets.utils.bec_widget import BECWidget - if TYPE_CHECKING: from qtpy.QtWidgets import QWidget @@ -185,12 +184,13 @@ class BECDock(BECWidget, Dock): """ Make the dock temporary. """ - from bec_widgets.widgets import BECDockArea + + from bec_widgets.widgets.dock import BECDockArea self.orig_area.docks.pop(self.name(), None) self.orig_area = BECDockArea() self.area = self.orig_area - self.area.docks[self.name()] = self + self.area.panels[self.name()] = self self.config.parent_dock_area = self.area.gui_id self.area.temporary = False self.hide_title_bar() diff --git a/bec_widgets/widgets/dock/dock_area.py b/bec_widgets/widgets/dock/dock_area.py index 93f3398b..9817d8fd 100644 --- a/bec_widgets/widgets/dock/dock_area.py +++ b/bec_widgets/widgets/dock/dock_area.py @@ -278,7 +278,7 @@ class BECDockArea(BECWidget, QWidget): name: str = None, position: Literal["bottom", "top", "left", "right", "above", "below"] = None, relative_to: BECDock | None = None, - temp: bool = False, + temporary: bool = False, closable: bool = True, floating: bool = False, prefix: str = "dock", @@ -319,7 +319,7 @@ class BECDockArea(BECWidget, QWidget): if position is None: position = "bottom" - dock = BECDock(name=name, parent_dock_area=self, closable=closable, temp=temp) + dock = BECDock(name=name, parent_dock_area=self, closable=closable, temp=temporary) dock.config.position = position self.config.docks[name] = dock.config @@ -340,7 +340,7 @@ class BECDockArea(BECWidget, QWidget): ): # TODO still decide how initial instructions should be handled self._instructions_visible = False self.update() - if floating or temp: + if floating or temporary: dock.detach() print("dock added") return dock @@ -350,6 +350,9 @@ class BECDockArea(BECWidget, QWidget): # area.show() # area.add_dock("dock1", widget="BECFigure") + def addDock(self, *args, **kwargs): + return self.add_dock(*args, **kwargs) + def detach_dock(self, dock_name: str) -> BECDock: """ Undock a dock from the dock area. @@ -415,6 +418,7 @@ class BECDockArea(BECWidget, QWidget): self.cleanup() super().closeEvent(event) + if __name__ == "__main__": from qtpy.QtWidgets import QApplication @@ -424,4 +428,5 @@ if __name__ == "__main__": set_theme("auto") dock_area = BECDockArea() dock_area.show() + dock_area.add_dock("dock1", widget="BECFigure", temporary=True) app.exec_()