def set_inspection(self, projectId, sectionId, inspectionId): self.clearContents() self.projectId = projectId self.sectionId = sectionId self.inspectionId = inspectionId for r in range(self.rowCount() - 1, -1, -1): self.removeRow(r) if self.projectId is None or self.sectionId is None or self.inspectionId is None: return for o_id, obs in self.data[self.projectId]['Sections'][self.sectionId]['Inspections'][self.inspectionId]['Observations'].iteritems(): r = self.rowCount() self.insertRow(r) for c, col in enumerate(ColumnData): item = QTableWidgetItem(u'{}'.format(obs[col] if c < 6 else '')) if c in (0,6): data_column = 'Import' if c == 0 else 'ForceImport' item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Checked if obs[data_column] else Qt.Unchecked) item.setData(Qt.UserRole, o_id) item.setData(Qt.UserRole+1, data_column) else: item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) font = item.font() font.setPointSize(font.pointSize() - 2) item.setFont(font) self.setItem(r, c, item) self.resizeColumnsToContents()
def finish_init(self, data): self.data = data for c, col in enumerate(ColumnHeaders): self.insertColumn(c) item = QTableWidgetItem(col) font = item.font() font.setPointSize(font.pointSize() - 2) item.setFont(font) self.setHorizontalHeaderItem(c, item) self.adjustSize()
def populate_function_table_1(self): """Populate the tblFunctions1 table with available functions.""" hazards = deepcopy(hazard_all) exposures = exposure_all self.lblAvailableFunctions1.clear() self.tblFunctions1.clear() self.tblFunctions1.setColumnCount(len(hazards)) self.tblFunctions1.setRowCount(len(exposures)) for i in range(len(hazards)): hazard = hazards[i] item = QTableWidgetItem() item.setIcon(QIcon(get_image_path(hazard))) item.setText(hazard['name'].capitalize()) item.setTextAlignment(Qt.AlignLeft) self.tblFunctions1.setHorizontalHeaderItem(i, item) for i in range(len(exposures)): exposure = exposures[i] item = QTableWidgetItem() item.setIcon(QIcon(get_image_path(exposure))) item.setText(exposure['name'].capitalize()) self.tblFunctions1.setVerticalHeaderItem(i, item) developer_mode = setting('developer_mode', False, bool) for hazard in hazards: for exposure in exposures: item = QTableWidgetItem() if (exposure in hazard['disabled_exposures'] and not developer_mode): background_colour = unavailable_option_color # Set it disable and un-selectable item.setFlags(item.flags() & ~Qt.ItemIsEnabled & ~Qt.ItemIsSelectable) else: background_colour = available_option_color item.setBackground(QBrush(background_colour)) item.setFont(big_font) item.setTextAlignment(Qt.AlignCenter | Qt.AlignHCenter) item.setData(RoleHazard, hazard) item.setData(RoleExposure, exposure) self.tblFunctions1.setItem(exposures.index(exposure), hazards.index(hazard), item) self.parent.pbnNext.setEnabled(False)
def create_widgets(self): # main/delete/supergroup self.set_as_main_button = QPushButton("Set As Main") self.create_super_group_button = QPushButton("Create Super Group") self.delete_groups_button = QPushButton("Delete Groups") self.revert_groups_button = QPushButton("Revert Groups") self.show_groups_button = QPushButton("Show Groups") self.hide_groups_button = QPushButton("Hide Groups") # closing self.apply_button = QPushButton("Apply") self.ok_button = QPushButton("OK") self.cancel_button = QPushButton("Cancel") #table self.table = QTableWidget() self.checks = [] self.names_text = [] bold = QtGui.QFont() bold.setBold(True) bold.setItalic(True) bold.setWeight(75) anames = array(self.names) for iname, name in enumerate(anames[self.inames]): check = QTableWidgetItem() check.setCheckState(False) # TODO: create right click menu ??? name_text = QTableWidgetItem(str(name)) if iname == self.imain: name_text.setFont(bold) self.shown_set.add(iname) check.setCheckState(2) name_text.setBackground(QtGui.QColor(*self.light_grey)) elif iname in self.shown_set: name_text.setBackground(QtGui.QColor(*self.light_grey)) self.checks.append(check) self.names_text.append(name_text)
def displayColumns(self): self.clear() for c in range(self.columnCount() - 1, -1, -1): self.removeColumn(c) for r in range(self.rowCount() - 1, -1, -1): self.removeRow(r) columns = self.settings.value("columns") c = 0 for i, col in enumerate(columnVarSetting): if col in columns: if columnRowName[i] == "changedGeometryStr" and not self.geomColumn: continue self.insertColumn(c) item = QTableWidgetItem(columnFancyName[i]) item.setData(Qt.UserRole, columnRowName[i]) font = item.font() font.setPointSize(font.pointSize() - 2) item.setFont(font) self.setHorizontalHeaderItem(c, item) c += 1 self.horizontalHeader().setMinimumSectionSize(15)
def __add_record(self, ip, port, schema): count = self.__profile_table.rowCount() self.__profile_table.insertRow(count) ip_item = QTableWidgetItem(ip) ip_item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) item_font = ip_item.font() item_font.setPointSizeF(12) ip_item.setFont(item_font) port_item = QTableWidgetItem(port) port_item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) port_item.setFont(item_font) schema_item = QTableWidgetItem(schema) schema_item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) schema_item.setFont(item_font) self.__profile_table.setItem(count, 0, ip_item) self.__profile_table.setItem(count, 1, port_item) self.__profile_table.setItem(count, 2, schema_item)
def initUI(self): fontLabel = QFont('SansSerif', 14) self.setMinimumSize(1200, 600) self.resize(1200, 600) self.sentenceToFillTable = QTableWidget(5, 1, self) self.sentenceToFillTable.setGeometry(QRect(70, 60, 800, 400)) self.sentenceToFillTable.setColumnCount(1) item = QTableWidgetItem() item.setText('Sentences To Match') font = QFont() font.setBold(True) font.setWeight(75) item.setFont(font) self.sentenceToFillTable.setHorizontalHeaderItem(0, item) self.sentenceToFillTable.resizeColumnsToContents() self.sentenceToFillTable.horizontalHeader().setStretchLastSection(True) self.sentenceToFillTable.verticalHeader().setStretchLastSection(True) self.sentenceList = [] self.getSentencesFromDatabase() # split the sentences into chunks of 5 # Map to hold the anwers self.rightWordList = {} self.iteration = 0 self.sentenceMasterList = [] self.sentenceSlaveList = [] if len(self.sentenceList) > 0: for sentence in self.sentenceList: if len(self.sentenceSlaveList) < 5: self.sentenceSlaveList.append(sentence) else: self.sentenceMasterList.append(self.sentenceSlaveList) self.sentenceSlaveList = [] self.sentenceSlaveList.append(sentence) if len(self.sentenceSlaveList) <= 5: self.sentenceMasterList.append(self.sentenceSlaveList) self.maxIteration = len(self.sentenceMasterList) ## set the row height self.tableHeightSize = 0 ## Only if there is atleast one sentence fetched from the database if len(self.sentenceList) > 0: for index in range(0, 5): if len(self.sentenceList[index]) < 150: self.sentenceToFillTable.verticalHeader().resizeSection(index, 80) self.tableHeightSize = self.tableHeightSize + 90 elif len(self.sentenceList[index]) < 200: self.sentenceToFillTable.verticalHeader().resizeSection(index, 100) self.tableHeightSize = self.tableHeightSize + 100 else: self.sentenceToFillTable.verticalHeader().resizeSection(index, 120) self.tableHeightSize = self.tableHeightSize + 120 # split words from databse into chunks of 5 self.refIteration = 0 self.refWordMasterList = [] self.refWordSlaveList = [] for wordList in self.wordMap.values(): if len(self.refWordSlaveList) < 5: self.refWordSlaveList.append(wordList) else: self.refWordMasterList.append(self.refWordSlaveList) self.refWordSlaveList = [] self.refWordSlaveList.append(wordList) if len(self.refWordSlaveList) <= 5: self.refWordMasterList.append(self.refWordSlaveList) self.refMaxIteration = len(self.refWordMasterList) self.insertSentencesInTable() self.connect(self.sentenceToFillTable, SIGNAL("cellClicked(int, int)"), self.itemSelect) # create next, submit and close buttons self.nextButton = QPushButton('Next', self) self.nextButton.move(170, 520) self.nextButton.setEnabled(False) self.submitButton = QPushButton('Submit', self) self.submitButton.move(380, 520) self.closeButton = QPushButton('Close', self) self.closeButton.move(600, 520) self.connect(self.closeButton, SIGNAL('clicked()'), self.closeClicked) self.connect(self.submitButton, SIGNAL('clicked()'), self.onSubmitClicked) self.connect(self.nextButton, SIGNAL('clicked()'), self.onNextClicked) self.setWindowTitle('Sentence Fill')