mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
wip - namespace
This commit is contained in:
@ -78,13 +78,7 @@ class WidgetHandler:
|
|||||||
}
|
}
|
||||||
|
|
||||||
def create_widget(
|
def create_widget(
|
||||||
self,
|
self, widget_type: str, parent_figure, parent_id: str, config: dict = None, **axis_kwargs
|
||||||
widget_type: str,
|
|
||||||
widget_id: str,
|
|
||||||
parent_figure,
|
|
||||||
parent_id: str,
|
|
||||||
config: dict = None,
|
|
||||||
**axis_kwargs,
|
|
||||||
) -> BECPlotBase:
|
) -> BECPlotBase:
|
||||||
"""
|
"""
|
||||||
Create and configure a widget based on its type.
|
Create and configure a widget based on its type.
|
||||||
@ -109,7 +103,6 @@ class WidgetHandler:
|
|||||||
widget_config_dict = {
|
widget_config_dict = {
|
||||||
"widget_class": widget_class.__name__,
|
"widget_class": widget_class.__name__,
|
||||||
"parent_id": parent_id,
|
"parent_id": parent_id,
|
||||||
"gui_id": widget_id,
|
|
||||||
**(config if config is not None else {}),
|
**(config if config is not None else {}),
|
||||||
}
|
}
|
||||||
widget_config = config_class(**widget_config_dict)
|
widget_config = config_class(**widget_config_dict)
|
||||||
@ -568,13 +561,13 @@ class BECFigure(BECWidget, pg.GraphicsLayoutWidget):
|
|||||||
|
|
||||||
widget = self.widget_handler.create_widget(
|
widget = self.widget_handler.create_widget(
|
||||||
widget_type=widget_type,
|
widget_type=widget_type,
|
||||||
widget_id=widget_id,
|
|
||||||
parent_figure=self,
|
parent_figure=self,
|
||||||
parent_id=self.gui_id,
|
parent_id=self.gui_id,
|
||||||
config=config,
|
config=config,
|
||||||
**axis_kwargs,
|
**axis_kwargs,
|
||||||
)
|
)
|
||||||
widget.set_gui_id(widget_id)
|
widget_id = widget.gui_id
|
||||||
|
|
||||||
widget.config.row = row
|
widget.config.row = row
|
||||||
widget.config.col = col
|
widget.config.col = col
|
||||||
|
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
|
from bec_lib.logger import bec_logger
|
||||||
from qtpy.QtWidgets import QApplication, QMainWindow
|
from qtpy.QtWidgets import QApplication, QMainWindow
|
||||||
|
|
||||||
from bec_widgets.utils import BECConnector
|
from bec_widgets.cli.rpc.rpc_register import RPCRegister
|
||||||
|
from bec_widgets.utils.bec_widget import BECWidget
|
||||||
|
from bec_widgets.utils.container_utils import WidgetContainerUtils
|
||||||
from bec_widgets.widgets.containers.dock.dock_area import BECDockArea
|
from bec_widgets.widgets.containers.dock.dock_area import BECDockArea
|
||||||
|
|
||||||
|
logger = bec_logger.logger
|
||||||
|
|
||||||
class BECMainWindow(QMainWindow, BECConnector):
|
|
||||||
def __init__(self, *args, **kwargs):
|
class BECMainWindow(BECWidget, QMainWindow):
|
||||||
BECConnector.__init__(self, **kwargs)
|
def __init__(self, gui_id: str = None, *args, **kwargs):
|
||||||
|
BECWidget.__init__(self, gui_id=gui_id, **kwargs)
|
||||||
QMainWindow.__init__(self, *args, **kwargs)
|
QMainWindow.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
def _dump(self):
|
def _dump(self):
|
||||||
@ -33,9 +38,38 @@ class BECMainWindow(QMainWindow, BECConnector):
|
|||||||
}
|
}
|
||||||
return info
|
return info
|
||||||
|
|
||||||
def new_dock_area(self, name):
|
def new_dock_area(
|
||||||
dock_area = BECDockArea()
|
self, name: str | None = None, geometry: tuple[int, int, int, int] | None = None
|
||||||
|
) -> BECDockArea:
|
||||||
|
"""Create a new dock area.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name(str): The name of the dock area.
|
||||||
|
geometry(tuple): The geometry parameters to be passed to the dock area.
|
||||||
|
Returns:
|
||||||
|
BECDockArea: The newly created dock area.
|
||||||
|
"""
|
||||||
|
rpc_register = RPCRegister()
|
||||||
|
existing_dock_areas = rpc_register.get_names_of_rpc_by_class_type(BECDockArea)
|
||||||
|
if name is not None:
|
||||||
|
if name in existing_dock_areas:
|
||||||
|
raise ValueError(
|
||||||
|
f"Name {name} must be unique for dock areas, but already exists: {existing_dock_areas}."
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
name = "dock_area"
|
||||||
|
name = WidgetContainerUtils.generate_unique_name(name, existing_dock_areas)
|
||||||
|
dock_area = BECDockArea(name=name)
|
||||||
dock_area.resize(dock_area.minimumSizeHint())
|
dock_area.resize(dock_area.minimumSizeHint())
|
||||||
dock_area.window().setWindowTitle(name)
|
# TODO Should we simply use the specified name as title here?
|
||||||
|
dock_area.window().setWindowTitle(f"BEC - {name}")
|
||||||
|
logger.info(f"Created new dock area: {name}")
|
||||||
|
logger.info(f"Existing dock areas: {geometry}")
|
||||||
|
if geometry is not None:
|
||||||
|
dock_area.setGeometry(*geometry)
|
||||||
dock_area.show()
|
dock_area.show()
|
||||||
return dock_area
|
return dock_area
|
||||||
|
|
||||||
|
def cleanup(self):
|
||||||
|
# TODO
|
||||||
|
super().close()
|
||||||
|
@ -942,7 +942,7 @@ class PlotBase(BECWidget, QWidget):
|
|||||||
self.axis_settings_dialog.close()
|
self.axis_settings_dialog.close()
|
||||||
self.axis_settings_dialog = None
|
self.axis_settings_dialog = None
|
||||||
self.cleanup_pyqtgraph()
|
self.cleanup_pyqtgraph()
|
||||||
self.rpc_register.remove_rpc(self)
|
super().cleanup()
|
||||||
|
|
||||||
def cleanup_pyqtgraph(self):
|
def cleanup_pyqtgraph(self):
|
||||||
"""Cleanup pyqtgraph items."""
|
"""Cleanup pyqtgraph items."""
|
||||||
|
@ -117,10 +117,13 @@ class Waveform(PlotBase):
|
|||||||
client=None,
|
client=None,
|
||||||
gui_id: str | None = None,
|
gui_id: str | None = None,
|
||||||
popups: bool = True,
|
popups: bool = True,
|
||||||
|
**kwargs,
|
||||||
):
|
):
|
||||||
if config is None:
|
if config is None:
|
||||||
config = WaveformConfig(widget_class=self.__class__.__name__)
|
config = WaveformConfig(widget_class=self.__class__.__name__)
|
||||||
super().__init__(parent=parent, config=config, client=client, gui_id=gui_id, popups=popups)
|
super().__init__(
|
||||||
|
parent=parent, config=config, client=client, gui_id=gui_id, popups=popups, **kwargs
|
||||||
|
)
|
||||||
|
|
||||||
# For PropertyManager identification
|
# For PropertyManager identification
|
||||||
self.setObjectName("Waveform")
|
self.setObjectName("Waveform")
|
||||||
|
Reference in New Issue
Block a user