Skip to content

qt_gui

Classes:

Name Description
AboutDialog

About dialog.

DcsPyQtGui

PySide6 GUI for DCSpy.

GitCloneWorker

Worker for git clone with reporting progress.

QTextEditLogHandler

GUI log handler.

UiLoader

UI file loader.

Worker

Runnable worker.

WorkerSignals

Defines the signals available from a running worker thread.

WorkerSignalsMixIn

Worker signals Mixin.

AboutDialog

AboutDialog(parent)

Bases: QDialog

About dialog.

Dcspy about dialog window.

Methods:

Name Description
showEvent

Prepare all information about DCSpy application.

Source code in src/dcspy/qt_gui.py
1826
1827
1828
1829
1830
1831
1832
1833
1834
def __init__(self, parent) -> None:
    """Dcspy about dialog window."""
    super().__init__(parent)
    self.parent: DcsPyQtGui | QWidget = parent
    UiLoader().load_ui(':/ui/ui/about.ui', self)
    self.tb_info: QTextBrowser = self.findChild(QTextBrowser, 'tb_info')
    self.l_logo: QLabel = self.findChild(QLabel, 'l_logo')
    self.tb_licenses: QTextBrowser = self.findChild(QTextBrowser, 'tb_licenses')
    QApplication.styleHints().colorSchemeChanged.connect(self._color_scheme_switched)

showEvent

showEvent(arg__1: QShowEvent) -> None

Prepare all information about DCSpy application.

Source code in src/dcspy/qt_gui.py
1842
1843
1844
1845
1846
def showEvent(self, arg__1: QShowEvent) -> None:
    """Prepare all information about DCSpy application."""
    super().showEvent(arg__1)
    self._prepare_about()
    self._prepare_licenses()

DcsPyQtGui

DcsPyQtGui(
    cli_args=Namespace(),
    cfg_dict: DcspyConfigYaml | None = None,
)

Bases: QMainWindow

PySide6 GUI for DCSpy.

PySide6 GUI for DCSpy.

Parameters:

Name Type Description Default

cli_args

Namespace of CLI arguments

Namespace()

cfg_dict

DcspyConfigYaml | None

dict with configuration

None

Methods:

Name Description
activated

Signal of activation.

apply_configuration

Apply configuration to GUI widgets.

event_set

Set event to close the running thread.

fetch_system_data

Fetch various system-related data.

run_in_background

Worker with signals callback to schedule a GUI job in the background.

save_configuration

Save configuration from GUI.

Attributes:

Name Type Description
bios_path Path

Get the path to the DCS-BIOS directory.

bios_repo_path Path

Get the path to DCS-BIOS repository.

current_plane str

Get current plane from combo box.

dcs_path Path

Get a path to the DCS World directory.

Source code in src/dcspy/qt_gui.py
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
def __init__(self, cli_args=Namespace(), cfg_dict: DcspyConfigYaml | None = None) -> None:
    """
    PySide6 GUI for DCSpy.

    :param cli_args: Namespace of CLI arguments
    :param cfg_dict: dict with configuration
    """
    super().__init__()
    UiLoader().load_ui(':/ui/ui/qtdcs.ui', self)
    self._find_children()
    QApplication.styleHints().colorSchemeChanged.connect(self._color_scheme_switched)
    self.config = cfg_dict
    if not cfg_dict:
        self.config = load_yaml(full_path=default_yaml)
    self._init_gui_logger()
    self.threadpool = QThreadPool.globalInstance()
    LOG.debug(f'QThreadPool with {self.threadpool.maxThreadCount()} thread(s)')
    self.cli_args = cli_args
    self.event: Event = Event()
    self.device = LogitechDeviceModel(klass='', lcd_info=LcdMono)
    self.mono_font = {'large': 0, 'medium': 0, 'small': 0}
    self.color_font = {'large': 0, 'medium': 0, 'small': 0}
    self.current_row = -1
    self.current_col = -1
    self._completer_items = 0
    self._git_refs_count = 0
    self.plane_aliases = ['']
    self.ctrl_input: dict[str, dict[str, ControlKeyData]] = {}
    self.ctrl_list = ['']
    self.ctrl_depiction: dict[str, ControlDepiction] = {}
    self.input_reqs: dict[str, dict[str, GuiPlaneInputRequest]] = {}
    self.git_exec = is_git_exec_present()
    self.bios_git_addr = self.config['git_bios_repo']
    self.l_bios = version.Version('0.0.0')
    self.r_bios = version.Version('0.0.0')
    self.systray = QSystemTrayIcon()
    self.traymenu = QMenu()
    self.dw_gkeys.hide()
    self.dw_device.hide()
    self.dw_device.setFloating(True)
    self.bg_rb_input_iface = QButtonGroup(self)
    self.bg_rb_device = QButtonGroup(self)
    self._init_tray()
    self._init_combo_plane()
    self._init_menu_bar()
    self.apply_configuration(cfg=self.config)
    self._init_settings()
    self._init_devices()
    self._init_autosave()
    self._trigger_refresh_data()

    if self.cb_autoupdate_bios.isChecked():
        self._bios_check_clicked(silence=True)
    if self.cb_check_ver.isChecked():  # todo: clarify checking bios and dcspy in same way...
        data = self.fetch_system_data(silence=False)  # todo: maybe add silence
        status_ver = ''
        status_ver += f'Dcspy: {data.dcspy_ver} ' if self.config['check_ver'] else ''
        status_ver += f'BIOS: {data.bios_ver}' if self.config['check_bios'] else ''
        self.statusbar.showMessage(status_ver)
    if self.config.get('autostart', False):
        self._start_clicked()
    self.statusbar.showMessage(f'ver. {__version__}')

