Skip to content

Commit

Permalink
Added support for combo box
Browse files Browse the repository at this point in the history
If allowed values are defined they now could be displayed as a combo box.
Not allowed values in a combo box have a red font.
Combo box with a not allowed value selected become red.
Fixed a bug with hiding columns. Now the current Page displays after hiding. No crazy line-numbers anymore.
  • Loading branch information
hduelme committed Jul 6, 2020
1 parent e347ffb commit 3e093b2
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 23 deletions.
4 changes: 4 additions & 0 deletions Message.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def __init__(self,name,typ,default,allowedvalues,allowedcharacter,description,hi
self.allowedcharacter = allowedcharacter
self.description = description
self.hide = hide
if(self.allowedvalues[0] != "all" and self.allowedvalues[0]!=""):
self.comboBox = True
else:
self.comboBox = False

def toString(self):
return "Name: "+self.name+" Typ: "+self.typ+" defaultvalues: "+str(self.defaultvalues)+" allowedvalues: "+self.allowedvalues+" description: "+self.description
Expand Down
124 changes: 101 additions & 23 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def __init__(self):
self.currentPage = 0
self.currentFile =""
self.hideCols = False
self.allowComboBox = True


self.config = config.Config()
self.config.read_Config()
Expand Down Expand Up @@ -86,12 +88,15 @@ def setupUi(self):
hideColums.triggered.connect(self.hideUnusedColums)
edit.addAction(hideColums)

allowCombo = QAction("Disable ComboBoxes", self)
allowCombo.triggered.connect(self.allow_comboBox)
edit.addAction(allowCombo)

help = menubar.addMenu("Help")


# Init tableWiget
self.tableWidget = QTableWidget()
self.tableWidget.setObjectName("tableWidget")
self.setCentralWidget(self.tableWidget)

# Init pages-windows (DockWidget)
Expand Down Expand Up @@ -132,6 +137,17 @@ def setupUi(self):
# show Window
self.show()

def allow_comboBox(self):
if (self.fileLoaded()):
sender = self.sender()
self.saveCurrentPage()
self.allowComboBox = not self.allowComboBox
if (self.hideCols):
sender.setText("Disable ComboBoxes")
else:
sender.setText("Allow ComboBoxes")
self.setCurrentPage((self.currentPage ) * self.lines_Site, (self.currentPage+1) * self.lines_Site)

def hideUnusedColums(self):
if(self.fileLoaded()):
sender = self.sender()
Expand All @@ -142,7 +158,7 @@ def hideUnusedColums(self):
sender.setText("Unhide unused colums")
else:
sender.setText("Hide unused colums")
self.setCurrentPage((self.pages - 1) * self.lines_Site, (self.pages) * self.lines_Site)
self.setCurrentPage((self.currentPage) * self.lines_Site, (self.currentPage+1) * self.lines_Site)

def addNewLine(self):
if (self.fileLoaded()):
Expand Down Expand Up @@ -217,8 +233,10 @@ def calcPages(self):

def setCurrentPage(self,fr,to):
#t1 = 0
for r in range(0,self.tableWidget.rowCount()):
self.tableWidget.removeRow(r)
#for r in range(0,self.tableWidget.rowCount()):
#self.tableWidget.removeRow(r)
self.tableWidget = QTableWidget()
self.setCentralWidget(self.tableWidget)
if (self.hideCols):
self.tableWidget.setColumnCount(len(self.headersHidden))

Expand All @@ -233,18 +251,47 @@ def setCurrentPage(self,fr,to):
vertikalHeader = []
t1 = 0

for x in range(fr,to):
if(x<len(self.users)):
user = self.users[x]
for allowed_value in range(fr,to):
if(allowed_value<len(self.users)):
user = self.users[allowed_value]
t2 = 0
skipped = 0
for i in user:
if (self.config.read_Sections[t2].hide == "False" or not self.hideCols):
self.tableWidget.setItem(t1, t2-skipped, QTableWidgetItem(i))
section = self.config.read_Sections[t2]
if (section.hide == "False" or not self.hideCols):
if(self.allowComboBox and section.comboBox):
index = -1
x = 0
data = []
for allowed in section.allowedvalues:
data.append(allowed)
if(allowed==i):
index = x
x+=1

comboBox = QComboBox()
comboBox.addItems(data)
comboBox.setEditable(False)
if(index==-1):
index = len(data)
model = comboBox.model()
item = QStandardItem()
item.setText(i)

item.setBackground(QColor(255, 0, 0))
model.appendRow(item)
comboBox.setCurrentIndex(index)


self.tableWidget.setCellWidget(t1, t2-skipped, comboBox)


else:
self.tableWidget.setItem(t1, t2-skipped, QTableWidgetItem(i))
else:
skipped +=1
t2 += 1
vertikalHeader.append(str(x))
vertikalHeader.append(str(allowed_value))
t1 +=1
if(self.hideCols):
self.tableWidget.setHorizontalHeaderLabels(self.headersHidden)
Expand All @@ -261,6 +308,7 @@ def checkCurrentPage(self):
count = len(self.headers)
for row in range(rows):
no_error = []
combo_no_error = []
x = 0
skipped = 0
temp_Sections = self.config.read_Sections
Expand All @@ -270,21 +318,46 @@ def checkCurrentPage(self):
skipped+=1
else:
col_temp = col-skipped
item = self.tableWidget.item(row, col_temp)
testing = temp_Sections[col].isvalueAllowed(item.text())
descriptipn = temp_Sections[col].description
if(testing!="Ok"):
#print("Soll nicht so "+temp_Sections[col].name)
self.tableWidget.item(row, col_temp).setBackground(QColor(255, 0, 0))
self.tableWidget.item(row, col_temp).setToolTip("Description: "+descriptipn+"\n"+testing)

if(self.allowComboBox and self.config.read_Sections[col].comboBox):
comboBox = self.tableWidget.cellWidget(row, col_temp)
if(comboBox.currentIndex()+1<=len(self.config.read_Sections[col].allowedvalues)):
combo_no_error.append(col_temp)
comboBox.setStyleSheet("QComboBox"
"{"
"background-color : white;"
"}")

else:
comboBox.setStyleSheet("QComboBox"
"{"
"background-color : red;"
"}")

else:
self.tableWidget.item(row, col_temp).setBackground(QColor(255, 255, 255))
self.tableWidget.item(row, col_temp).setToolTip("Description: "+descriptipn)
no_error.append(col_temp)
item = self.tableWidget.item(row, col_temp)
testing = temp_Sections[col].isvalueAllowed(item.text())
descriptipn = temp_Sections[col].description
if(testing!="Ok"):
#print("Soll nicht so "+temp_Sections[col].name)
self.tableWidget.item(row, col_temp).setBackground(QColor(255, 0, 0))
self.tableWidget.item(row, col_temp).setToolTip("Description: "+descriptipn+"\n"+testing)

else:
self.tableWidget.item(row, col_temp).setBackground(QColor(255, 255, 255))
self.tableWidget.item(row, col_temp).setToolTip("Description: "+descriptipn)
no_error.append(col_temp)
x+=1
if(len(no_error)<count):
if((len(no_error)+len(combo_no_error))<count):
for col_gray in no_error:
self.tableWidget.item(row, col_gray).setBackground(QColor(140, 140, 140))
if(self.allowComboBox):
for col_gray in combo_no_error:
comboBox = self.tableWidget.cellWidget(row, col_gray)
comboBox.setStyleSheet("QComboBox"
"{"
"background-color : gray;"
"}")

def delline(self):
if (self.fileLoaded()):
Expand Down Expand Up @@ -335,8 +408,13 @@ def saveCurrentPage(self):
user.append(self.users[(self.currentPage * self.lines_Site) + row][col])
skipped += 1
else:
item=self.tableWidget.item(row,col-skipped)
user.append(item.text())
col_temp = col-skipped
if(self.allowComboBox and self.config.read_Sections[col].comboBox):
comboBox = self.tableWidget.cellWidget(row, col_temp)
user.append(comboBox.currentText())
else:
item=self.tableWidget.item(row,col_temp)
user.append(item.text())
if(len(user)>len(self.headers)):
print("Länge FALSCH")
self.users[(self.currentPage * self.lines_Site) + row]=user
Expand Down

0 comments on commit 3e093b2

Please sign in to comment.