-
Notifications
You must be signed in to change notification settings - Fork 0
/
PyQtKaWig.py
196 lines (150 loc) · 5.44 KB
/
PyQtKaWig.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
'''
Created on 24 Jan 2016
@author: kamichal
'''
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
from matplotlib.figure import Figure
import random
from PyQt4 import QtGui, QtCore
class SuwakPoziomy(QtGui.QWidget):
SygnSuwakPoszedl = QtCore.pyqtSignal()
def __init__(self, parent=None, nazwa='', jednostka=''):
super(SuwakPoziomy, self).__init__(parent)
self.nazwa = QtGui.QLabel(self)
self.nazwa.setText(nazwa + ' = ')
self.wartosc = QtGui.QSpinBox(self)
self.postfiks = QtGui.QLabel(self)
self.postfiks.setText(jednostka)
self.suwak = QtGui.QSlider(QtCore.Qt.Horizontal, self)
self.suwak.valueChanged.connect(self.wartosc.setValue)
self.suwak.valueChanged.connect(self.SygnSuwakPoszedl)
self.wartosc.valueChanged.connect(self.suwak.setValue)
self.wartosc.valueChanged.connect(self.SygnSuwakPoszedl)
self.ukladWidzetu = QtGui.QHBoxLayout(self)
self.ukladWidzetu.addWidget(self.nazwa)
self.ukladWidzetu.addWidget(self.wartosc)
self.ukladWidzetu.addWidget(self.postfiks)
self.ukladWidzetu.addWidget(self.suwak)
def UstawMin(self, maxWart):
self.suwak.setMinimum(maxWart)
self.wartosc.setMinimum(maxWart)
def UstawMax(self, maxWart):
self.suwak.setMaximum(maxWart)
self.wartosc.setMaximum(maxWart)
class WidzetWykres(QtGui.QWidget):
def __init__(self, parent=None):
super(WidzetWykres, self).__init__(parent)
self.figure = Figure()
self.canvas = FigureCanvasQTAgg(self.figure)
self.axis = self.figure.add_subplot(111)
self.ukladPionowy = QtGui.QVBoxLayout(self)
self.ukladPionowy.addWidget(self.canvas)
def kolorLini(self, n=0):
kolory = (
'b' # blue
'g' # green
'r' # red
'c' # cyan
'm' # magenta
'y' # yellow
'k' # black
'w' # white
)
return kolory[n % len(kolory)]
def stylMarkera(self, n=0):
znaczniki = (
'x', # x
'o', # circle
'v', # triangle_down
'^', # triangle_up
'<', # triangle_left
'>', # triangle_right
'1', # tri_down
'2', # tri_up
'3', # tri_left
'4', # tri_right
'8', # octagon
's', # square
'p', # pentagon
'*', # star
'h', # hexagon1
'.', # point
'H', # hexagon2
'+', # plus
',', # pixel
'D', # diamond
'd', # thin_diamond
'|', # vline
'_' # hline
)
return znaczniki[n%len(znaczniki)]
class TestOknoGlowne(QtGui.QWidget):
def __init__(self, parent=None):
super(TestOknoGlowne, self).__init__(parent)
# self.suwak = SuwakPoziomy(self)
self.tA = SuwakPoziomy(self,'Asd',"opis moze\nbyc lamany")
self.tA.UstawMax(1000)
self.tB = SuwakPoziomy(self,'N','[Watt]')
self.tB.wartosc.setMaximum(200)
self.tB.postfiks.setText('[laczy]')
self.tC = SuwakPoziomy(self,'E','[V]')
self.uklad = QtGui.QVBoxLayout(self)
self.uklad.addWidget(self.tA)
self.uklad.addWidget(self.tB)
self.uklad.addWidget(self.tC)
class TestWykresow(QtGui.QWidget):
def __init__(self, parent=None):
super(TestWykresow, self).__init__(parent)
# self.suwak = SuwakPoziomy(self)
self.W = WidzetWykres(self)
# self.RysujCosTam()
self.RysujSlownikiem()
self.zatwierdz = QtGui.QPushButton(self)
self.zatwierdz.setText("Jeszcze raz")
self.zatwierdz.clicked.connect(self.RysujCosTam)
self.uklad = QtGui.QVBoxLayout(self)
self.uklad.addWidget(self.W)
self.uklad.addWidget(self.zatwierdz)
@QtCore.pyqtSlot()
def RysujCosTam(self):
self.W.axis.clear()
N = 16
XX = range(N)
YY = []
for _ in range(4):
tmp = random.sample(range(N), N)
YY.append(tmp)
for i, seria in enumerate(YY):
self.W.axis.plot(XX, seria,
c=self.W.kolory[i],
marker=self.W.styleMarkerow[i])
self.W.canvas.draw()
@QtCore.pyqtSlot()
def RysujSlownikiem(self):
self.W.axis.clear()
N = 16
XX = range(N)
dane = []
for _ in range(4):
tmp = random.randint(0,5)
YY = random.sample(range(N), N)
dane.append({'xx':XX,
'yy':YY,
'ma':self.W.styleMarkerow[tmp],
'ko':self.W.kolory[tmp]
})
for seria in dane:
self.W.axis.plot(seria['xx'],
seria['yy'],
c=seria['ko'],
marker=seria['ma'])
self.W.canvas.draw()
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
app.setApplicationName('OknoGlowne')
# main = TestOknoGlowne()
main = TestWykresow()
main.resize(666, 333)
main.show()
sys.exit(app.exec_())