bios_path property

bios_path: Path

Get the path to the DCS-BIOS directory.

Returns:

Type Description
Path

Full path as Path

bios_repo_path property

bios_repo_path: Path

Get the path to DCS-BIOS repository.

Returns:

Type Description
Path

Full path as Path

current_plane property

current_plane: str

Get current plane from combo box.

Returns:

Type Description
str

Plane name as string

dcs_path property

dcs_path: Path

Get a path to the DCS World directory.

Returns:

Type Description
Path

Full path as Path

activated

activated(reason: ActivationReason) -> None

Signal of activation.

Parameters:

Name Type Description Default

reason

ActivationReason

Reason of activation

required
Source code in src/dcspy/qt_gui.py
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
def activated(self, reason: QSystemTrayIcon.ActivationReason) -> None:
    """
    Signal of activation.

    :param reason: Reason of activation
    """
    if reason == QSystemTrayIcon.ActivationReason.Trigger:
        if self.isVisible():
            self.hide()
        else:
            self.show()

apply_configuration

apply_configuration(cfg: dict) -> None

Apply configuration to GUI widgets.

Parameters:

Name Type Description Default

cfg

dict

dictionary with configuration

required
Source code in src/dcspy/qt_gui.py
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
def apply_configuration(self, cfg: dict) -> None:
    """
    Apply configuration to GUI widgets.

    :param cfg: dictionary with configuration
    """
    icon_map = {0: 'a_icons_only', 1: 'a_text_only', 2: 'a_text_beside', 3: 'a_text_under'}
    try:
        self.cb_autostart.setChecked(cfg['autostart'])
        self.cb_show_gui.setChecked(cfg['show_gui'])
        self.cb_lcd_screenshot.setChecked(cfg['save_lcd'])
        self.cb_check_ver.setChecked(cfg['check_ver'])
        self.cb_verbose.setChecked(cfg['verbose'])
        self.cb_ded_font.setChecked(cfg['f16_ded_font'])
        self.cb_autoupdate_bios.setChecked(cfg['check_bios'])
        self.le_font_name.setText(cfg['font_name'])
        self.sp_completer.setValue(cfg['completer_items'])
        self._completer_items = cfg['completer_items']
        self.combo_planes.setCurrentText(cfg['current_plane'])
        self.mono_font = {'large': int(cfg['font_mono_l']), 'medium': int(cfg['font_mono_m']), 'small': int(cfg['font_mono_s'])}
        self.color_font = {'large': int(cfg['font_color_l']), 'medium': int(cfg['font_color_m']), 'small': int(cfg['font_color_s'])}
        getattr(self, f'rb_{cfg["device"].lower()}').toggle()
        self.le_dcsdir.setText(cfg['dcs'])
        self.le_biosdir.setText(cfg['dcsbios'])
        self.le_bios_ref.setText(cfg['git_bios_ref'])
        self.le_bios_repo.setText(cfg['git_bios_repo'])
        self.cb_bios_live.setChecked(cfg['git_bios'])
        self.addDockWidget(Qt.DockWidgetArea(int(cfg['gkeys_area'])), self.dw_gkeys)
        self.dw_gkeys.setFloating(bool(cfg['gkeys_float']))
        self.addToolBar(Qt.ToolBarArea(int(cfg['toolbar_area'])), self.toolbar)
        getattr(self, icon_map.get(cfg['toolbar_style'], 'a_icons_only')).setChecked(True)
        color_mode: QAction = getattr(self, f'a_mode_{cfg["color_mode"]}')
        color_mode.setChecked(True)
        self._switch_color_mode(color_mode)
        self.tw_main.setTabEnabled(GuiTab.debug, cfg['gui_debug'])
        self.cb_debug_enable.setChecked(cfg['gui_debug'])
        self.hs_debug_font_size.setValue(cfg['debug_font_size'])
    except (TypeError, AttributeError, ValueError) as exc:
        LOG.warning(exc, exc_info=True)
        self._reset_defaults_cfg()

