TabDock

Implementation of a tabbed dock widget.

This is more constrained and opinionated than the built-in Qt docking elements, and it is easier to deploy than the Qt Advanced Docking system, with accordingly less functionality.

This was originally LucidDock from the lucid module, ported here to have lighter dependencies and to be more generic.

../../../_images/tab_dock.png
class pcdswidgets.common.dock.tab_dock.TabDock(parent: QWidget | None = None)[source]

A widget that implements tabbed dock/undock functionality.

The widget contents of the dock can be changed using a TabDockButton, or by implementing other widgets that call the classmethods here.

It is expected but not enforced that only one TabDock exists at a time. If multiple TabDock widgets exist, the most recently created dock is the main dock.

Most of the functionality is exposed as classmethods so that other code does not have to locate the dock singleton, instead you can reference the TabDock class directly.

You should usually populate the dock by calling TabDock.add_to_dock_user_keybinds, which will: - Replace the current tab if no modifiers are held - Add a new tab if the ctrl modifier key is held - Open in a new window if the shift modifier key is held - Open in a new window if the dock is not visible

or TabDock.add_to_dock_user_menu, which does the same but with clickable menu options.

Parameters:

parent (QWidget, optional) – Standard qt parent argument

classmethod add_many_to_dock_user_menu(widget_list: list[QWidget] | Callable[[], list[QWidget]], title_list: list[str] | Callable[[], list[str]] | None = None, pos: QPoint | None = None, menu: QMenu | None = None) → QMenu[source]

Add widgets to the dock, with a menu and multiple widgets at once.

This is the third intended way to add widgets from external code.

This creates a compact menu where we can either open every widget in a new tab or every widget in a new window.

Parameters:
  • widget_list (DeferredWidgetList) – The widgets to use, or a callable to produce the widgets right before they are needed.

  • title_list (DeferredWidgetList, optional) – The title of each tab and/or window, or a callable to produce the titles right before they are needed. If omitted we’ll use each widget’s windowTitle.

  • pos (QPoint, optional) – The position to open the menu at. If omitted, we won’t open the menu.

  • menu (QMenu, optional) – If provided, we’ll add actions to this menu rather than create a new menu. This is used to include these menus as submenus of other menus.

Returns:

menu

Return type:

QMenu

classmethod add_to_dock(widget: QWidget | Callable[[], QWidget], title: str = '', new_tab: bool = False, tab_widget: QTabWidget | None = None)[source]

Add a widget to the tabbed docking area.

This is used internally in TabDock to service the external-facing methods.

Parameters:
  • widget (DeferredWidget) – The widget to use, or a callable to produce the widget right before it is needed.

  • title (str, optional) – The title of the tab and/or window. If omitted we’ll use the widget’s windowTitle.

  • new_tab (bool, optional) – If True, opens a new tab for the widget. If False, overwrites the current open tab. Defaults to False.

  • tab_widget (QTabWidget, optional) – If provided, make sure to put the widget into a specific tabbed docking area. Otherwise, we’ll find the first open dock, or default to the first dock if all are occupied.

classmethod add_to_dock_many(widget_list: list[QWidget] | Callable[[], list[QWidget]], title_list: list[str] | Callable[[], list[str]] | None = None)[source]

Add many widgets to the docking area in new tabs all at once.

Used in add_many_to_dock_user_menu.

Parameters:
  • widget_list (DeferredWidgetList) – The widgets to use, or a callable to produce the widgets right before they are needed.

  • title_list (DeferredWidgetList, optional) – The title of each tab, or a callable to produce the titles right before they are needed. If omitted we’ll use each widget’s windowTitle.

classmethod add_to_dock_user_keybinds(widget: QWidget | Callable[[], QWidget], title: str = '')[source]

Add widgets to the dock, based on the user keypresses.

This is the first intended way to add widgets from external code.

This checks the user’s modifier keys and opens the widget in the current tab (default), a new tab (ctrl), or a new window (shift, or invisible dock) as appropriate.

Parameters:
  • widget (DeferredWidget) – The widget to use, or a callable to produce the widget right before it is needed.

  • title (str) – The title of the tab and/or window. If omitted we’ll use the widget’s windowTitle

classmethod add_to_dock_user_menu(widget: QWidget | Callable[[], QWidget], title: str = '', pos: QPoint | None = None, menu: QMenu | None = None) → QMenu[source]

Add widgets to the dock, with a multiple choice menu.

