Skip to content

main_panel

freecad.datamanager_wb.ui.main_panel

Main Qt panel for the DataManager workbench.

Loads the .ui file, finds widgets, wires signals, and delegates operations to PanelController.

MainPanel(*, gui_port=None, app_port=None, settings_port=None)

Main Qt panel for the DataManager workbench.

Responsibilities:

  • Load the Qt Designer .ui file.
  • Find and configure required widgets.
  • Connect UI signals to handler methods.
  • Delegate domain operations to PanelController.

This class is the primary bridge between FreeCAD GUI events and the workbench controller/data layers.

Source code in freecad/datamanager_wb/ui/main_panel.py
def __init__(
    self,
    *,
    gui_port: GuiPort | None = None,
    app_port: AppPort | None = None,
    settings_port: SettingsPort | None = None,
):
    super().__init__()
    self._gui_port: GuiPort = gui_port or FreeCadGuiAdapter()
    self._app_port: AppPort = app_port or FreeCadAppAdapter()
    self._settings_port: SettingsPort = settings_port or QtSettingsAdapter(
        group=_SETTINGS_GROUP,
        app=_SETTINGS_APP,
    )
    self._mdi_subwindow = None
    self._controller = PanelController()
    self._presenter = MainPanelPresenter(self._controller)
    self._copy_map: dict[QtWidgets.QListWidget, QtWidgets.QAbstractButton] = {}
    self._active_doc_name: str | None = None
    self._active_doc_timer: QtCore.QTimer | None = None

    self.form = self._load_ui()
    self._widget = self._resolve_root_widget()

    self._find_widgets()
    self._configure_widgets()
    self._populate_varsets()
    self._populate_spreadsheets()
    self._connect_signals()
    self._start_active_document_watch()

form = self._load_ui() instance-attribute

accept()

Close the panel (Qt dialog accept semantics).

When hosted inside FreeCAD's MDI, closes the subwindow; otherwise closes the top-level form.

Source code in freecad/datamanager_wb/ui/main_panel.py
def accept(self):
    """Close the panel (Qt dialog accept semantics).

    When hosted inside FreeCAD's MDI, closes the subwindow; otherwise closes
    the top-level form.
    """
    self._stop_active_document_watch()
    self._save_splitter_states()
    if self._mdi_subwindow is not None:
        self._mdi_subwindow.close()
    else:
        self.form.close()

eventFilter(watched, event)

Intercept focus events on list widgets to update copy-button state.

Source code in freecad/datamanager_wb/ui/main_panel.py
def eventFilter(self, watched: QtCore.QObject, event: QtCore.QEvent) -> bool:  # noqa: N802
    """Intercept focus events on list widgets to update copy-button state."""
    if isinstance(watched, QtWidgets.QListWidget) and watched in self._copy_map:
        if event.type() in (
            QtCore.QEvent.Type.FocusIn,
            QtCore.QEvent.Type.MouseButtonPress,
        ):
            QtCore.QTimer.singleShot(0, self._update_copy_buttons_enabled_state)
    return super().eventFilter(watched, event)

reject()

Close the panel (Qt dialog reject semantics).

Source code in freecad/datamanager_wb/ui/main_panel.py
def reject(self):
    """Close the panel (Qt dialog reject semantics)."""
    self._stop_active_document_watch()
    self._save_splitter_states()
    if self._mdi_subwindow is not None:
        self._mdi_subwindow.close()
    else:
        self.form.close()

show(*, tab_index=None)

Show the panel, optionally selecting a tab.

Parameters:

Name Type Description Default
tab_index int | None

When provided, selects the corresponding tab index before showing the panel.

None
Source code in freecad/datamanager_wb/ui/main_panel.py
def show(self, *, tab_index: int | None = None):  # noqa: A003
    """Show the panel, optionally selecting a tab.

    Args:
        tab_index: When provided, selects the corresponding tab index before
            showing the panel.
    """
    self._apply_requested_tab_index(tab_index)

    mdi = self._gui_port.get_mdi_area()
    plan = self._presenter.get_show_plan(
        mdi_available=mdi is not None,
        has_existing_subwindow=self._mdi_subwindow is not None,
    )

    if self._try_show_standalone(plan):
        return
    if self._try_reuse_subwindow(plan):
        return

    self._ensure_mdi_subwindow(plan=plan, mdi=mdi)
    self._mdi_subwindow.setWindowTitle(self._app_port.translate("Workbench", "Data Manager"))
    self._mdi_subwindow._dm_main_panel = self  # pylint: disable=protected-access
    self._mdi_subwindow.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
    self._mdi_subwindow.destroyed.connect(self._on_subwindow_destroyed)
    self._mdi_subwindow.showMaximized()

get_main_panel() cached

Return a cached singleton instance of the workbench main panel.

The workbench registers FreeCAD commands that open the panel. Using a cached factory ensures command activations reuse the same Qt widget instance instead of creating multiple panels.

Source code in freecad/datamanager_wb/ui/main_panel.py
@functools.lru_cache(maxsize=1)
def get_main_panel() -> "MainPanel":
    """Return a cached singleton instance of the workbench main panel.

    The workbench registers FreeCAD commands that open the panel. Using a
    cached factory ensures command activations reuse the same Qt widget instance
    instead of creating multiple panels.
    """
    return MainPanel()