-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableEditor.py
More file actions
132 lines (112 loc) · 6.13 KB
/
TableEditor.py
File metadata and controls
132 lines (112 loc) · 6.13 KB
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
from PyQt4 import QtCore, QtGui
class TableEditor(QtGui.QWidget):
def __init__(self,row,col,sizeX,sizeY,which,*args,**kwargs):
super(TableEditor, self).__init__(*args,**kwargs)
self.row = row
self.col = col
self.sizeX = sizeX
self.sizeY = sizeY
self.which = which #which=1:DAC which=2:Delay which=3:Patterns
self.initUI()
def initUI(self):
self.intValidatorDAC = QtGui.QIntValidator()
self.intValidatorDAC.setRange(0,65535)
self.intValidatorDelay = QtGui.QIntValidator()
self.intValidatorDelay.setRange(0,240)
self.hexValidator = QtGui.QRegExpValidator(QtCore.QRegExp("0x[0-9A-Fa-f]{8}"))
self.tableWidget = QtGui.QTableWidget(self.row,self.col,self)
self.tableWidget.resize(self.sizeX,self.sizeY)
self.tableWidget.move(0,20)
self.tableWidget.horizontalHeader().setResizeMode(1) #All Cells Stretch to the size of the table.
self.tableWidget.setDragEnabled(1)
self.tableWidget.setAcceptDrops(1)
self.plusBtn = QtGui.QPushButton('+',self)
self.plusBtn.setToolTip('Adding a row')
self.plusBtn.resize(self.plusBtn.sizeHint())
#self.plusBtn.setStyleSheet("background: orange")
self.minusBtn = QtGui.QPushButton('-',self)
self.minusBtn.setToolTip('Removing a row')
self.minusBtn.resize(self.plusBtn.sizeHint())
#self.minusBtn.setStyleSheet("border-radius: 5px")
self.layoutWidget = QtGui.QWidget(self)
self.layoutWidget.resize(50,100)
self.layoutWidget.move(self.sizeX+10, 30)
self.verticalLayout = QtGui.QVBoxLayout(self.layoutWidget)
self.verticalLayout.setMargin(0)
self.verticalLayout.addWidget(self.plusBtn)
self.verticalLayout.addWidget(self.minusBtn)
self.plusBtn.clicked.connect(self.addRow)
self.minusBtn.clicked.connect(self.delRow)
####Crude Way to Distinguish if DAC/Delay or Pat#####
if self.which == 1:
self.tableWidget.cellChanged.connect(self.checkIntDAC)
elif self.which == 2:
self.tableWidget.cellChanged.connect(self.checkIntDelay)
elif self.which == 3:
self.tableWidget.cellChanged.connect(self.checkHex)
#####################################################
def addRow(self):
rowPosition = self.tableWidget.rowCount()
self.tableWidget.insertRow(rowPosition)
def delRow(self):
rowPosition = self.tableWidget.rowCount()
self.tableWidget.removeRow(rowPosition-1)
def checkTableIntDAC(self):
for i in range (0,self.tableWidget.rowCount()):
state = self.intValidatorDAC.validate(self.tableWidget.item(i,0).text(),0)[0]
if state == QtGui.QValidator.Acceptable:
self.tableWidget.item(i,0).setBackgroundColor(QtGui.QColor(152,251,152))
else:
self.tableWidget.item(i,0).setBackgroundColor(QtGui.QColor(255, 128, 128))
self.tableWidget.item(i,0).setToolTip('Integer only please.')
i += 1
def checkTableIntDelay(self):
for i in range (0,self.tableWidget.rowCount()):
state = self.intValidatorDAC.validate(self.tableWidget.item(i,0).text(),0)[0]
if state == QtGui.QValidator.Acceptable:
self.tableWidget.item(i,0).setBackgroundColor(QtGui.QColor(152,251,152))
else:
self.tableWidget.item(i,0).setBackgroundColor(QtGui.QColor(255, 128, 128))
self.tableWidget.item(i,0).setToolTip('Integer only please.')
i += 1
def checkTableHex(self):
for x in range (0,self.tableWidget.rowCount()):
for y in range (0,self.tableWidget.columnCount()):
state = self.hexValidator.validate(self.tableWidget.item(x,y).text(),0)[0]
if state == QtGui.QValidator.Acceptable:
self.tableWidget.item(x,y).setBackgroundColor(QtGui.QColor(152,251,152))
else:
self.tableWidget.item(x,y).setBackgroundColor(QtGui.QColor(255, 128, 128))
self.tableWidget.item(x,y).setToolTip('Hex# only please. (ie. 0x1234567f)')
y += 1
x += 1
def checkIntDAC(self):
currentRow = self.tableWidget.currentRow()
currentCol = self.tableWidget.currentColumn()
currentItem = QtGui.QTableWidgetItem(self.tableWidget.item(currentRow,currentCol))
state = self.intValidatorDAC.validate(currentItem.text(),0)[0]
if state == QtGui.QValidator.Acceptable:
self.tableWidget.item(currentRow,currentCol).setBackgroundColor(QtGui.QColor(152,251,152))
else:
self.tableWidget.item(currentRow,currentCol).setBackgroundColor(QtGui.QColor(255, 128, 128))
self.tableWidget.item(currentRow,currentCol).setToolTip('Integer only please.')
def checkIntDelay(self):
currentRow = self.tableWidget.currentRow()
currentCol = self.tableWidget.currentColumn()
currentItem = QtGui.QTableWidgetItem(self.tableWidget.item(currentRow,currentCol))
state = self.intValidatorDelay.validate(currentItem.text(),0)[0]
if state == QtGui.QValidator.Acceptable:
self.tableWidget.item(currentRow,currentCol).setBackgroundColor(QtGui.QColor(152,251,152))
else:
self.tableWidget.item(currentRow,currentCol).setBackgroundColor(QtGui.QColor(255, 128, 128))
self.tableWidget.item(currentRow,currentCol).setToolTip('Integer only please.')
def checkHex(self):
currentRow = self.tableWidget.currentRow()
currentCol = self.tableWidget.currentColumn()
currentItem = QtGui.QTableWidgetItem(self.tableWidget.item(currentRow,currentCol))
state = self.hexValidator.validate(currentItem.text(),0)[0]
if state == QtGui.QValidator.Acceptable:
self.tableWidget.item(currentRow,currentCol).setBackgroundColor(QtGui.QColor(152,251,152))
else:
self.tableWidget.item(currentRow,currentCol).setBackgroundColor(QtGui.QColor(255, 128, 128))
self.tableWidget.item(currentRow,currentCol).setToolTip('Hex# only please. (ie. 0x1234567f)')