def createLabelWidget(self, parent, name, field, x, y, noedit=False): q = QLabel(name) q.setParent(parent) q.setGeometry(x, y, FIELD_WIDTH - 10, 26) q.setFont(QFont("Arial", 12, QFont.Bold)) q.show() if field == None: return q critical = critical_mask if self.metadata["fbx"].lower().endswith(".json"): critical = critical_combo value = self.metadata[field] if field in DROP_DOWNS: dropvals = DROP_DOWNS[field] q = QComboBox() idx = 0 selidx = -1 for s in dropvals: if s == str(value): selidx = idx q.addItem(s) idx += 1 if selidx < 0: selidx = 0 q.setCurrentIndex(selidx) q.currentIndexChanged.connect(lambda state: self.onDropdownChanged(state, field)) elif type(value) is str or type(value) is float or type(value) is int: if noedit: q = QLabel(str(value)) else: q = QLineEdit(str(value)) q.textChanged.connect(lambda text: self.onTextFieldChanged(text, field)) if critical(field) and len(value) == 0: q.setStyleSheet("border: 1px solid #FF0000;") elif desired(field) and len(value) == 0: q.setStyleSheet("border: 1px solid #FF7F50;") else: q.setStyleSheet("border: 0px;") elif type(value) is bool: q = QCheckBox() q.setChecked(value) q.stateChanged.connect(lambda state: self.onCheckboxChanged(state, field)) q.setParent(parent) if type(value) is int: q.setGeometry(x + FIELD_WIDTH - 10, y, FIELD_WIDTH, 20) else: q.setGeometry(x + FIELD_WIDTH - 10, y, PANE_WIDTH - FIELD_WIDTH - 10, 20) q.setFont(QFont("Arial", 12, QFont.Bold)) q.show() return q
class item(): def __init__(self, parent, name, value, _type, values=None): self.parent = parent self.name = name self.type = _type self._value = value self.values = values def doit(self): getattr(self, 'create_' + str(self.type).split("'")[1])() def create_list(self): self.Object = QComboBox(self.parent) for value in self.values: self.Object.addItem(str(value)) self.Label = QLabel(self.name.replace('_', ' ')) # return Object, Label def create_float(self): self.Object = extended_QLineEdit('{0:.2e}'.format(self._value)) self.Label = QLabel(self.name.replace('_', ' ')) # return Object, Label def create_bool(self): self.Object = QCheckBox(self.parent) if self._value: self.Object.toggle() self.Label = QLabel(self.name.replace('_', ' ')) # return Object, Label def create_int(self): self.Object = QLineEdit('{0:.0f}'.format(self._value)) self.Label = QLabel(self.name.replace('_', ' ')) # return Object, Label def create_btn(self): self.Object = QPushButton(self._value) def create_str(self): self.Object = QLabel('{0:.0f}'.format(self._value)) self.Label = QLabel(self.name.replace('_', ' ')) def connect(self, function): self.Object.editingFinished.connect(function) @property def value(self): return getattr(self, 'get_' + str(self.type).split("'")[1])() @value.setter def value(self, value): return getattr(self, 'set_' + str(self.type).split("'")[1])(value) def get_float(self): return float(self.Object.text()) def get_int(self): return int(float(self.Object.text())) def get_bool(self): return self.Object.isChecked() def get_list(self): return str(self.Object.currentText()) def get_str(self): return str(self.Object.text()) def set_float(self, value): self.Object.setText('{0:.2e}'.format(value)) def set_int(self, value): self.Object.setText(str(value)) pass def set_bool(self, value): pass def set_list(self, value): if value in self.values: index = self.values.index(value) self.Object.setCurrentIndex(index) pass def set_str(self, value): self.Object.setText(str(value)) pass
def createLabelWidget(self, parent, field, x, y, noedit=False): q = QLabel(field) q.setParent(parent) q.setGeometry(x, y, FW - 10, 36) q.setFont(QFont("Arial", 12, QFont.Bold)) q.show() add_type = self.addition["type"] value = self.addition[field] if (add_type, field) in DROP_DOWNS: dropvals = DROP_DOWNS[(add_type, field)] q = QComboBox() idx = 0 selidx = -1 for s in dropvals: if s == str(value): selidx = idx q.addItem(s) idx += 1 if selidx < 0: selidx = 0 q.setCurrentIndex(selidx) q.currentIndexChanged.connect(lambda state: self.onDropdownChanged(state, field)) elif type(value) is str or type(value) is int or type(value) is float: if noedit: q = QLabel(str(value)) else: q = QLineEdit(str(value)) q.textChanged.connect(lambda text: self.onTextFieldChanged(text, field)) elif type(value) is bool: q = QCheckBox() q.setChecked(value) q.stateChanged.connect(lambda state: self.onCheckboxChanged(state, field)) elif type(value) is list: xx = x + FW idx = 0 for val in value: q = QLineEdit(str(val)) q.setParent(parent) q.setGeometry(xx, y, 75, 30) q.setFont(QFont("Arial", 12, QFont.Bold)) q.show() xx += 80 q.textChanged.connect(lambda text, idx=idx: self.onTextFieldChanged(text, field, idx)) idx += 1 if type(value) is not list: q.setParent(parent) if field == "file": q.setGeometry(x + FW, y, PW - FW - 60, 30) b = QPushButton("BROWSE") b.setParent(parent) b.setGeometry(x + PW - 60, y, 50, 30) b.pressed.connect(lambda: self.onFileBrowser(field)) else: q.setGeometry(x + FW, y, PW - FW - 10, 30) q.show() q.setFont(QFont("Arial", 12, QFont.Bold)) return q
def createLayout(self): self.layout = QGridLayout(self) toplabel1 = QLabel("1-, 2- or 3-Shift CSV File Constructor Algorithm") toplabel2 = QLabel( "Phase 2: Generate and/or find solution(s) to a combination") toplabel2x = QLabel("- - - - Define the parameters below - - - -") toplabel3 = QLabel("") dailyrestingtimelbl = QLabel( "Minimum continuous daily resting time [h]: ") toplabel1.setAlignment(Qt.AlignCenter) toplabel2.setAlignment(Qt.AlignCenter) toplabel2x.setAlignment(Qt.AlignCenter) toplabel3.setAlignment(Qt.AlignCenter) row = 0 self.layout.addWidget(toplabel1, row, 0, 1, 7) row += 1 self.layout.addWidget(toplabel2, row, 0, 1, 7) row += 1 self.layout.addWidget(toplabel2x, row, 0, 1, 7) row += 1 self.layout.addWidget(toplabel3, row, 0, 1, 7) row += 1 shiftlengthlbl = QLabel("Shift lengths [h]: ") self.layout.addWidget(shiftlengthlbl, row, 0, 1, 4) self.shiftlengthinput = QDoubleSpinBox() self.shiftlengthinput.setValue(self.shiftlengths) self.shiftlengthinput.setMinimum(1) self.shiftlengthinput.valueChanged.connect( self.shiftlengthinputChanged) self.layout.addWidget(self.shiftlengthinput, row, 4, 1, 3) row += 1 dailyrestingtimelbl = QLabel( "Minimum continuous daily resting time [h]: ") self.layout.addWidget(dailyrestingtimelbl, row, 0, 1, 4) self.checkWeeklyRestBtn = QPushButton("Check Weekly Rest") self.dailyrestinginput = QSpinBox() self.dailyrestinginput.setValue(self.dailyresting) self.dailyrestinginput.setMinimum(1) self.dailyrestinginput.setToolTip("Swedish law: 11 hours minimum") self.dailyrestinginput.valueChanged.connect( self.dailyrestinginputChanged) self.layout.addWidget(self.dailyrestinginput, row, 4, 1, 3) row += 1 weeklyrestingtimelbl = QLabel( "Minimum continuous weekly resting time [h]: ") self.layout.addWidget(weeklyrestingtimelbl, row, 0, 1, 4) self.weeklyrestinginput = QSpinBox() self.weeklyrestinginput.setValue(self.weeklyresting) self.weeklyrestinginput.setMinimum(1) self.weeklyrestinginput.setToolTip("Swedish law: 11 hours minimum") self.weeklyrestinginput.valueChanged.connect( self.weeklyrestinginputChanged) self.layout.addWidget(self.weeklyrestinginput, row, 4, 1, 3) row += 1 toplabel4 = QLabel( "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" ) toplabel4.setAlignment(Qt.AlignCenter) self.layout.addWidget(toplabel4, row, 0, 1, 7) self.solutionsBrowsing = QSpinBox() self.solutionsBrowsing.valueChanged.connect(self.solutionIntChangedI) self.solutionsBrowsing.setVisible(False) self.solutionsBrowsing.setKeyboardTracking(False) if self.shifttype > 1: row += 1 self.findSolutionsBtn = QPushButton("Find solutions") self.findSolutionsBtn.clicked.connect(self.findSolution) self.layout.addWidget(self.findSolutionsBtn, row, 1, 1, 1) self.find1SolutionBtn = QPushButton("Find First Solution") self.find1SolutionBtn.clicked.connect(self.find1Solution) self.layout.addWidget(self.find1SolutionBtn, row, 2, 1, 2) self.checkWeeklyRestBtn.clicked.connect(self.checkWeeklyRest) self.layout.addWidget(self.checkWeeklyRestBtn, row, 4, 1, 2) row += 1 self.solutionsLbl = QLabel("Solution index: ") self.solutionsLbl.setVisible(False) self.layout.addWidget(self.solutionsLbl, row, 0, 1, 2) self.layout.addWidget(self.solutionsBrowsing, row, 2, 1, 2) self.solutionsSlider = QSlider() self.solutionsSlider.setOrientation(Qt.Horizontal) self.solutionsSlider.setVisible(False) self.solutionsSlider.valueChanged.connect(self.solutionIntChangedS) self.solutionsSlider.sliderReleased.connect( self.solutionMatrix2Table1) self.layout.addWidget(self.solutionsSlider, row, 4, 1, 3) row += 1 toplabel4b = QLabel( "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" ) toplabel4b.setAlignment(Qt.AlignCenter) self.layout.addWidget(toplabel4b, row, 0, 1, 7) row += 1 tablelayout = QVBoxLayout() self.layout.addLayout(tablelayout, row, 0, len(self.series), 7) self.table = QTableWidget() # Create table for the series we work with tablelayout.addWidget(self.table) self.table.setColumnCount(7) self.table.setHorizontalHeaderLabels( "Mon;Tue;Wed;Thu;Fri;Sat;Sun".split(";")) for i in range(0, 7): self.table.horizontalHeader().setSectionResizeMode( i, QHeaderView.Stretch) self.table.setRowCount(len(self.series)) for rr, serie in enumerate(self.series): for col, value in enumerate(serie): if value == 0: wdg = QLabel("0") wdg.setAlignment(Qt.AlignCenter) else: wdg = QComboBox() for t in self.shifts: wdg.addItem(t) wdg.currentIndexChanged.connect(self.readTableContents) self.table.setCellWidget(rr, col, wdg) self.table.setMaximumSize(self.getQTableWidgetSize(self.table)) self.table.setMinimumSize(self.getQTableWidgetSize(self.table)) row = row + 1 + len(self.series) toplabel5 = QLabel( "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" ) toplabel5.setAlignment(Qt.AlignCenter) self.layout.addWidget(toplabel5, row, 0, 1, 7) row += 1 self.shifttype1Label = QLabel("Number of " + self.shifts[0] + "-shifts: ") self.layout.addWidget(self.shifttype1Label, row, 0, 1, 2) self.shiftsof1 = QLabel(str(self.shift1)) self.layout.addWidget(self.shiftsof1, row, 2, 1, 2) if self.shifttype > 1: row += 1 self.shifttype1Label = QLabel("Number of " + self.shifts[1] + "-shifts: ") self.layout.addWidget(self.shifttype1Label, row, 0, 1, 2) self.shiftsof2 = QLabel(str(self.shift2)) self.layout.addWidget(self.shiftsof2, row, 2, 1, 2) if self.shifttype > 2: row += 1 self.shifttype1Label = QLabel("Number of " + self.shifts[2] + "-shifts: ") self.layout.addWidget(self.shifttype1Label, row, 0, 1, 2) self.shiftsof3 = QLabel(str(self.shift3)) self.layout.addWidget(self.shiftsof3, row, 2, 1, 2) row += 1 toplabel6 = QLabel( "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" ) toplabel6.setAlignment(Qt.AlignCenter) self.layout.addWidget(toplabel6, row, 0, 1, 7) row += 1 toplabel7 = QLabel("Results:") toplabel7.setAlignment(Qt.AlignCenter) self.layout.addWidget(toplabel7, row, 0, 1, 7) row += 1 toplabel8 = QLabel( "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" ) toplabel8.setAlignment(Qt.AlignCenter) self.layout.addWidget(toplabel8, row, 0, 1, 7) row += 1 table2layout = QVBoxLayout() self.layout.addLayout(table2layout, row, 0, 3, 7) self.table2 = QTableWidget( ) # Create table for the series we work with table2layout.addWidget(self.table2) self.table2.setColumnCount(7) self.table2.setHorizontalHeaderLabels( "Mon;Tue;Wed;Thu;Fri;Sat;Sun".split(";")) for i in range(0, 7): self.table2.horizontalHeader().setSectionResizeMode( i, QHeaderView.Stretch) self.table2.setRowCount(self.shifttype) verticalHeaders = [] for rr in range(self.shifttype): for col in range(7): wdg = QLabel("0") wdg.setAlignment(Qt.AlignCenter) self.table2.setCellWidget(rr, col, wdg) verticalHeaders.append(self.shifts[rr]) self.table2.setVerticalHeaderLabels(verticalHeaders) self.table2.setMaximumSize(self.getQTableWidgetSize(self.table2)) self.table2.setMinimumSize(self.getQTableWidgetSize(self.table2)) row = row + 1 + self.shifttype * 10 self.loadButton = QPushButton("Load") self.loadButton.clicked.connect(self.loadFunctionClicked) self.layout.addWidget(self.loadButton, row, 0, 3, 2) self.saveButton = QPushButton("Save") self.saveButton.clicked.connect(self.saveFunction) self.layout.addWidget(self.saveButton, row, 2, 3, 2) self.exportButton = QPushButton("Export") self.exportButton.clicked.connect(self.exportFunction) self.exportButton.setToolTip("Export in a CSV format") self.layout.addWidget(self.exportButton, row, 4, 3, 3) row = row + 1 + self.shifttype * 10 bottomlabel1 = QLabel( "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -") bottomlabel2 = QLabel( "Coder: Benjamin Bolling ([email protected])") self.layout.addWidget(bottomlabel1, row, 0, 1, 7) row += 1 self.layout.addWidget(bottomlabel2, row, 0, 1, 7)