Completed
Pull Request — master (#380)
by
unknown
03:38
created

CameraGUI.on_activate()   B

Complexity

Conditions 1

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
dl 0
loc 25
rs 8.8571
c 2
b 0
f 1
1
# -*- coding: utf-8 -*-
2
"""
3
This module contains a GUI for operating the spectrometer camera logic module.
4
5
Qudi is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9
10
Qudi is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with Qudi. If not, see <http://www.gnu.org/licenses/>.
17
18
Copyright (c) the Qudi Developers. See the COPYRIGHT.txt file at the
19
top-level directory of this distribution and at <https://github.com/Ulm-IQO/qudi/>
20
"""
21
22
import os
23
import pyqtgraph as pg
24
25
from core.module import Connector
26
from gui.colordefs import QudiPalettePale as Palette
27
from gui.guibase import GUIBase
28
29
from qtpy import QtCore
30
from qtpy import QtGui
31
from qtpy import QtWidgets
32
from qtpy import uic
33
34
35
class CameraWindow(QtWidgets.QMainWindow):
36
    """ Class defined for the main window (not the module)
37
38
    """
39
40
    def __init__(self):
41
        # Get the path to the *.ui file
42
        this_dir = os.path.dirname(__file__)
43
        ui_file = os.path.join(this_dir, 'ui_camera.ui')
44
45
        # Load it
46
        super().__init__()
47
        uic.loadUi(ui_file, self)
48
        self.show()
49
50
51
class CameraGUI(GUIBase):
52
    """ Main spectrometer camera class.
53
    """
54
    _modclass = 'CameraGui'
55
    _modtype = 'gui'
56
57
    camera_logic = Connector(interface='CameraLogic')
58
59
    sigStart = QtCore.Signal()
60
    sigStop = QtCore.Signal()
61
    _image = []
62
63
    _logic = None
64
    _mw = None
65
66
    def __init__(self, config, **kwargs):
67
68
        # load connection
69
        super().__init__(config=config, **kwargs)
70
71
    def on_activate(self):
72
        """ Initializes all needed UI files and establishes the connectors.
73
        """
74
75
        self._logic = self.camera_logic()
76
77
        # Windows
78
        self._mw = CameraWindow()
79
        self._mw.centralwidget.hide()
80
        self._mw.setDockNestingEnabled(True)
81
82
        self._mw.start_control_Action.setEnabled(True)
83
        self._mw.start_control_Action.setChecked(self._logic.enabled)
84
        self._mw.start_control_Action.triggered.connect(self.start_clicked)
85
86
        self._logic.sigUpdateDisplay.connect(self.update_data)
87
88
        # starting the physical measurement
89
        self.sigStart.connect(self._logic.startLoop)
90
        self.sigStop.connect(self._logic.stopLoop)
91
92
        raw_data_image = self._logic.get_last_image()
93
        self._image = pg.ImageItem(image=raw_data_image, axisOrder='row-major')
94
        self._mw.image_PlotWidget.addItem(self._image)
95
        self._mw.image_PlotWidget.setAspectLocked(True)
96
97
    def on_deactivate(self):
98
        """ Deinitialisation performed during deactivation of the module.
99
        """
100
        self._mw.close()
101
102
    def show(self):
103
        """Make window visible and put it above all other windows.
104
        """
105
        QtWidgets.QMainWindow.show(self._mw)
106
        self._mw.activateWindow()
107
        self._mw.raise_()
108
109
    def start_clicked(self):
110
        """ Handling the Start button to stop and restart the counter.
111
        """
112
        if self._logic.enabled:
113
            self._mw.start_control_Action.setText('Start')
114
            self.sigStop.emit()
115
        else:
116
            self._mw.start_control_Action.setText('Stop')
117
            self.sigStart.emit()
118
119
    def update_data(self):
120
        """
121
        Get the image data from the logic and print it on the window
122
        """
123
        raw_data_image = self._logic.get_last_image()
124
        levels = (0., 1.)
125
        self._image.setImage(image=raw_data_image)
126
        # self._image.setImage(image=raw_data_image, levels=levels)
127
128
    def updateView(self):
129
        """
130
        Update the view when the model change
131
        """
132
        pass
133
134