00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 from PyQt4.QtGui import *
00014 from PyQt4.QtCore import *
00015
00016 import utils
00017
00018
00019
00020
00021 class DSO_Scene(QGraphicsScene):
00022
00023 def __init__(self):
00024 QGraphicsScene.__init__(self, 0,0,540,440)
00025
00026
00027 bg = QBrush()
00028 bg.setColor(QColor(Qt.black))
00029 bg.setStyle(Qt.SolidPattern)
00030 self.setBackgroundBrush(bg)
00031
00032
00033 self.grid = DSO_grid(self)
00034
00035
00036 self.ch1_cursor = DSO_cursor(self, "1", Qt.cyan, "Y")
00037 self.ch2_cursor = DSO_cursor(self, "2", Qt.yellow, "Y")
00038 self.chX_cursor = DSO_cursor(self, "", Qt.red, "X")
00039
00040 self.CH1_info = DSO_channel(self, "Test<br>Test2<br>Test3")
00041
00042 self.wave1 = DSO_wave(self, Qt.cyan)
00043 self.wave1.hide()
00044
00045 self.wave2 = DSO_wave(self, Qt.yellow)
00046 self.wave2.hide()
00047
00048
00049 self.update()
00050
00051 self.pixmap = QGraphicsPixmapItem(None, self)
00052
00053 def updateScreen(self, ch1_data, ch2_data):
00054 self.grid.show()
00055 if ch1_data["active"]:
00056 self.wave1.repaint(ch1_data["samples"])
00057 self.ch1_cursor.setP(2*(106-ch1_data["y_offset"]))
00058 self.ch1_cursor.show()
00059 else:
00060 self.wave1.hide()
00061 self.ch1_cursor.hide()
00062
00063 if ch2_data["active"]:
00064 self.wave2.repaint(ch2_data["samples"])
00065 self.ch2_cursor.setP(2*(106-ch2_data["y_offset"]))
00066 self.ch2_cursor.show()
00067 else:
00068 self.wave2.hide()
00069 self.ch2_cursor.hide()
00070
00071 if ch2_data["y_offset"] in range(3,250):
00072 self.chX_cursor.setP(2*(ch2_data["x_offset"])+14)
00073 elif ch2_data["y_offset"] in range(0,3):
00074 self.chX_cursor.setP(20)
00075 elif ch2_data["y_offset"] > 250:
00076 self.chX_cursor.setP(270)
00077
00078 self.pixmap.hide()
00079 self.update()
00080
00081 def showPixmap(self, pixmap):
00082
00083 self.wave1.hide()
00084 self.ch1_cursor.hide()
00085 self.wave2.hide()
00086 self.ch2_cursor.hide()
00087 self.grid.hide()
00088
00089 print "Showing pixmap"
00090
00091 self.pixmap.setPixmap(pixmap)
00092 self.pixmap.setPos(-50,-20)
00093 self.pixmap.show()
00094 self.update()
00095
00096
00097
00098 class DSO_wave(QGraphicsItemGroup):
00099
00100 def __init__(self, parent, color):
00101 QGraphicsItemGroup.__init__(self, None, parent)
00102
00103 self.color = QColor(color)
00104 self.pen = QPen()
00105 self.pen.setColor(self.color)
00106
00107 self.lines = []
00108
00109 self.offset_x = 10
00110
00111 for i in range(self.offset_x,250+self.offset_x):
00112 line = QGraphicsLineItem(self)
00113 line.setLine(i*2,20+200,(i*2)+2,20+200)
00114 line.setPen(self.pen)
00115 self.lines.append(line)
00116
00117
00118
00119 def hide(self):
00120 for line in self.lines:
00121 line.hide()
00122
00123 def repaint(self, samples):
00124 index = 0
00125 x = 20
00126 y = 20
00127 for sample in samples:
00128 line = self.lines[index]
00129 index += 1
00130
00131 if x == 20:
00132 line.setLine(x,(2*(255 - sample) - 34),x,(2*(255 - sample) - 34))
00133 else:
00134 line.setLine(x-2,y,x,(2*(255 - sample) - 34))
00135
00136 x = x + 2
00137 y = (2*(255 - sample) - 34)
00138
00139 line.show()
00140
00141
00142 class DSO_channel(QGraphicsPolygonItem):
00143
00144 def __init__(self, parent, txt="", color=Qt.white):
00145 QGraphicsPolygonItem.__init__(self, None, parent)
00146
00147 polygon = QPolygonF()
00148
00149 polygon.append(QPointF(0,0))
00150 polygon.append(QPointF(0,16))
00151 polygon.append(QPointF(12,16))
00152 polygon.append(QPointF(20,8))
00153 polygon.append(QPointF(12,0))
00154
00155 bg = QBrush()
00156 col = QColor(color)
00157 col.setAlpha(200)
00158 bg.setColor(col)
00159 bg.setStyle(Qt.SolidPattern)
00160 self.setBrush(bg)
00161 text = QGraphicsTextItem(self, parent)
00162 text.setHtml(txt)
00163 self.show()
00164
00165
00166
00167 class DSO_cursor(QGraphicsPolygonItem):
00168
00169 def __init__(self, parent, name="", color=Qt.white, typ="X"):
00170 QGraphicsPolygonItem.__init__(self, None, parent)
00171
00172 polygon = QPolygonF()
00173
00174 if typ == "Y":
00175 polygon.append(QPointF(0,0))
00176 polygon.append(QPointF(0,16))
00177 polygon.append(QPointF(12,16))
00178 polygon.append(QPointF(20,8))
00179 polygon.append(QPointF(12,0))
00180
00181 if typ == "X":
00182 polygon.append(QPointF(0,0))
00183 polygon.append(QPointF(6,6))
00184 polygon.append(QPointF(12,0))
00185
00186
00187 self.setPolygon(polygon)
00188
00189
00190 bg = QBrush()
00191 col = QColor(color)
00192 col.setAlpha(200)
00193 bg.setColor(col)
00194 bg.setStyle(Qt.SolidPattern)
00195 self.setBrush(bg)
00196
00197 if typ == "Y":
00198 text = QGraphicsTextItem(self, parent)
00199 text.setPlainText(name)
00200
00201 self.typ = typ
00202 self.show()
00203
00204 def setP(self, pos):
00205 if self.typ == "Y":
00206 self.setPos(0,pos)
00207 if self.typ == "X":
00208 self.setPos(pos,10)
00209
00210
00211
00212 class DSO_grid(QGraphicsItemGroup):
00213
00214 def __init__(self, parent):
00215 QGraphicsItemGroup.__init__(self, None, parent)
00216 self.showGrid()
00217
00218
00219 def showGrid(self):
00220 self.color = QColor()
00221 pen = QPen()
00222 self.color.setNamedColor("white")
00223 pen.setColor(self.color)
00224
00225
00226 for x in range(20,521,10):
00227 for y in range(20,421,50):
00228
00229 self.point = QGraphicsLineItem(self)
00230
00231 if y == 20:
00232 self.point.setLine(x,y,x,y+3)
00233 elif y == 220:
00234 self.point.setLine(x,y-2,x,y+2)
00235 elif y == 420:
00236 self.point.setLine(x,y,x,y-3)
00237 else:
00238 self.point.setLine(x,y,x,y)
00239
00240 self.point.setPen(pen)
00241 self.point.show()
00242
00243 for x in range(20,521,50):
00244 for y in range(20,421,10):
00245
00246 self.point = QGraphicsLineItem(self)
00247
00248 if x == 20:
00249 self.point.setLine(x,y,x+3,y)
00250 elif x == 270:
00251 self.point.setLine(x-2,y,x+2,y)
00252 elif x == 520:
00253 self.point.setLine(x,y,x-3,y)
00254 else:
00255 self.point.setLine(x,y,x,y)
00256
00257 self.point.setPen(pen)
00258 self.point.show()
00259