event_set

event_set() -> None

Set event to close the running thread.

Source code in src/dcspy/qt_gui.py
1631
1632
1633
def event_set(self) -> None:
    """Set event to close the running thread."""
    self.event.set()

fetch_system_data

fetch_system_data(silence: bool = False) -> SystemData

Fetch various system-related data.

Parameters:

Name Type Description Default

silence

bool

Perform action with silence

False

Returns:

Type Description
SystemData

SystemData named tuple with all data

Source code in src/dcspy/qt_gui.py
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
def fetch_system_data(self, silence: bool = False) -> SystemData:
    """
    Fetch various system-related data.

    :param silence: Perform action with silence
    :return: SystemData named tuple with all data
    """
    system, _, release, ver, _, proc = uname()
    dcs_ver = check_dcs_ver(Path(self.config['dcs']))
    dcspy_ver = get_version_string(repo=DCSPY_REPO_NAME, current_ver=__version__, check=self.config['check_ver'])
    bios_ver = str(self._check_local_bios())
    dcs_bios_ver = self._get_bios_full_version(silence=silence)
    git_ver = 'Not installed'
    if self.git_exec:
        from git import cmd
        git_ver = '.'.join([str(i) for i in cmd.Git().version_info])
    return SystemData(system=system, release=release, ver=ver, proc=proc, dcs_ver=dcs_ver,
                      dcspy_ver=dcspy_ver, bios_ver=bios_ver, dcs_bios_ver=dcs_bios_ver, git_ver=git_ver)

run_in_background

run_in_background(
    job: partial | Callable,
    signal_handlers: dict[str, Callable],
) -> None

Worker with signals callback to schedule a GUI job in the background.

Parameter signal_handlers is a dict with signals from WorkerSignals. Possible signals are: finished, error, result, progress. Values in dict are methods/callables as handlers/callbacks for a particular signal.

Parameters:

Name Type Description Default

job

partial | Callable

GUI method or function to run in background

required

signal_handlers

dict[str, Callable]

Signals as keys: finished, error, result, progress and values as callable

required
Source code in src/dcspy/qt_gui.py
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
def run_in_background(self, job: partial | Callable, signal_handlers: dict[str, Callable]) -> None:
    """
    Worker with signals callback to schedule a GUI job in the background.

    Parameter `signal_handlers` is a dict with signals from WorkerSignals.
    Possible signals are: `finished`, `error`, `result`, `progress`.
    Values in dict are methods/callables as handlers/callbacks for a particular signal.

    :param job: GUI method or function to run in background
    :param signal_handlers: Signals as keys: finished, error, result, progress and values as callable
    """
    progress = True if 'progress' in signal_handlers.keys() else False
    worker: QRunnable | WorkerSignalsMixIn = Worker(func=job, with_progress=progress)
    worker.setup_signal_handlers(signal_handlers=signal_handlers)
    if isinstance(job, partial):
        job_name = job.func.__name__
        args = job.args
        kwargs = job.keywords
    else:
        job_name = job.__name__
        args = ()
        kwargs = {}
    signals = {signal: handler.__name__ for signal, handler in signal_handlers.items()}
    LOG.debug(f'bg job for: {job_name} args: {args} kwargs: {kwargs} signals {signals}')
    self.threadpool.start(worker)

save_configuration

