-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_win.py
181 lines (145 loc) · 5.7 KB
/
simple_win.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# simplewin.py
# dmf 5.12.20
# GUI routines for SimpleRigolGrab
#
# ---------
# Copyright (c) 2020 Douglas M Freymann
#
import sys
from PyQt5.QtWidgets import QHBoxLayout, QVBoxLayout, QApplication
from PyQt5.QtWidgets import QWidget, QLabel, QPushButton, QMessageBox
from PyQt5.QtWidgets import QInputDialog, QLineEdit
from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import QTimer, Qt
class display_grab_success(object):
# Wrapper to move PyQt code to one file
def __init__(self, passedvalue):
self.filename = passedvalue
def show(self):
a = imagewin(self.filename)
a.displayImage()
class display_grab_failure(object):
# Wrapper to move PyQt code to one file
def __init__(self, passedvalue):
self.errormsg = passedvalue
# error popup and time-out...
def show(self):
b = failpopup(self.errormsg).displayPopup()
# reminder for the beginner:
# everything is in methods and you call them from
# other methods in the class, or from outside.
class imagewin(QWidget):
# Display the captured Rigol image
def __init__(self, inputval):
# http://zetcode.com/gui/pyqt5/firstprograms/
# "The [win] class inherits from the QWidget class.
# This means that we call two constructors: the first
# one for the Example class and the second one for the
# inherited class. The super() method returns the parent
# object of the Example class and we call its constructor."
super(imagewin, self).__init__()
self.filename = str(inputval)
self.message = " " + self.filename + " has been captured succesfully"
# test method, not used
def displaymessage(self):
print(self.message)
def displayImage(self):
# This is the display of the captured image
image = QLabel()
image.setPixmap(QPixmap(self.filename))
# This is the OK button to close the window
bOK = QPushButton('OK')
bOK.setMaximumWidth(60)
bOK.setStyleSheet("font: 12pt")
# need lambda here! if do 'win.close()' only get an error
# because? win.close() is type bool. lamba invokes the
# win.close() as a function. at least that's what I can
# infer so far...
bOK.clicked.connect(lambda: self.close())
# This is just a text widget reporting status
msg = QLabel()
msg.setText(self.message)
# Found on the internets:
msg.setStyleSheet("font: 16pt")
# This organizes the info text and the OK button
# horizontally
msg_layout = QHBoxLayout()
msg_layout.addWidget(msg)
msg_layout.addStretch
msg_layout.addWidget(bOK)
# This sets the vertical layout of the image and
# info text/OK button widgets
imagebox = QVBoxLayout()
imagebox.addWidget(image)
imagebox.addLayout(msg_layout)
# This sets a time-out for the display
time = QTimer(self)
time.setInterval(6000)
# Need lambda here!
time.timeout.connect(lambda: self.close())
# Need to start it!
time.start()
# This incorporates the layout into the window
self.setLayout(imagebox)
self.setWindowTitle("Simple Rigol Grab")
# This shows and quits when done
self.show()
class failpopup(QWidget):
# Report failure to find Rigol
def __init__(self, inputval):
# http://zetcode.com/gui/pyqt5/firstprograms/
# "The [win] class inherits from the QWidget class.
# This means that we call two constructors: the first
# one for the Example class and the second one for the
# inherited class. The super() method returns the parent
# object of the Example class and we call its constructor."
super(failpopup, self).__init__()
self.message = inputval
# test method, not used
def displaymessage(self):
print(self.message)
def displayPopup(self):
# This is the OK button to close the window
bOK = QPushButton('OK')
bOK.setMaximumWidth(60)
bOK.setStyleSheet("font: 12pt")
# need lambda here! if do 'win.close()' only get an error
# because? win.close() is type bool. lamba invokes the
# win.close() as a function. at least that's what I can
# infer so far...
bOK.clicked.connect(lambda: self.close())
bOK_layout = QHBoxLayout()
bOK_layout.addWidget(bOK)
# This is just a text widget reporting status
msg = QLabel()
msg.setText(self.message)
# Found on the internets:
msg.setStyleSheet("font: 16pt")
msg.setAlignment(Qt.AlignCenter)
# This sets the vertical layout of the image and
# info text/OK button widgets
popupbox = QVBoxLayout()
popupbox.addWidget(msg)
popupbox.addLayout(bOK_layout)
# This sets a time-out for the display
time = QTimer(self)
time.setInterval(3000)
# Need lambda here!
time.timeout.connect(lambda: self.close())
# Need to start it!
time.start()
# This incorporates the layout into the window
self.setLayout(popupbox)
self.setWindowTitle("Simple Rigol Grab")
# This shows and quits when done
self.show()
class get_descriptor(QWidget):
def __init__(self):
super().__init__()
self.title = "Simple Rigol Grab"
def get(self):
text, okPressed = QInputDialog.getText(self, "Filename","Enter a short descriptor:", QLineEdit.Normal, "")
if okPressed and text != '':
return(text)
else:
return("Rigol")