mirror of
https://github.com/bec-project/bec_widgets.git
synced 2026-05-09 08:12:15 +02:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 65dceead0c | |||
| 20125139f0 |
@@ -336,6 +336,13 @@ class BECDock(RPCBase):
|
|||||||
Detach the dock from the parent dock area.
|
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):
|
class BECDockArea(RPCBase, BECGuiClientMixin):
|
||||||
@property
|
@property
|
||||||
@@ -394,6 +401,7 @@ class BECDockArea(RPCBase, BECGuiClientMixin):
|
|||||||
name: "str" = None,
|
name: "str" = None,
|
||||||
position: "Literal['bottom', 'top', 'left', 'right', 'above', 'below']" = None,
|
position: "Literal['bottom', 'top', 'left', 'right', 'above', 'below']" = None,
|
||||||
relative_to: "BECDock | None" = None,
|
relative_to: "BECDock | None" = None,
|
||||||
|
temporary: "bool" = False,
|
||||||
closable: "bool" = True,
|
closable: "bool" = True,
|
||||||
floating: "bool" = False,
|
floating: "bool" = False,
|
||||||
prefix: "str" = "dock",
|
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.
|
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.
|
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.
|
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.
|
closable(bool): Whether the dock is closable.
|
||||||
floating(bool): Whether the dock is detached after creating.
|
floating(bool): Whether the dock is detached after creating.
|
||||||
prefix(str): The prefix for the dock name if no name is provided.
|
prefix(str): The prefix for the dock name if no name is provided.
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import TYPE_CHECKING, Any, Literal, Optional
|
from typing import TYPE_CHECKING, Any, Literal, Optional
|
||||||
|
|
||||||
|
from qtpy.QtCore import QSize
|
||||||
from pydantic import Field
|
from pydantic import Field
|
||||||
from pyqtgraph.dockarea import Dock, DockLabel
|
from pyqtgraph.dockarea import Dock, DockLabel
|
||||||
from qtpy import QtCore, QtGui
|
from qtpy import QtCore, QtGui
|
||||||
@@ -116,6 +117,7 @@ class BECDock(BECWidget, Dock):
|
|||||||
"remove",
|
"remove",
|
||||||
"attach",
|
"attach",
|
||||||
"detach",
|
"detach",
|
||||||
|
"close",
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@@ -126,6 +128,7 @@ class BECDock(BECWidget, Dock):
|
|||||||
name: str | None = None,
|
name: str | None = None,
|
||||||
client=None,
|
client=None,
|
||||||
gui_id: str | None = None,
|
gui_id: str | None = None,
|
||||||
|
temp: bool = False,
|
||||||
closable: bool = True,
|
closable: bool = True,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> None:
|
) -> None:
|
||||||
@@ -147,6 +150,8 @@ class BECDock(BECWidget, Dock):
|
|||||||
# Layout Manager
|
# Layout Manager
|
||||||
self.layout_manager = GridLayoutManager(self.layout)
|
self.layout_manager = GridLayoutManager(self.layout)
|
||||||
|
|
||||||
|
self.temp = temp
|
||||||
|
|
||||||
def dropEvent(self, event):
|
def dropEvent(self, event):
|
||||||
source = event.source()
|
source = event.source()
|
||||||
old_area = source.area
|
old_area = source.area
|
||||||
@@ -172,6 +177,24 @@ class BECDock(BECWidget, Dock):
|
|||||||
else:
|
else:
|
||||||
super().float()
|
super().float()
|
||||||
|
|
||||||
|
if self.temp:
|
||||||
|
self.make_dock_temporary()
|
||||||
|
|
||||||
|
def make_dock_temporary(self):
|
||||||
|
"""
|
||||||
|
Make the dock temporary.
|
||||||
|
"""
|
||||||
|
|
||||||
|
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.panels[self.name()] = self
|
||||||
|
self.config.parent_dock_area = self.area.gui_id
|
||||||
|
self.area.temporary = False
|
||||||
|
self.hide_title_bar()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def widget_list(self) -> list[BECWidget]:
|
def widget_list(self) -> list[BECWidget]:
|
||||||
"""
|
"""
|
||||||
@@ -333,3 +356,7 @@ class BECDock(BECWidget, Dock):
|
|||||||
self.cleanup()
|
self.cleanup()
|
||||||
super().close()
|
super().close()
|
||||||
self.parent_dock_area.dock_area.docks.pop(self.name(), None)
|
self.parent_dock_area.dock_area.docks.pop(self.name(), None)
|
||||||
|
|
||||||
|
if self.temp:
|
||||||
|
self.area.deleteLater()
|
||||||
|
self.deleteLater()
|
||||||
|
|||||||
@@ -278,6 +278,7 @@ class BECDockArea(BECWidget, QWidget):
|
|||||||
name: str = None,
|
name: str = None,
|
||||||
position: Literal["bottom", "top", "left", "right", "above", "below"] = None,
|
position: Literal["bottom", "top", "left", "right", "above", "below"] = None,
|
||||||
relative_to: BECDock | None = None,
|
relative_to: BECDock | None = None,
|
||||||
|
temporary: bool = False,
|
||||||
closable: bool = True,
|
closable: bool = True,
|
||||||
floating: bool = False,
|
floating: bool = False,
|
||||||
prefix: str = "dock",
|
prefix: str = "dock",
|
||||||
@@ -294,6 +295,7 @@ class BECDockArea(BECWidget, QWidget):
|
|||||||
name(str): The name of the dock to be displayed and for further references. Has to be unique.
|
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.
|
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.
|
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.
|
closable(bool): Whether the dock is closable.
|
||||||
floating(bool): Whether the dock is detached after creating.
|
floating(bool): Whether the dock is detached after creating.
|
||||||
prefix(str): The prefix for the dock name if no name is provided.
|
prefix(str): The prefix for the dock name if no name is provided.
|
||||||
@@ -317,7 +319,7 @@ class BECDockArea(BECWidget, QWidget):
|
|||||||
if position is None:
|
if position is None:
|
||||||
position = "bottom"
|
position = "bottom"
|
||||||
|
|
||||||
dock = BECDock(name=name, parent_dock_area=self, closable=closable)
|
dock = BECDock(name=name, parent_dock_area=self, closable=closable, temp=temporary)
|
||||||
dock.config.position = position
|
dock.config.position = position
|
||||||
self.config.docks[name] = dock.config
|
self.config.docks[name] = dock.config
|
||||||
|
|
||||||
@@ -338,10 +340,19 @@ class BECDockArea(BECWidget, QWidget):
|
|||||||
): # TODO still decide how initial instructions should be handled
|
): # TODO still decide how initial instructions should be handled
|
||||||
self._instructions_visible = False
|
self._instructions_visible = False
|
||||||
self.update()
|
self.update()
|
||||||
if floating:
|
if floating or temporary:
|
||||||
dock.detach()
|
dock.detach()
|
||||||
|
print("dock added")
|
||||||
return dock
|
return dock
|
||||||
|
|
||||||
|
# def add_temp_dock(self):
|
||||||
|
# area = BECDockArea()
|
||||||
|
# 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:
|
def detach_dock(self, dock_name: str) -> BECDock:
|
||||||
"""
|
"""
|
||||||
Undock a dock from the dock area.
|
Undock a dock from the dock area.
|
||||||
@@ -402,6 +413,11 @@ class BECDockArea(BECWidget, QWidget):
|
|||||||
self.cleanup()
|
self.cleanup()
|
||||||
super().close()
|
super().close()
|
||||||
|
|
||||||
|
def closeEvent(self, event):
|
||||||
|
print("close event called")
|
||||||
|
self.cleanup()
|
||||||
|
super().closeEvent(event)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
from qtpy.QtWidgets import QApplication
|
from qtpy.QtWidgets import QApplication
|
||||||
@@ -412,4 +428,5 @@ if __name__ == "__main__":
|
|||||||
set_theme("auto")
|
set_theme("auto")
|
||||||
dock_area = BECDockArea()
|
dock_area = BECDockArea()
|
||||||
dock_area.show()
|
dock_area.show()
|
||||||
|
dock_area.add_dock("dock1", widget="BECFigure", temporary=True)
|
||||||
app.exec_()
|
app.exec_()
|
||||||
|
|||||||
Reference in New Issue
Block a user