-
Notifications
You must be signed in to change notification settings - Fork 141
/
Copy pathtestgui.py
90 lines (74 loc) · 3.12 KB
/
testgui.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
# -*- coding: utf-8 -*-
"""
This file contains the Qudi GUI module base class.
Qudi is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Qudi is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Qudi. If not, see <http://www.gnu.org/licenses/>.
Copyright (c) the Qudi Developers. See the COPYRIGHT.txt file at the
top-level directory of this distribution and at <https://github.com/Ulm-IQO/qudi/>
"""
# Test gui (test)
from core.configoption import ConfigOption
from gui.guibase import GUIBase
from qtpy import QtWidgets
class TestGui(GUIBase):
"""A class to test gui module loading.
This class does not implement a show() method to test the
error thrown by GUIBase when this function is not implemented.
"""
buttonText = ConfigOption('text', 'No Text configured')
infoOption = ConfigOption('info', 'Info Option', missing='info')
warningOption = ConfigOption('warning', 'Warning Option', missing='warn')
errorOption = ConfigOption('error', missing='error')
def __init__(self, config, **kwargs):
"""Create a TestWindow object.
@param dict config: configuration dictionary
@param dict kwargs: further optional arguments
"""
super().__init__(config=config, **kwargs)
def on_activate(self):
"""This creates all the necessary UI elements.
"""
self._mw = QtWidgets.QMainWindow()
self._mw.setGeometry(300,300,500,100)
self._mw.setWindowTitle('TEST')
self.cwdget = QtWidgets.QWidget()
self.button = QtWidgets.QPushButton(self.buttonText)
self.buttonerror = QtWidgets.QPushButton('Giff Error!')
self.checkbutton = QtWidgets.QPushButton('Status Error')
self.checkbutton.setCheckable(True)
self.button.clicked.connect(self.handleButton)
self.buttonerror.clicked.connect(self.handleButtonError)
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.button)
self.layout.addWidget(self.buttonerror)
self.layout.addWidget(self.checkbutton)
self.cwdget.setLayout(self.layout)
self._mw.setCentralWidget(self.cwdget)
self._mw.show()
def on_deactivate(self):
"""
"""
pass
def handleButton(self):
"""Change style of buttons.
"""
self.button.setStyleSheet(
'QPushButton {background-color:'
' #A3C1DA; color: red;}')
def handleButtonError(self):
""" Produce an exception for testing.
"""
raise Exception('Сука Блять')
def getState(self):
if hasattr(self, 'checkbutton') and self.checkbutton.isChecked():
raise Exception('Fail.')
else:
return super().module_state()