save_configuration() -> None

Save configuration from GUI.

Source code in src/dcspy/qt_gui.py
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
def save_configuration(self) -> None:
    """Save configuration from GUI."""
    cfg = {
        'api_ver': __version__,
        'device': self.device.klass,
        'autostart': self.cb_autostart.isChecked(),
        'show_gui': self.cb_show_gui.isChecked(),
        'save_lcd': self.cb_lcd_screenshot.isChecked(),
        'check_ver': self.cb_check_ver.isChecked(),
        'check_bios': self.cb_autoupdate_bios.isChecked(),
        'verbose': self.cb_verbose.isChecked(),
        'f16_ded_font': self.cb_ded_font.isChecked(),
        'dcs': self.le_dcsdir.text(),
        'dcsbios': self.le_biosdir.text(),
        'font_name': self.le_font_name.text(),
        'git_bios': self.cb_bios_live.isChecked(),
        'git_bios_ref': self.le_bios_ref.text(),
        'git_bios_repo': self.le_bios_repo.text(),
        'font_mono_l': self.mono_font['large'],
        'font_mono_m': self.mono_font['medium'],
        'font_mono_s': self.mono_font['small'],
        'font_color_l': self.color_font['large'],
        'font_color_m': self.color_font['medium'],
        'font_color_s': self.color_font['small'],
        'completer_items': self.sp_completer.value(),
        'current_plane': self.current_plane,
        'gkeys_area': self.dockWidgetArea(self.dw_gkeys).value,
        'gkeys_float': self.dw_gkeys.isFloating(),
        'toolbar_area': self.toolBarArea(self.toolbar).value,
        'toolbar_style': self.toolbar.toolButtonStyle().value,
        'gui_debug': self.cb_debug_enable.isChecked(),
        'debug_font_size': self.hs_debug_font_size.value(),
    }
    if self.device.lcd_info.type == LcdType.COLOR:
        font_cfg = {'font_color_l': self.hs_large_font.value(),
                    'font_color_m': self.hs_medium_font.value(),
                    'font_color_s': self.hs_small_font.value()}
    else:
        font_cfg = {'font_mono_l': self.hs_large_font.value(),
                    'font_mono_m': self.hs_medium_font.value(),
                    'font_mono_s': self.hs_small_font.value()}

    for mode_menu in [self.a_mode_system, self.a_mode_dark, self.a_mode_light]:
        if mode_menu.isChecked():
            color_mode = mode_menu.text().lower()
            break
    else:
        color_mode = 'system'

    cfg.update(font_cfg)
    cfg.update({'color_mode': color_mode})
    save_yaml(data=cfg, full_path=default_yaml)

GitCloneWorker

GitCloneWorker(
    git_ref: str,
    bios_path: Path,
    to_path: Path,
    repo: str,
    silence: bool = False,
)

Bases: QRunnable, WorkerSignalsMixIn

Worker for git clone with reporting progress.

Inherits from QRunnable to handler worker thread setup, signals and wrap-up.

Parameters:

Name Type Description Default

git_ref

str

Git reference

required

repo

str

Valid git repository address

required

bios_path

Path

Path to DCS-BIOS

required

to_path

Path

Path to which the repository should be cloned to

required

silence

bool

Perform action with silence

False

Methods:

Name Description
run

Clone the repository and report progress using a special object CloneProgress.

setup_signal_handlers

Connect handlers to signals.

Source code in src/dcspy/qt_gui.py
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
def __init__(self, git_ref: str, bios_path: Path, to_path: Path, repo: str, silence: bool = False) -> None:
    """
    Inherits from QRunnable to handler worker thread setup, signals and wrap-up.

    :param git_ref: Git reference
    :param repo: Valid git repository address
    :param bios_path: Path to DCS-BIOS
    :param to_path: Path to which the repository should be cloned to
    :param silence: Perform action with silence
    """
    super().__init__()
    self.git_ref = git_ref
    self.repo = repo
    self.to_path = to_path
    self.bios_path = bios_path
    self.silence = silence

run

run() -> None

Clone the repository and report progress using a special object CloneProgress.

