def writeLabel(self, openetran): grid = self.Label.layout() status = 0 # Status = 1 when no widgets are left to delete while status == 0: status = Add_Delete_Widgets.deleteLabel(self, grid) # Number of Meters in the system num = len(openetran['label']) if num > 1: for k in range(num - 1): Add_Delete_Widgets.addLabel(self, grid) # Different version of the writeWidget function because there are ComboBoxes in the layout countTotal = grid.count() count = 0 # current count of the elements in the layout i = 0 # index of the current list (each key containing a list of lists) rowStart = 2 rowEnd = rowStart + 2 while count < countTotal: # List of positions of each text fields in the layout positions = [(i, j) for i in range(rowStart, rowEnd) for j in range(1, 4, 2)] k = 0 for position in positions: count = (position[0] + 1) * (position[1] + 1) if position[0] == (rowEnd - 1) and position[1] == 3: continue # Slightly different function if it's a combo box to set the text elif position[0] == rowStart and position[1] == 1: v = openetran['label'][i][k] widget = grid.itemAtPosition(position[0], position[1]).widget() if v == 'Phase': widget.setCurrentIndex(0) else: widget.setCurrentIndex(1) k += 1 else: v = openetran['label'][i][k] widget = grid.itemAtPosition(position[0], position[1]).widget() widget.setText(v) k += 1 rowStart = rowEnd + 1 rowEnd = rowStart + 2 i += 1 k = 0
def deleteLabel(): Add_Delete_Widgets.deleteLabel(self, self.Label.layout())