This is the second intended way to add widgets from external code.

Rather than using modifier keys like add_to_dock_user_keybinds, this creates a compact menu with each variant as an option.

Parameters:
  • widget (DeferredWidget) – The widget to use, or a callable to produce the widget right before it is needed.

  • title (str, optional) – The title of the tab and/or window. If omitted we’ll use the widget’s windowTitle.

  • pos (QPoint, optional) – The position to open the menu at. If omitted, we won’t open the menu.

  • menu (QMenu, optional) – If provided, we’ll add actions to this menu rather than create a new menu. This is used to include these menus as submenus of other menus.

Returns:

menu

Return type:

QMenu

apply_settings()[source]

Apply settings changes from the dock settings dialog.

clean_detached_widgets()[source]

Prunes the lists of tracked widgets to remove any windows that the user has closed.

Closed windows are not eligible to be reattached to the dock.

classmethod clear_instance()[source]

Forget about any existing TabDock instance.

close_tab(tab_widget: QTabWidget)[source]

Remove the currently opened tab.

detach_from_dock(tab_widget: QTabWidget)[source]

Move the widget from the currently opened tab into a floating window.

The tab text will be preserved and moved to the window’s title.

classmethod dock_exists() → bool[source]

Return True if a tab dock exists.

classmethod get_instance() → TabDock[source]

Return the TabDock instance or raise if there is not one.

get_open_tab_widget() → QTabWidget[source]

Return the first tab widget that is empty and visible.

If no tab widget is empty and visible, returns the first tab widget.

has_empty_tab() → bool[source]

Return True if any tab is empty as visible.

classmethod open_in_new_window(widget: QWidget | Callable[[], QWidget], title: str = '')[source]

Move a widget into a floating window and let it be tracked by the dock.

In contrast with a window opened by a PydmRelatedDisplay widget, this allows the floating window to be recalled to the dock at any time.

Parameters:
  • widget (DeferredWidget) – The widget to use, or a callable to produce the widget right before it is needed.

  • title (str, optional) – The title of the tab and/or window. If omitted we’ll use the widget’s windowTitle.

classmethod open_in_new_window_many(widget_list: list[QWidget] | Callable[[], list[QWidget]], title_list: list[str] | Callable[[], list[str]] | None = None)[source]

Open many widgets in detached dock mode dialogs all at once.

Used in add_many_to_dock_user_menu.

Parameters:
  • widget_list (DeferredWidgetList) – The widgets to use, or a callable to produce the widgets right before they are needed.

  • title_list (DeferredWidgetList, optional) – The title of each window, or a callable to produce the titles right before they are needed. If omitted we’ll use each widget’s windowTitle.

reattach_to_dock(widget: QWidget, tab_widget: QTabWidget)[source]

Reattaches a specific widget to the dock in a new tab.

The window title will be preserved and placed in the tab’s text field.

Parameters:

widget (QWidget) – The widget to return to the dock

reattach_user_choice(tab_widget: QTabWidget)[source]

Lets the user select a widget to return to the dock in a new tab.

If there are no eligible widgets, this does nothing. If there is only one eligible widget, this will return that widget to the dock. If there are two or more eligible widgets, this will open the attach menu, so the user can pick one widget.

The window title will be preserved and placed in the tab’s text field.

classmethod set_fixed_tab_width(width: int)[source]

Set the width of the individual tab widgets that make up the TabDock widget.

Every tab widget will have the same width. The default tab width is 850, defined in this class’s __init__.

Parameters:

width (int) – The width of the tab areas in pixels.

show_attach_menu(tab_widget: QTabWidget, pos: QPoint | None = None) → QMenu[source]

Create a menu that can be used to reattach one tracked widget to the dock.

The window title will be preserved and placed in the tab’s text field.

show_correct_tab_buttons(new_idx: int, tab_widget: QTabWidget)[source]

Ensure that the undock/close buttons are only visible on the active tab.

Otherwise, it’s really easy to accidentally close/undock tabs when trying to change tabs.

Parameters:

new_idx (int) – The integer of the currently open tab. This is intended be passed by the QTabWidget’s “currentChanged” signal.

show_settings()[source]

Show dock settings in a pop-up dialog.

static show_widget_at_cursor(widget: QWidget) → None[source]

Re-usable internals of open_in_new_window. Provided separately for cases where there is no dock.

update_attach_enabled()[source]

Enable the attach button if we have any detached widgets, otherwise disables it.