0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 03:31:50 +02:00

feat: add '.delete()' method to BECDockArea, make main window undeletable

This commit is contained in:
2024-12-18 15:32:05 +01:00
committed by wakonig_k
parent 48c140f937
commit 92b802021f
3 changed files with 34 additions and 0 deletions

View File

@ -487,6 +487,12 @@ class BECDockArea(RPCBase):
Hide all windows including floating docks.
"""
@rpc_call
def delete(self):
"""
None
"""
class BECFigure(RPCBase):
@property

View File

@ -288,6 +288,29 @@ def wait_for_server(client):
yield
### ----------------------------
### NOTE
### it is far easier to extend the 'delete' method on the client side,
### to know when the client is deleted, rather than listening to server
### to get notified. However, 'generate_cli.py' cannot add extra stuff
### in the generated client module. So, here a class with the same name
### is created, and client module is patched.
class BECDockArea(client.BECDockArea):
def delete(self):
if self is BECGuiClient._top_level["main"].widget:
raise RuntimeError("Cannot delete main window")
super().delete()
try:
del BECGuiClient._top_level[self._gui_id]
except KeyError:
# if a dock area is not at top level
pass
client.BECDockArea = BECDockArea
### ----------------------------
@dataclass
class WidgetDesc:
title: str

View File

@ -57,6 +57,7 @@ class BECDockArea(BECWidget, QWidget):
"temp_areas",
"show",
"hide",
"delete",
]
def __init__(
@ -444,6 +445,10 @@ class BECDockArea(BECWidget, QWidget):
continue
docks.window().hide()
def delete(self):
self.hide()
self.deleteLater()
if __name__ == "__main__":
from qtpy.QtWidgets import QApplication