Source code in src/dcspy/qt_gui.py
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
@Slot()
def run(self) -> None:
    """Clone the repository and report progress using a special object CloneProgress."""
    try:
        sha = check_github_repo(git_ref=self.git_ref, update=True, repo=self.repo, repo_dir=self.to_path,
                                progress=CloneProgress(self.signals.progress, self.signals.stage))
        if not self.bios_path.is_symlink():
            target = self.to_path / 'Scripts' / 'DCS-BIOS'
            cmd_symlink = f'"New-Item -ItemType SymbolicLink -Path \\"{self.bios_path}\\" -Target \\"{target}\\"'
            ps_command = f"Start-Process powershell.exe -ArgumentList '-Command {cmd_symlink}' -Verb RunAs"
            LOG.debug(f'Make symbolic link: {ps_command}')
            run_command(cmd=['powershell.exe', '-Command', ps_command])
            sleep(0.8)
        LOG.debug(f'Directory: {self.bios_path} is symbolic link: {self.bios_path.is_symlink()}')
    except Exception:
        exctype, value = sys.exc_info()[:2]
        self.signals.error.emit((exctype, value, traceback.format_exc()))
    else:
        self.signals.result.emit((sha, self.silence))
    finally:
        self.signals.finished.emit()

setup_signal_handlers

setup_signal_handlers(
    signal_handlers: dict[str, Callable[[Any], None]],
) -> None

Connect handlers to signals.

Parameters:

Name Type Description Default

signal_handlers

dict[str, Callable[[Any], None]]

Dict with signals and handlers as value.

required
Source code in src/dcspy/qt_gui.py
1925
1926
1927
1928
1929
1930
1931
1932
def setup_signal_handlers(self, signal_handlers: dict[str, Callable[[Any], None]]) -> None:
    """
    Connect handlers to signals.

    :param signal_handlers: Dict with signals and handlers as value.
    """
    for signal, handler in signal_handlers.items():
        getattr(self.signals, signal).connect(handler)

QTextEditLogHandler

QTextEditLogHandler(text_widget: QTextEdit)

Bases: Handler

GUI log handler.

Log handler for GUI application.

Parameters:

Name Type Description Default

text_widget

QTextEdit

widget to emit logs to.

required

Methods:

Name Description
emit

Emit a log record.

toggle_logging

Toggle a logging state on and off.

Source code in src/dcspy/qt_gui.py
2057
2058
2059
2060
2061
2062
2063
2064
2065
def __init__(self, text_widget: QTextEdit) -> None:
    """
    Log handler for GUI application.

    :param text_widget: widget to emit logs to.
    """
    super().__init__()
    self.text_widget = text_widget
    self.paused = False

emit

emit(record: LogRecord) -> None

Emit a log record.

Parameters:

Name Type Description Default

record

LogRecord

LogRecord instance.

required
Source code in src/dcspy/qt_gui.py
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
def emit(self, record: LogRecord) -> None:
    """
    Emit a log record.

    :param record: LogRecord instance.
    """
    if self.paused:
        return
    cursor = self.text_widget.textCursor()
    text_format = QTextCharFormat()
    text_format.setForeground(self.colors.get(record.levelname, QColorConstants.Svg.black))
    cursor.movePosition(cursor.MoveOperation.End)
    cursor.insertText(f'{self.format(record)}\n', text_format)
    self.text_widget.setTextCursor(cursor)

toggle_logging

toggle_logging(state: bool) -> None

Toggle a logging state on and off.

Parameters:

Name Type Description Default

state

bool

State of logging

required
Source code in src/dcspy/qt_gui.py
2082
2083
2084
2085
2086
2087
2088
def toggle_logging(self, state: bool) -> None:
    """
    Toggle a logging state on and off.

    :param state: State of logging
    """
    self.paused = not state

UiLoader

Bases: QUiLoader

UI file loader.

Methods:

Name Description
createWidget

Create a widget.

load_ui

Load a UI file.

createWidget

createWidget(
    className: str, parent: QWidget | None = None, name=""
) -> QWidget

Create a widget.

Parameters:

Name Type Description Default

className

str

Class name

required

parent

QWidget | None

Parent

None

name

Name

''

Returns:

Type Description
QWidget

QWidget

Source code in src/dcspy/qt_gui.py
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
def createWidget(self, className: str, parent: QWidget | None = None, name='') -> QWidget:
    """
    Create a widget.

    :param className: Class name
    :param parent: Parent
    :param name: Name
    :return: QWidget
    """
    if parent is None and self._base_instance is not None:
        widget = self._base_instance
    else:
        widget = super().createWidget(className, parent, name)
        if self._base_instance is not None:
            setattr(self._base_instance, name, widget)
    return widget

load_ui

load_ui(
    ui_path: str | bytes | Path, base_instance=None
) -> QWidget

Load a UI file.

Parameters:

Name Type Description Default

ui_path

str | bytes | Path

Path to a UI file

required

base_instance

None

Returns:

Type Description
QWidget

QWidget

Source code in src/dcspy/qt_gui.py
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
def load_ui(self, ui_path: str | bytes | Path, base_instance=None) -> QWidget:
    """
    Load a UI file.

    :param ui_path: Path to a UI file
    :param base_instance:
    :return: QWidget
    """
    self._base_instance = base_instance
    ui_file = QFile(ui_path)
    ui_file.open(QIODevice.OpenModeFlag.ReadOnly)
    try:
        widget = self.load(ui_file)
        QMetaObject.connectSlotsByName(widget)
        return widget
    finally:
        ui_file.close()

Worker

Worker(func: partial, with_progress: bool)

Bases: QRunnable, WorkerSignalsMixIn

Runnable worker.

Worker thread.

Inherits from QRunnable to handler worker thread setup, signals and wrap-up.

Parameters:

Name Type Description Default

func

partial

The function callback to run on a worker thread

required

Methods:

Name Description
run

Run the worker function.

setup_signal_handlers

Connect handlers to signals.

Source code in src/dcspy/qt_gui.py
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
def __init__(self, func: partial, with_progress: bool) -> None:
    """
    Worker thread.

    Inherits from QRunnable to handler worker thread setup, signals and wrap-up.
    :param func: The function callback to run on a worker thread
    """
    super().__init__()
    self.func = func
    if with_progress:
        self.func.keywords['progress_callback'] = self.signals.progress

run

run() -> None

Run the worker function.

Source code in src/dcspy/qt_gui.py
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
@Slot()
def run(self) -> None:
    """Run the worker function."""
    try:
        result = self.func()
    except Exception:
        exctype, value = sys.exc_info()[:2]
        self.signals.error.emit((exctype, value, traceback.format_exc()))
    else:
        self.signals.result.emit(result)
    finally:
        self.signals.finished.emit()

setup_signal_handlers

setup_signal_handlers(
    signal_handlers: dict[str, Callable[[Any], None]],
) -> None

Connect handlers to signals.

Parameters:

Name Type Description Default

signal_handlers

dict[str, Callable[[Any], None]]

Dict with signals and handlers as value.

required
Source code in src/dcspy/qt_gui.py
1925
1926
1927
1928
1929
1930
1931
1932
def setup_signal_handlers(self, signal_handlers: dict[str, Callable[[Any], None]]) -> None:
    """
    Connect handlers to signals.

    :param signal_handlers: Dict with signals and handlers as value.
    """
    for signal, handler in signal_handlers.items():
        getattr(self.signals, signal).connect(handler)

WorkerSignals

Bases: QObject

Defines the signals available from a running worker thread.

Supported signals are: * finished - no data * error - tuple with exctype, value, traceback.format_exc() * result - object/any type - data returned from processing * progress - float between zero (0) and one (1) as an indication of progress * stage - string with current stage

WorkerSignalsMixIn

WorkerSignalsMixIn()

Worker signals Mixin.

Signal handler for WorkerSignals.

Methods:

Name Description
setup_signal_handlers

Connect handlers to signals.

Source code in src/dcspy/qt_gui.py
1921
1922
1923
def __init__(self) -> None:
    """Signal handler for WorkerSignals."""
    self.signals = WorkerSignals()

setup_signal_handlers

setup_signal_handlers(
    signal_handlers: dict[str, Callable[[Any], None]],
) -> None

Connect handlers to signals.

Parameters:

Name Type Description Default

signal_handlers

dict[str, Callable[[Any], None]]

Dict with signals and handlers as value.

required
Source code in src/dcspy/qt_gui.py
1925
1926
1927
1928
1929
1930
1931
1932
def setup_signal_handlers(self, signal_handlers: dict[str, Callable[[Any], None]]) -> None:
    """
    Connect handlers to signals.

    :param signal_handlers: Dict with signals and handlers as value.
    """
    for signal, handler in signal_handlers.items():
        getattr(self.signals, signal).connect(handler)