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

fix(dock): add_widget and add_widget_bec consolidated

This commit is contained in:
2024-06-06 00:06:11 +02:00
parent a3805a765b
commit 8ae323f5c3
3 changed files with 49 additions and 40 deletions

View File

@ -30,7 +30,7 @@ class AutoUpdates:
Create a default dock for the auto updates.
"""
dock = self.gui.add_dock("default_figure")
dock.add_widget_bec("BECFigure")
dock.add_widget("BECFigure")
self.dock_name = "default_figure"
@staticmethod

View File

@ -1468,20 +1468,20 @@ class BECDock(RPCBase):
"""
@rpc_call
def add_widget_bec(
def add_widget(
self,
widget_type: "str",
widget: "BECConnector | str",
row=None,
col=0,
rowspan=1,
colspan=1,
shift: "Literal['down', 'up', 'left', 'right']" = "down",
):
) -> "BECConnector":
"""
Add a widget to the dock.
Args:
widget_type(str): The widget to add. Only BEC RPC widgets from RPCWidgetHandler are allowed.
widget(QWidget): The widget to add.
row(int): The row to add the widget to. If None, the widget will be added to the next available row.
col(int): The column to add the widget to.
rowspan(int): The number of rows the widget should span.

View File

@ -33,7 +33,7 @@ class BECDock(BECConnector, Dock):
"hide_title_bar",
"get_widgets_positions",
"set_title",
"add_widget_bec",
"add_widget",
"list_eligible_widgets",
"move_widget",
"remove_widget",
@ -152,47 +152,47 @@ class BECDock(BECConnector, Dock):
"""
return list(RPCWidgetHandler.widget_classes.keys())
def add_widget_bec(
self,
widget_type: str,
row=None,
col=0,
rowspan=1,
colspan=1,
shift: Literal["down", "up", "left", "right"] = "down",
):
"""
Add a widget to the dock.
Args:
widget_type(str): The widget to add. Only BEC RPC widgets from RPCWidgetHandler are allowed.
row(int): The row to add the widget to. If None, the widget will be added to the next available row.
col(int): The column to add the widget to.
rowspan(int): The number of rows the widget should span.
colspan(int): The number of columns the widget should span.
shift(Literal["down", "up", "left", "right"]): The direction to shift the widgets if the position is occupied.
"""
if row is None:
row = self.layout.rowCount()
if self.layout_manager.is_position_occupied(row, col):
self.layout_manager.shift_widgets(shift, start_row=row)
widget = RPCWidgetHandler.create_widget(widget_type)
self.addWidget(widget, row=row, col=col, rowspan=rowspan, colspan=colspan)
self.config.widgets[widget.gui_id] = widget.config
return widget
# def add_widget_bec(
# self,
# widget_type: str,
# row=None,
# col=0,
# rowspan=1,
# colspan=1,
# shift: Literal["down", "up", "left", "right"] = "down",
# ):
# """
# Add a widget to the dock.
#
# Args:
# widget_type(str): The widget to add. Only BEC RPC widgets from RPCWidgetHandler are allowed.
# row(int): The row to add the widget to. If None, the widget will be added to the next available row.
# col(int): The column to add the widget to.
# rowspan(int): The number of rows the widget should span.
# colspan(int): The number of columns the widget should span.
# shift(Literal["down", "up", "left", "right"]): The direction to shift the widgets if the position is occupied.
# """
# if row is None:
# row = self.layout.rowCount()
#
# if self.layout_manager.is_position_occupied(row, col):
# self.layout_manager.shift_widgets(shift, start_row=row)
#
# widget = RPCWidgetHandler.create_widget(widget_type)
# self.addWidget(widget, row=row, col=col, rowspan=rowspan, colspan=colspan)
# self.config.widgets[widget.gui_id] = widget.config
#
# return widget
def add_widget(
self,
widget: QWidget,
widget: BECConnector | str,
row=None,
col=0,
rowspan=1,
colspan=1,
shift: Literal["down", "up", "left", "right"] = "down",
):
) -> BECConnector:
"""
Add a widget to the dock.
@ -210,8 +210,17 @@ class BECDock(BECConnector, Dock):
if self.layout_manager.is_position_occupied(row, col):
self.layout_manager.shift_widgets(shift, start_row=row)
if isinstance(widget, str):
widget = RPCWidgetHandler.create_widget(widget)
else:
widget = widget
self.addWidget(widget, row=row, col=col, rowspan=rowspan, colspan=colspan)
self.config.widgets[widget.gui_id] = widget.config
if hasattr(widget, "config"):
self.config.widgets[widget.gui_id] = widget.config
return widget
def move_widget(self, widget: QWidget, new_row: int, new_col: int):
"""