gui_utils_base#

Various utility functions specific to the graphical interface

Warning

This file is imported by the early_boot module, so avoid heavy imports here. Any non-standard-library imports should be done locally inside functions.

class TmpDebug(workspace)[source]#

Bases: object

add_missing_combobox_items(combobox: QComboBox, items: list[str])[source]#

Add the items to the combobox if they are not already present

clear_layout(layout: QLayout)[source]#

Clears all widgets in the layout

Parameters:

layout

Returns

compute_grid(nb: int) tuple[int, int][source]#
create_clearmap_widget(ui_name: str, patch_parent_class: bool, window_title: str | None = None) QWidget[source]#
delete_widget(widget: QWidget | None = None, layout: QLayout | None = None, tool_box: QToolBox | None = None, toolbox_page_index: int | None = None) QWidget[source]#
disconnect_widget_signal(widget_signal, max_iter: int = 10, slot: Callable | None = None) None[source]#
ensure_qapp() QApplication[source]#
find_parent_layout(widget: QWidget) QLayout | None[source]#
format_long_nb(nb: int) str[source]#

Formats a long number by inserting apostrophes every three digits for better readability.

Parameters:

nb (int) – The number to be formatted.

Returns

str

The formatted number as a string with apostrophes inserted every three digits.

Examples

>>> format_long_nb(123456789)
"123'456'789"
get_widget(layout, key='', widget_type=None, index=0) tuple[QWidget | None, int][source]#

Retrieve the widget (label or control) based on the key and index.

Parameters: layout (QLayout): The layout containing the widgets. key (str): The key to search for in the widget’s objectName. index (int): The index to specify whether to get the first (0) or second (1) occurrence.

Returns: tuple: A tuple containing the found widget (or None if not found) and the total count of matching widgets.

html_to_ansi(msg: str) str[source]#
html_to_plain_text(msg: str) str[source]#
is_headless() bool[source]#
populate_combobox(box: QComboBox, items: list[str])[source]#

Replace all items in the combobox with the given items

replace_widget(old_widget: QWidget, new_widget: QWidget, layout: QLayout | None = None) QWidget[source]#

Replace a widget in a layout. If no layout is provided, the parent layout of the old widget is used The old widget is deleted.

Parameters:
  • old_widget (QWidget) – The widget to replace

  • new_widget (QWidget) – The new widget to insert

  • layout (QLayout | None) – The layout in which to replace the widget. If None, the parent layout of the old widget is used

Returns

QWidget

The new widget

unique_connect(signal: pyqtSignal, slot: Callable, *, max_disconnect_iter: int = 10, disconnect_all: bool = False) None[source]#

Connect a signal to a slot, ensuring no duplicate connections.

Parameters:
  • signal (pyqtSignal) – The signal to connect.

  • slot (callable) – The slot to connect.

  • max_disconnect_iter (int) – Maximum number of attempts to disconnect (safety valve against multiply-connected signals).

  • disconnect_all (bool) – If False (default), only disconnect slot if already connected (idempotent re-connect of the same slot). If True, disconnect ALL existing slots first, then connect slot (ensures this is the ONLY slot on the signal — useful when the slot target changes between calls, e.g. progress dialog widgets).