aboutsummaryrefslogtreecommitdiff
path: root/acquisition/parent_hardware.py
blob: 8ced565f156762a08f9b5743f84f4ea8e1c4c0ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class Hardware(QtCore.QObject):
    update_ui = QtCore.pyqtSignal()
    initialized_signal = QtCore.pyqtSignal()

    def __init__(self, driver_class, driver_arguments, gui_class,
                 name, model, serial=None):
        """
        Hardware representation object living in the main thread.

        Parameters
        driver_class : Driver class
        driver_arguments : dictionary
        name : string
        model : string
        serial : string or None (optional)
        """
        QtCore.QObject.__init__(self)
        self.name = name
        self.model = model
        self.serial = serial
        # create objects
        self.thread = QtCore.QThread()
        self.enqueued = Enqueued()
        self.busy = Busy()
        self.driver = driver_class(self, **driver_arguments)
        self.initialized = self.driver.initialized
        self.gui = gui_class(self)
        self.q = Q(self.enqueued, self.busy, self.driver)
        # start thread
        self.driver.moveToThread(self.thread)
        self.thread.start()
        # connect to address object signals
        self.driver.update_ui.connect(self.update)
        self.busy.update_signal = self.driver.update_ui
        # initialize drivers
        self.q.push('initialize')
        # integrate close into PyCMDS shutdown
        self.shutdown_timeout = 30  # seconds
        g.shutdown.add_method(self.close)
        g.hardware_waits.add(self.wait_until_still)