• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

int-brain-lab / iblrig / 9031936551

10 May 2024 12:05PM UTC coverage: 48.538% (+1.7%) from 46.79%
9031936551

Pull #643

github

53c3e3
web-flow
Merge 3c8214f78 into ec2d8e4fe
Pull Request #643: 8.19.0

377 of 1073 new or added lines in 38 files covered. (35.14%)

977 existing lines in 19 files now uncovered.

3253 of 6702 relevant lines covered (48.54%)

0.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

36.17
/iblrig/gui/tools.py
1
import argparse
2✔
2
import subprocess
2✔
3
import sys
2✔
4
import traceback
2✔
5
from collections.abc import Callable
2✔
6
from typing import Any
2✔
7

8
from PyQt5.QtCore import QObject, QRunnable, pyqtSignal
2✔
9

10
from iblrig.constants import BASE_PATH
2✔
11

12

13
def convert_uis():
2✔
14
    """
15
    A wrapper for PyQt5's pyuic5 and pyrcc5, set up for development on iblrig
16
    """
17
    parser = argparse.ArgumentParser()
×
18
    parser.add_argument('pattern', nargs='?', default='*.*', type=str)
×
19
    args = parser.parse_args()
×
20

21
    gui_path = BASE_PATH.joinpath('iblrig', 'gui')
×
22
    files = set([f for f in gui_path.glob(args.pattern)])
×
23

24
    for filename_in in files.intersection(gui_path.glob('*.qrc')):
×
NEW
25
        rel_path_in = filename_in.relative_to(BASE_PATH)
×
NEW
26
        rel_path_out = rel_path_in.with_stem(rel_path_in.stem + '_rc').with_suffix('.py')
×
NEW
27
        args = ['pyrcc5', str(rel_path_in), '-o', str(rel_path_out)]
×
NEW
28
        print(' '.join(args))
×
29
        subprocess.check_output(args, cwd=BASE_PATH)
×
30

31
    for filename_in in files.intersection(gui_path.glob('*.ui')):
×
NEW
32
        rel_path_in = filename_in.relative_to(BASE_PATH)
×
NEW
33
        rel_path_out = rel_path_in.with_suffix('.py')
×
NEW
34
        args = ['pyuic5', str(rel_path_in), '-o', str(rel_path_out), '-x', '--import-from=iblrig.gui']
×
NEW
35
        print(' '.join(args))
×
36
        subprocess.check_output(args, cwd=BASE_PATH)
×
37

38

39
class WorkerSignals(QObject):
2✔
40
    """
41
    Signals used by the Worker class to communicate with the main thread.
42

43
    Attributes
44
    ----------
45
    finished : pyqtSignal
46
        Signal emitted when the worker has finished its task.
47

48
    error : pyqtSignal(tuple)
49
        Signal emitted when an error occurs. The signal carries a tuple with the exception type,
50
        exception value, and the formatted traceback.
51

52
    result : pyqtSignal(Any)
53
        Signal emitted when the worker has successfully completed its task. The signal carries
54
        the result of the task.
55

56
    progress : pyqtSignal(int)
57
        Signal emitted to report progress during the task. The signal carries an integer value.
58
    """
59

60
    finished = pyqtSignal()
2✔
61
    error = pyqtSignal(tuple)
2✔
62
    result = pyqtSignal(object)
2✔
63
    progress = pyqtSignal(int)
2✔
64

65

66
class Worker(QRunnable):
2✔
67
    """
68
    A generic worker class for executing functions concurrently in a separate thread.
69

70
    This class is designed to run functions concurrently in a separate thread and emit signals
71
    to communicate the results or errors back to the main thread.
72

73
    Adapted from: https://www.pythonguis.com/tutorials/multithreading-pyqt-applications-qthreadpool/
74

75
    Attributes
76
    ----------
77
    fn : Callable
78
        The function to be executed concurrently.
79

80
    args : tuple
81
        Positional arguments for the function.
82

83
    kwargs : dict
84
        Keyword arguments for the function.
85

86
    signals : WorkerSignals
87
        An instance of WorkerSignals used to emit signals.
88

89
    Methods
90
    -------
91
    run() -> None
92
        The main entry point for running the worker. Executes the provided function and
93
        emits signals accordingly.
94
    """
95

96
    def __init__(self, fn: Callable[..., Any], *args: Any, **kwargs: Any):
2✔
97
        """
98
        Initialize the Worker instance.
99

100
        Parameters
101
        ----------
102
        fn : Callable
103
            The function to be executed concurrently.
104

105
        *args : tuple
106
            Positional arguments for the function.
107

108
        **kwargs : dict
109
            Keyword arguments for the function.
110
        """
111
        super().__init__()
×
112
        self.fn = fn
×
113
        self.args = args
×
114
        self.kwargs = kwargs
×
115
        self.signals: WorkerSignals = WorkerSignals()
×
116

117
    def run(self) -> None:
2✔
118
        """
119
        Execute the provided function and emit signals accordingly.
120

121
        This method is the main entry point for running the worker. It executes the provided
122
        function and emits signals to communicate the results or errors back to the main thread.
123

124
        Returns
125
        -------
126
        None
127
        """
128
        try:
×
129
            result = self.fn(*self.args, **self.kwargs)
×
130
        except:  # noqa: E722
×
131
            # Handle exceptions and emit error signal with exception details
132
            traceback.print_exc()
×
133
            exctype, value = sys.exc_info()[:2]
×
134
            self.signals.error.emit((exctype, value, traceback.format_exc()))
×
135
        else:
136
            # Emit result signal with the result of the task
137
            self.signals.result.emit(result)
×
138
        finally:
139
            # Emit the finished signal to indicate completion
140
            self.signals.finished.emit()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc