def loadSentencesInTable(self): self.col = 0 if len(self.sentenceList) > 0: self.sentenceTable.setRowCount(len(self.sentenceList)) cellList = [] ## Create QTableWidgetItems from the sentence list for sentence in self.sentenceList: item = QTableWidgetItem(QString(sentence)) item.setFlags(Qt.ItemFlags(Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)) item.setCheckState(Qt.Unchecked) cellList.append(item) cellList.reverse() # set the widget items in the table for item in range(0, len(self.sentenceList)): self.sentenceTable.setItem(item, self.col, cellList.pop()) for index in range(0, len(self.sentenceList)): self.sentenceTable.verticalHeader().resizeSection(index, 100) if len(self.sentenceList) == 5: self.sentenceTable.setFixedHeight(500) if len(self.sentenceList) == 4: self.sentenceTable.setFixedHeight(400) elif len(self.sentenceList) == 3: self.sentenceTable.setFixedHeight(300) elif len(self.sentenceList) == 2: self.sentenceTable.setFixedHeight(200) elif len(self.sentenceList) == 1: self.sentenceTable.setFixedHeight(100) else: self.sentenceTable.clearContents()
def setTableContent(self): numOutputs = 0 for output in self.alg.outputs: if isinstance(output, (OutputVector, OutputRaster)): if not output.hidden: numOutputs += 1 self.tblStyles.setRowCount(numOutputs) i = 0 for output in self.alg.outputs: if isinstance(output, (OutputVector, OutputRaster)): if not output.hidden: item = QTableWidgetItem(output.description + '<' + output.__class__.__name__ + '>') item.setFlags(Qt.ItemIsEnabled) self.tblStyles.setItem(i, 0, item) item = RenderingStyleFilePanel() style = \ RenderingStyles.getStyle(self.alg.commandLineName(), output.name) if style: item.setText(unicode(style)) self.valueItems[output.name] = item self.tblStyles.setCellWidget(i, 1, item) self.tblStyles.setRowHeight(i, 22) i += 1
def initTable(self): # stop the update timer self.timerDataRequest.stop() # init servo memory data table self.tableServoData.clear() self.tableServoData.setColumnCount(1) self.tableServoData.setHorizontalHeaderItem( 0, QTableWidgetItem('Parameter')) self.tableServoData.setRowCount( len(self.serialProtocol.memoryInfo['fieldNames'])) rowNumber = 0 for fieldName in self.serialProtocol.memoryInfo['fieldNames']: fieldInfo = self.serialProtocol.memoryInfo[fieldName] nameItem = QTableWidgetItem(fieldInfo['name']) if fieldInfo['writable']: nameItem.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) else: nameItem.setFlags(Qt.ItemFlag()) self.tableServoData.setItem(rowNumber, 0, nameItem) self.tableServoData.resizeRowToContents(rowNumber) self.tableServoData.setRowHeight( rowNumber, self.tableServoData.rowHeight(rowNumber) - 7) rowNumber += 1 self.tableServoData.resizeColumnToContents(0) # restart the update timer self.timerDataRequest.start(20)
def _add_proc_to_table(self, row, proc_info): self.setItem(row, 0, QTableWidgetItem(str(proc_info.identifier))) self.item(row, 0).setTextAlignment(Qt.AlignCenter) self.setItem(row, 1, QTableWidgetItem(str(proc_info.name))) self.setItem(row, 2, QTableWidgetItem(str(proc_info.cs_overhead))) self.item(row, 2).setTextAlignment(Qt.AlignRight | Qt.AlignVCenter) self.setItem(row, 3, QTableWidgetItem(str(proc_info.cl_overhead))) self.item(row, 3).setTextAlignment(Qt.AlignRight | Qt.AlignVCenter) self.setItem( row, 4, QTableWidgetItem(', '.join([x.name for x in proc_info.caches]))) penalty_item = QTableWidgetItem(str(proc_info.penalty)) penalty_item.setFlags(penalty_item.flags() ^ (Qt.ItemIsEditable | Qt.ItemIsEnabled)) self.setItem(row, 5, penalty_item) self.item(row, 5).setTextAlignment(Qt.AlignRight | Qt.AlignVCenter) self.setItem(row, 6, QTableWidgetItem(str(proc_info.speed))) for col in range(len(self._custom_fields)): key = self._custom_fields[col] if key in proc_info.data and proc_info.data[key] is not None: item = QTableWidgetItem(str(proc_info.data[key])) else: item = QTableWidgetItem('') item.setBackgroundColor(QColor.fromRgb(200, 255, 200)) self.setItem(row, col + len(self._header), item)
def populateVars(self, selectedVar=None): selected = None self.ui.varTableWidget.clear() self.ui.varTableWidget.setSortingEnabled(False) self.ui.varTableWidget.setRowCount(len(self.__vars)) headers = ["Name", "Value", "Info"] self.ui.varTableWidget.setColumnCount(len(headers)) self.ui.varTableWidget.setHorizontalHeaderLabels(headers) for row, name in enumerate(sorted(self.__vars.keys())): item = QTableWidgetItem(name) item.setData(Qt.UserRole, QVariant(name)) flags = item.flags() flags ^= Qt.ItemIsEditable item.setFlags(flags) self.ui.varTableWidget.setItem(row, 0, item) item2 = QTableWidgetItem(self.__vars[name] or "") self.ui.varTableWidget.setItem(row, 1, item2) item3 = QTableWidgetItem(self.__pardesc[name]['doc'] or "") flags = item3.flags() flags &= ~Qt.ItemIsEnabled item3.setFlags(flags) self.ui.varTableWidget.setItem(row, 2, item3) if selectedVar is not None and selectedVar == name: selected = item2 self.ui.varTableWidget.setSortingEnabled(True) self.ui.varTableWidget.resizeColumnsToContents() self.ui.varTableWidget.horizontalHeader()\ .setStretchLastSection(True) if selected is not None: selected.setSelected(True) self.ui.varTableWidget.setCurrentItem(selected)
def populateTable(self,filePath): self.filePath = filePath ui = self table = ui.tableWidget # table.clear() table.setRowCount(0) xml = file(filePath).read() d = QtXml.QDomDocument() d.setContent(xml) maps = d.elementsByTagName("maplayer") self.maps=maps for i in range(maps.length()): table.setRowCount(table.rowCount()+1) info = getMapInfo(maps.item(i)) nameItem = QTableWidgetItem(info['name']) nameItem.setFlags(QtCore.Qt.ItemIsUserCheckable|QtCore.Qt.ItemIsSelectable|QtCore.Qt.ItemIsEnabled) nameItem.setCheckState(QtCore.Qt.Unchecked) nameItem.setData(QtCore.Qt.UserRole,str(i)) table.setItem(i,0,nameItem) table.setItem(i,1,FixedWidgetItem(info['mtype'])) table.setItem(i,2,FixedWidgetItem(info['geom'])) table.setItem(i,3,FixedWidgetItem(info['provider'])) ds = FixedWidgetItem(info['ds']) ds.setData(QtCore.Qt.ToolTipRole,info['ds']) table.setItem(i,4,ds)
def render_result(self): query = self.query_edit.text() if not query: return self.feed = FeedBooks() response = self.feed.search(str(query)) if not response: QMessageBox.critical(self, 'Error', 'Could not get any result') return self.table.clear() self.table.setHorizontalHeaderLabels(['Select', 'Title', 'URL']) self.table.setRowCount(len(response[1])) for i, name in enumerate(zip(response[1], response[3])): item = QTableWidgetItem(1) item.data(Qt.CheckStateRole) item.setCheckState(Qt.Checked) self.table.setItem(i, 0, item) for j in range(2): item = QTableWidgetItem(name[j]) item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) self.table.setItem(i, j+1, item) self.table.resizeColumnsToContents()
def _add_proc_to_table(self, row, proc_info): self.setItem(row, 0, QTableWidgetItem(str(proc_info.identifier))) self.item(row, 0).setTextAlignment(Qt.AlignCenter) self.setItem(row, 1, QTableWidgetItem(str(proc_info.name))) self.setItem(row, 2, QTableWidgetItem(str(proc_info.cs_overhead))) self.item(row, 2).setTextAlignment(Qt.AlignRight | Qt.AlignVCenter) self.setItem(row, 3, QTableWidgetItem(str(proc_info.cl_overhead))) self.item(row, 3).setTextAlignment(Qt.AlignRight | Qt.AlignVCenter) self.setItem( row, 4, QTableWidgetItem(', '.join([x.name for x in proc_info.caches]))) penalty_item = QTableWidgetItem(str(proc_info.penalty)) penalty_item.setFlags(penalty_item.flags() ^ (Qt.ItemIsEditable | Qt.ItemIsEnabled)) self.setItem(row, 5, penalty_item) self.item(row, 5).setTextAlignment(Qt.AlignRight | Qt.AlignVCenter) self.setItem(row, 6, QTableWidgetItem(str(proc_info.speed))) for col in range(len(self._custom_fields)): key = self._custom_fields[col] if key in proc_info.data and proc_info.data[key] is not None: item = QTableWidgetItem(str(proc_info.data[key])) else: item = QTableWidgetItem('') item.setBackgroundColor(QColor.fromRgb(200, 255, 200)) self.setItem(row, col + len(self._header), item)
def load_words(self): dictionary = self.dictionaries[self.dict_combo.currentIndex()] words = Word.objects.filter(dictionary=dictionary.abbrev) \ .order_by('original') paginator = Paginator(words, self.row, allow_empty_first_page=True) try: page_obj = paginator.page(self.page_number) except InvalidPage: return self.words_table.clear() self.words_table.setRowCount(len(page_obj.object_list)) self.words_table.setHorizontalHeaderLabels(['Original', 'Translation', 'Parts of Speech', 'Phoneme', 'Synonyms', 'Antonyms', 'Added at', 'Status' ]) for i, word in enumerate(page_obj.object_list): for j, cell in enumerate([word.original, word.translation, word.pos, word.phoneme, word.synonyms, word.antonyms, word.added_at.strftime("%Y-%m-%d %H:%M"), "exported" if word.exported else "new"]): item = QTableWidgetItem(cell) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.words_table.setItem(i, j, item) self.next_button.setEnabled(page_obj.has_next()) self.previous_button.setEnabled(page_obj.has_previous())
def addRequest(self, widget=None): currow = self.rowCount() self.setRowCount(self.rowCount() + 1) # Add conjonctions if not First widget if len(self.fieldMapper) != 0: conjonction = ConjonctionCombo(self) self.setCellWidget(currow, 0, conjonction) self.horizontalHeader().setResizeMode(0, QHeaderView.ResizeToContents) else: empty = QTableWidgetItem(QString("")) empty.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled) self.setItem(currow, 0, empty) # Add Field choice fields = FieldCombo(self) self.connect(fields, SIGNAL("fieldChanged"), self.changeFilterType) self.setCellWidget(currow, 1, fields) self.fieldMapper.append(fields.fieldCombo) # Add Widget if widget == None: widget = NameRequest(self) self.setCellWidget(currow, 2, widget) # Add request button add = self.createAddRequestButton() self.setCellWidget(currow, 3, add) # Remove request button rm = removeRequestButton() self.removeMapper.append(rm) self.connect(rm, SIGNAL("removeRequest"), self.removeRequest) self.setCellWidget(currow, 4, rm)
def addMachine(self,name,ip,status=''): for row in self.machinesData.values: if row.has_key('nameItem'): if row['nameItem'] == name: isAlive = True else: rowNumber = self.tbl.rowCount() nameItem = QTableWidgetItem(name) IPItem = QTableWidgetItem(self.machinesData[name]) statusItem = QTableWidgetItem(status) checkboxItem = QTableWidgetItem() checkboxItem.setFlags(Qt.ItemIsEnabled|Qt.ItemIsUserCheckable) checkboxItem.setCheckState(Qt.Checked) transferItem = QTableWidgetItem('') self.allItemsChecked = True self.tbl.insertRow(rowNumber) self.tbl.setItem(rowNumber,NAME,nameItem) self.tbl.setItem(rowNumber,IP,IPItem) self.tbl.setItem(rowNumber,STATUS,statusItem) self.tbl.setItem(rowNumber,CHECKED,checkboxItem) self.tbl.setItem(rowNumber,TRANSFER,transferItem) self.machinesData[rowNumber] = {'checkboxItem':checkboxItem, 'nameItem':nameItem, 'IPItem':IPItem, 'statusItem':statusItem, 'transferItem':transferItem} row = self.machinesData[rowNumber] isAlive = None self.emit(SIGNAL('updateStatus'),row,isAlive) return
def load_items(self): """ Load items from the indexed_items list and add them in the self.indexedItems QTableWidget. """ count = 0 # get the list of already indexed stuff and add them in the qtablewidget # with a not-editable check box indicating if it has been indexed # recursively or not for i in self.indexed_items: node = VFS.Get().getNodeFromPointer(long(i)) if node == None: continue recurse = self.indexed_items[i] new_item = QTableWidgetItem(QIcon(":/folder.png"), node.name()) self.indexedItems.setRowCount(count + 1) new_item.setData(Qt.UserRole + 1, QVariant(long(node.this))) self.indexedItems.setItem(count, 0, new_item) new_item2 = QTableWidgetItem() new_item2.setFlags(Qt.ItemIsUserCheckable) if recurse: new_item2.setCheckState(Qt.Checked) else: new_item2.setCheckState(Qt.Unchecked) self.indexedItems.setItem(count, 1, new_item2) count += 1 return count
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 updateTable(self, rhive, key): self.resetTable() values = key.values for value in values: currow = self.rowCount() self.setRowCount(self.rowCount() + 1) if value.name: name = value.name else: name = "(Default)" # item_name = valueItem(value.fetch_data(), key.name) # item_name = QTableWidgetItem(QString.fromUtf8(name)) # item_name.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled) item_name = valueItem(name, key.name) item_type = QTableWidgetItem(QString(regtype[value.type])) item_type.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) item_data = valueItem(value.fetch_data(), key.name) #QTableWidgetItem(self.dataToQString(value.fetch_data())) # item_data.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled) self.setItem(currow, 0, item_name) self.setItem(currow, 1, item_type) self.setItem(currow, 2, item_data) del (rhive)
def addRequest(self, widget=None): currow = self.rowCount() self.setRowCount(self.rowCount() + 1) # Add conjonctions if not First widget if len(self.fieldMapper) != 0: conjonction = ConjonctionCombo(self) self.connect(conjonction, SIGNAL("queryUpdated"), self.updateQuery) self.setCellWidget(currow, 0, conjonction) self.horizontalHeader().setResizeMode(0, QHeaderView.ResizeToContents) else: empty = QTableWidgetItem(QString("")) empty.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.setItem(currow, 0, empty) # Add Field choice fields = FieldCombo(self) self.connect(fields, SIGNAL("fieldChanged"), self.changeFilterType) self.setCellWidget(currow, 1, fields) self.fieldMapper.append(fields.fieldCombo) # Add Widget if widget == None: widget = StringRequest(self, 'name') self.connect(widget, SIGNAL("queryUpdated"), self.updateQuery) self.setCellWidget(currow, 2, widget) # Add request button add = self.createAddRequestButton() self.setCellWidget(currow, 3, add) # Remove request button rm = removeRequestButton() self.removeMapper.append(rm) self.connect(rm, SIGNAL("removeRequest"), self.removeRequest) self.setCellWidget(currow, 4, rm) self.updateQuery()
def clear_table(self): self.need_to_update_graph = False for r in range(self.table.rowCount()): self.table.setItem(r, 0, QTableWidgetItem(None)) self.table.setItem(r, 1, QTableWidgetItem(None)) for row in range(self.rows_nr): for col in range(self.cols_nr): if self.edit_type == self.edit_patterns: if col == 0: item = QTableWidgetItem(str(row)) self.table.setItem(row, col, item) item.setFlags(QtCore.Qt.ItemIsSelectable) # elif col == 1 and row == 0: # item = QTableWidgetItem(str(1)) # self.table.setItem(row, col, item) # item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) # elif self.edit_type == self.edit_curves: # if row == 0: # item = QTableWidgetItem(str(0)) # self.table.setItem(row, 0, item) # item = QTableWidgetItem(str(1)) # self.table.setItem(row, 1, item) # item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.need_to_update_graph = True
def initTable(self): # stop the update timer self.timerDataRequest.stop() # init servo memory data table self.tableServoData.clear() self.tableServoData.setColumnCount(1) self.tableServoData.setHorizontalHeaderItem(0, QTableWidgetItem('Parameter')) self.tableServoData.setRowCount(len(self.serialProtocol.memoryInfo['fieldNames'])) rowNumber = 0 for fieldName in self.serialProtocol.memoryInfo['fieldNames']: fieldInfo = self.serialProtocol.memoryInfo[fieldName] nameItem = QTableWidgetItem(fieldInfo['name']) if fieldInfo['writable']: nameItem.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) else: nameItem.setFlags(Qt.ItemFlag()) self.tableServoData.setItem(rowNumber, 0, nameItem) self.tableServoData.resizeRowToContents(rowNumber) self.tableServoData.setRowHeight(rowNumber, self.tableServoData.rowHeight(rowNumber) - 7) rowNumber += 1 self.tableServoData.resizeColumnToContents(0) # restart the update timer self.timerDataRequest.start(20)
def __init__(self, parent=None, datalist=None, mode='r'): super(SimpleListDlg, self).__init__(parent) self.tbl = QTableWidget() self.mode = mode # read only or write 'r'/'w' self.values = [] if datalist is not None: data = datalist.toList() self.tbl.setRowCount(len(data)) self.tbl.setColumnCount(1) for i, val in enumerate(data): #print i, val.toFloat() self.values.append(val.toFloat()[0]) it = QTableWidgetItem("%g" % val.toFloat()[0]) if self.mode == 'r': it.setFlags(it.flags() & ~Qt.ItemIsEditable) self.tbl.setItem(i, 0, it) buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) layout = QVBoxLayout() layout.addWidget(self.tbl) layout.addWidget(buttonBox) self.setLayout(layout) self.connect(buttonBox, SIGNAL("accepted()"), self.accept) self.connect(buttonBox, SIGNAL("rejected()"), self.reject)
def updateTable(self, rhive, key): self.resetTable() values = key.values for value in values: currow = self.rowCount() self.setRowCount(self.rowCount() + 1) if value.name: name = value.name else: name = "(Default)" # item_name = valueItem(value.fetch_data(), key.name) # item_name = QTableWidgetItem(QString.fromUtf8(name)) # item_name.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled) item_name = valueItem(name, key.name) item_type = QTableWidgetItem(QString(regtype[value.type])) item_type.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) item_data = valueItem(value.fetch_data(), key.name) # QTableWidgetItem(self.dataToQString(value.fetch_data())) # item_data.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled) self.setItem(currow, 0, item_name) self.setItem(currow, 1, item_type) self.setItem(currow, 2, item_data) del (rhive)
def create_table_widget(table, parent): formats = table.getColFormats() names = table.getColNames() indices_of_visible_columns = [ j for (j, f) in enumerate(formats) if f is not None ] headers = ["ok"] + [names[j] for j in indices_of_visible_columns] n_rows = len(table) widget = QTableWidget(n_rows, 1 + len(indices_of_visible_columns), parent=parent) widget.setHorizontalHeaderLabels(headers) widget.setMinimumSize(200, 200) widget.horizontalHeader().setResizeMode(QHeaderView.Interactive) for i, row in enumerate(table.rows): item = QTableWidgetItem() item.setCheckState(Qt.Unchecked) item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsUserCheckable) widget.setItem(i, 0, item) for j0, j in enumerate(indices_of_visible_columns): value = row[j] formatter = table.colFormatters[j] item = QTableWidgetItem(formatter(value)) item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) widget.setItem(i, j0 + 1, item) return widget
def AddVersion(self): self.ui.versions.insertRow(0) item = QTableWidgetItem(str(self.ui.versions.rowCount())) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsUserCheckable) self.ui.versions.setItem(0, 0, item) self.ui.versions.setItem(0, 1, QTableWidgetItem(str(1.0)))
def __init__(self, parent = None, datalist = None, mode='r'): super(SimpleListDlg, self).__init__(parent) self.tbl = QTableWidget() self.mode = mode # read only or write 'r'/'w' self.values = [] if datalist is not None: data = datalist.toList() self.tbl.setRowCount(len(data)) self.tbl.setColumnCount(1) for i,val in enumerate(data): #print i, val.toFloat() self.values.append(val.toFloat()[0]) it = QTableWidgetItem("%g" % val.toFloat()[0]) if self.mode == 'r': it.setFlags(it.flags() & ~Qt.ItemIsEditable) self.tbl.setItem(i,0,it) buttonBox = QDialogButtonBox(QDialogButtonBox.Ok| QDialogButtonBox.Cancel) layout = QVBoxLayout() layout.addWidget(self.tbl) layout.addWidget(buttonBox) self.setLayout(layout) self.connect(buttonBox, SIGNAL("accepted()"), self.accept) self.connect(buttonBox, SIGNAL("rejected()"), self.reject)
def get_columns_names(self): """ A function that retrieves the name of the columns from the .csv file and returns a list with name :return: """ self.IHD.TWColumnNames.clear() with open(self.input_file) as f: read_all = f.readlines() first_row_bo = True if not self.rb_pressed: c = read_all[0].count(",") sc = read_all[0].count(";") if c > sc: self.sep = "," else: self.sep = ";" for row in read_all: row = row.split(self.sep) if first_row_bo: first_row = row first_row_bo = False else: second_row = row break headingrow = [] for col in first_row: only_char = check_text(col) headingrow.append(only_char) self.col_types = self.determine_coloumn_type() combo_box_options = ["Integer", "Decimal value", "Character"] self.combo = [] self.IHD.TWColumnNames.setRowCount(len(headingrow)) self.IHD.TWColumnNames.setColumnCount(3) self.IHD.TWColumnNames.setSelectionBehavior( QAbstractItemView.SelectRows) for i, col in enumerate(headingrow): item1 = QTableWidgetItem(col) item1.setFlags(xor(item1.flags(), QtCore.Qt.ItemIsEditable)) item2 = QTableWidgetItem(second_row[i]) item2.setFlags(xor(item2.flags(), QtCore.Qt.ItemIsEditable)) self.combo.append(RadioComboBox()) for nr, t in enumerate(combo_box_options): self.combo[i].addItem(t) item = self.combo[i].model().item(nr, 0) if self.col_types[i] == nr: item.setCheckState(QtCore.Qt.Checked) self.combo[i].setCurrentIndex(nr) else: item.setCheckState(QtCore.Qt.Unchecked) self.IHD.TWColumnNames.setItem(i, 0, item1) self.IHD.TWColumnNames.setItem(i, 1, item2) self.IHD.TWColumnNames.setCellWidget(i, 2, self.combo[i]) self.combo[i].view().pressed.connect(self.change_col_type) first_row_checked = [] for name in first_row: first_row_checked.append(check_text(name)) self.IHD.ComBHarvestCol.addItems(first_row_checked) self.heading_row = first_row_checked self.IHD.pButInsertDataIntoDB.setEnabled(True)
def showDescriptors(self, processMIdx): try: self.handlesTable.setRowCount(0) self.handlesTable.clearContents() descriptors = self.model.getProcDescriptors(processMIdx) libs = self.model.getProcLibraries(processMIdx) self.handlesTable.setRowCount(len(descriptors) + len(libs)) except PermissionError: self.handlesTable.setRowCount(1) self.handlesTable.setSpan(0, 0, 1, 2) permDeniedMsg = QTableWidgetItem('<Permission Denied>') permDeniedMsg.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) permDeniedMsg.setTextAlignment(Qt.AlignCenter) permDeniedMsg.setTextColor(QColor(255, 0, 0)) self.handlesTable.setItem(0, 0, permDeniedMsg) else: for row, descriptor in enumerate(descriptors): typeItem = QTableWidgetItem(descriptor.type) typeItem.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) nameItem = QTableWidgetItem(descriptor.name) nameItem.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.handlesTable.setItem(row, 0, typeItem) self.handlesTable.setItem(row, 1, nameItem) for row, libName in enumerate(libs, start=len(descriptors)): typeItem = QTableWidgetItem('Shared Library') typeItem.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) nameItem = QTableWidgetItem(libName) nameItem.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.handlesTable.setItem(row, 0, typeItem) self.handlesTable.setItem(row, 1, nameItem)
def setTableContent(self): params = self._alg.parameters outputs = self._alg.outputs visibleParams = [p for p in params if not p.hidden] visibleOutputs = [p for o in outputs if not o.hidden] self.tableWidget.setRowCount(len(visibleParams) + len(visibleOutputs)) for i, param in visibleParams: item = QTableWidgetItem(param.description) item.setFlags(Qt.ItemIsEnabled) self.tableWidget.setItem(i, 0, item) item = self.getWidgetFromParameter(param) self.valueItems[param.name] = item self.tableWidget.setCellWidget(i, 1, item) self.tableWidget.setRowHeight(i, 22) for i, output in visibleOutputs: item = QTableWidgetItem(output.description + '<' + output.__module__.split('.')[-1] + '>') item.setFlags(Qt.ItemIsEnabled) self.tableWidget.setItem(i, 0, item) item = QLineEdit() if hasattr(item, 'setPlaceholderText'): item.setPlaceholderText(ModelerParametersDialog.ENTER_NAME) self.valueItems[output.name] = item self.tableWidget.setCellWidget(i, 1, item) self.tableWidget.setRowHeight(i, 22)
def create_table_widget(table, parent): formats = table.getColFormats() names = table.getColNames() indices_of_visible_columns = [j for (j, f) in enumerate(formats) if f is not None] headers = ["ok"] + [names[j] for j in indices_of_visible_columns] n_rows = len(table) widget = QTableWidget(n_rows, 1 + len(indices_of_visible_columns), parent=parent) widget.setHorizontalHeaderLabels(headers) widget.setMinimumSize(200, 200) widget.horizontalHeader().setResizeMode(QHeaderView.Interactive) for i, row in enumerate(table.rows): item = QTableWidgetItem() item.setCheckState(Qt.Unchecked) item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsUserCheckable) widget.setItem(i, 0, item) for j0, j in enumerate(indices_of_visible_columns): value = row[j] formatter = table.colFormatters[j] item = QTableWidgetItem(formatter(value)) item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) widget.setItem(i, j0 + 1, item) return widget
def add_to_table(self, table, row, row_list, set_enabled=True, color=[255, 255, 255]): for col in range(len(row_list)): item = QTableWidgetItem(str(row_list[col])) if set_enabled: item.setFlags(QtCore.Qt.ItemIsEnabled) table.setItem(row, col, item) table.item(row, col).setBackground(QtGui.QColor(color[0], color[1], color[2]))
def setTableContent(self): params = self._alg.parameters outputs = self._alg.outputs visibleParams = [p for p in params if not p.hidden] visibleOutputs = [p for o in outputs if not o.hidden] self.tableWidget.setRowCount(len(visibleParams) + len(visibleOutputs)) for i, param in visibleParams: item = QTableWidgetItem(param.description) item.setFlags(Qt.ItemIsEnabled) self.tableWidget.setItem(i, 0, item) item = self.getWidgetFromParameter(param) self.valueItems[param.name] = item self.tableWidget.setCellWidget(i, 1, item) self.tableWidget.setRowHeight(i, 22) for i, output in visibleOutputs: item = QTableWidgetItem(output.description + '<' + output.__module__.split('.')[-1] + '>') item.setFlags(Qt.ItemIsEnabled) self.tableWidget.setItem(i, 0, item) item = QLineEdit() if hasattr(item, 'setPlaceholderText'): item.setPlaceholderText(ModelerParametersDialog.ENTER_NAME) self.valueItems[output.name] = item self.tableWidget.setCellWidget(i, 1, item) self.tableWidget.setRowHeight(i, 22)
def setTableContent(self): numOutputs = 0 for output in self.alg.outputs: if isinstance(output, (OutputVector, OutputRaster)): if not output.hidden: numOutputs += 1 self.tblStyles.setRowCount(numOutputs) i = 0 for output in self.alg.outputs: if isinstance(output, (OutputVector, OutputRaster)): if not output.hidden: item = QTableWidgetItem(output.description + '<' + output.__class__.__name__ + '>') item.setFlags(Qt.ItemIsEnabled) self.tblStyles.setItem(i, 0, item) item = RenderingStyleFilePanel() style = \ RenderingStyles.getStyle(self.alg.commandLineName(), output.name) if style: item.setText(unicode(style)) self.valueItems[output.name] = item self.tblStyles.setCellWidget(i, 1, item) self.tblStyles.setRowHeight(i, 22) i += 1
def _add_task_to_table(self, row, task): self._ignore_cell_changed = True self.setItem(row, self._dict_header['id'], QTableWidgetItem(str(task.identifier))) self.item(row, self._dict_header['id']) \ .setTextAlignment(Qt.AlignCenter) self.setItem(row, self._dict_header['name'], QTableWidgetItem(str(task.name))) combo = QComboBox() items = [task_type for task_type in Task.task_types_names] combo.addItems(items) # FIXME: only until I get an access to the documentation. for i, t in enumerate(Task.task_types_names): if t == task.task_type: combo.setCurrentIndex(i) combo.currentIndexChanged.connect( lambda x: self._cell_changed(row, self._dict_header['task_type'])) self.setCellWidget(row, self._dict_header['task_type'], combo) item = QTableWidgetItem(task.abort_on_miss and 'Yes' or 'No') item.setFlags( Qt.ItemIsUserCheckable | Qt.ItemIsEnabled | Qt.ItemIsSelectable) item.setCheckState(task.abort_on_miss and Qt.Checked or Qt.Unchecked) self.setItem(row, self._dict_header['abort'], item) self.setItem(row, self._dict_header['list_activation_dates'], QTableWidgetItem( ', '.join(map(str, task.list_activation_dates)))) self.item(row, self._dict_header['list_activation_dates']) \ .setTextAlignment(Qt.AlignRight | Qt.AlignVCenter) for i in ['activation_date', 'period', 'deadline', 'wcet', 'base_cpi', 'n_instr', 'mix', 'acet', 'et_stddev', 'preemption_cost']: self.setItem(row, self._dict_header[i], QTableWidgetItem(str(task.__dict__[i]))) self.item(row, self._dict_header[i]) \ .setTextAlignment(Qt.AlignRight | Qt.AlignVCenter) stack_item = QTableWidgetItem(str(task.stack_file)) stack_item.setFlags(stack_item.flags() ^ (Qt.ItemIsEditable)) self.setItem(row, self._dict_header['sdp'], stack_item) combo = QComboBox() combo.currentIndexChanged.connect( lambda x: self._cell_changed(row, self._dict_header['followed'])) self.setCellWidget(row, self._dict_header['followed'], combo) for col in range(len(self._custom_fields)): key = self._custom_fields[col] if key in task.data and task.data[key] is not None: item = QTableWidgetItem(str(task.data[key])) else: item = QTableWidgetItem('') item.setBackgroundColor(QColor.fromRgb(200, 255, 200)) self.setItem(row, col + len(self._header), item) self._ignore_cell_changed = False self._show_period(task, row)
def __init__(self, parent, caller): super(aggregate, self).__init__(parent) self.parent = parent self.iface = caller.iface self.resize(QSize(310, 260)) self.setColumnCount(2) self.setColumnWidth(0, 152) self.setColumnWidth(1, 152) self.setRowCount(len(self.parameters) - 1) self.verticalHeader().hide() self.horizontalHeader().hide() S = QSettings() for row, parameter in enumerate(self.parameters): if row == 0: self.service_id = parameter[1] continue row = row - 1 pKey = QTableWidgetItem(parameter[0]) pKey.setFlags(pKey.flags() ^ Qt.ItemIsEditable) pValue = QTableWidgetItem(parameter[1]) self.setItem(row, 0, pKey) valueFromSettings = S.value( "QRealTime/%s/%s/" % (self.service_id, self.item(row, 0).text()), defaultValue="undef") if not valueFromSettings or valueFromSettings == "undef": self.setItem(row, 1, pValue) S.setValue( "QRealTime/%s/%s/" % (self.service_id, self.item(row, 0).text()), parameter[1]) else: self.setItem(row, 1, QTableWidgetItem(valueFromSettings))
def __setTableItem(self, table, row, col, text): item = table.item(row, col) if item: item.setText(text) else: newitem = QTableWidgetItem(text) newitem.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) table.setItem(row, col, newitem)
def __setTableItem(self, table, row, col, text): item = table.item(row, col) if item: item.setText(text) else: newitem = QTableWidgetItem(text) newitem.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable) table.setItem(row, col, newitem)
def _add_task_to_table(self, row, task): self._ignore_cell_changed = True self.setItem(row, self._dict_header['id'], QTableWidgetItem(str(task.identifier))) self.item(row, self._dict_header['id']) \ .setTextAlignment(Qt.AlignCenter) self.setItem(row, self._dict_header['name'], QTableWidgetItem(str(task.name))) combo = QComboBox() items = [task_type for task_type in Task.task_types_names] combo.addItems(items) combo.setCurrentIndex(combo.findText(task.task_type)) combo.currentIndexChanged.connect( lambda x: self._cell_changed(row, self._dict_header['task_type'])) self.setCellWidget(row, self._dict_header['task_type'], combo) item = QTableWidgetItem(task.abort_on_miss and 'Yes' or 'No') item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled | Qt.ItemIsSelectable) item.setCheckState(task.abort_on_miss and Qt.Checked or Qt.Unchecked) self.setItem(row, self._dict_header['abort'], item) self.setItem( row, self._dict_header['list_activation_dates'], QTableWidgetItem(', '.join(map(str, task.list_activation_dates)))) self.item(row, self._dict_header['list_activation_dates']) \ .setTextAlignment(Qt.AlignRight | Qt.AlignVCenter) for i in [ 'activation_date', 'period', 'deadline', 'wcet', 'base_cpi', 'n_instr', 'mix', 'acet', 'et_stddev', 'preemption_cost' ]: self.setItem(row, self._dict_header[i], QTableWidgetItem(str(task.__dict__[i]))) self.item(row, self._dict_header[i]) \ .setTextAlignment(Qt.AlignRight | Qt.AlignVCenter) stack_item = QTableWidgetItem(str(task.stack_file)) stack_item.setFlags(stack_item.flags() ^ (Qt.ItemIsEditable)) self.setItem(row, self._dict_header['sdp'], stack_item) combo = QComboBox() combo.currentIndexChanged.connect( lambda x: self._cell_changed(row, self._dict_header['followed'])) self.setCellWidget(row, self._dict_header['followed'], combo) for col in range(len(self._custom_fields)): key = self._custom_fields[col] if key in task.data and task.data[key] is not None: item = QTableWidgetItem(str(task.data[key])) else: item = QTableWidgetItem('') item.setBackgroundColor(QColor.fromRgb(200, 255, 200)) self.setItem(row, col + len(self._header), item) self._ignore_cell_changed = False self._show_period(task, row)
def loadOneItem(self, nameModule, typeModule): self.tableModules.setRowCount(1) item = QTableWidgetItem(str(nameModule)) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) item2 = QTableWidgetItem(str(typeModule)) item2.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.tableModules.setItem(0, 0, item) self.tableModules.setItem(0, 1, item2) self.tableModules.setCurrentItem(item)
def __init__(self, actions, parent=None): super(ActionEditorDialog, self).__init__(parent) self.actions = actions help = QLabel(translate("Shortcut Settings", '<b>Double click a cell in the Shortcut Column' \ ' to <br />modify the key sequence.</b>')) self.actionTable = QTableWidget(self) self.actionTable.setSelectionBehavior(QTableWidget.SelectRows) self.actionTable.setEditTriggers(QTableWidget.DoubleClicked) self.actionTable.setColumnCount(2) self.actionTable.setHorizontalHeaderLabels( [translate("Shortcut Settings", "Description"), translate("Shortcut Settings", "Shortcut")] ) self.actionTable.horizontalHeader().setStretchLastSection(True) self.actionTable.verticalHeader().hide() self.actionTable.setItemDelegate(ActionEditorDelegate(self)) self.connect(self.actionTable, SIGNAL("cellChanged(int, int)"), self.validateAction) row = 0 for action in self.actions: if action.text().isEmpty(): continue self.actionTable.insertRow(self.actionTable.rowCount()) item = QTableWidgetItem() item.setText(action.text()) item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) self.actionTable.setItem(row, 0, item) item = QTableWidgetItem() item.setText(action.shortcut().toString()) item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsEditable | Qt.ItemIsSelectable) item.oldShortcutText = item.text() self.actionTable.setItem(row, 1, item) row += 1 self.actionTable.resizeColumnsToContents() mainLayout = QVBoxLayout() mainLayout.addWidget(help) mainLayout.setMargin(8) mainLayout.setSpacing(8) mainLayout.addWidget(self.actionTable) self.setLayout(mainLayout) self._model = self.actionTable.model() self._model.edited = False self.actionTable.model().edited = False self.setWindowTitle(translate("Shortcut Settings", "Edit Shortcuts"))
def loadOneItem(self, nameModule, typeModule): self.tableModules.setRowCount(1) item = QTableWidgetItem(str(nameModule)) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) item2 = QTableWidgetItem(str(typeModule)) item2.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.tableModules.setItem(0, 0, item) self.tableModules.setItem(0, 1, item2) self.tableModules.setCurrentItem(item)
def generateIdField(id=''): """ @rtype: QTableWidgetItem """ idField = QTableWidgetItem(str(id)) idField.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) idField.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter) return idField
def generateIdField(id=''): """ @rtype: QTableWidgetItem """ idField = QTableWidgetItem(str(id)) idField.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) idField.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter) return idField
def add_row(self): row_pos = self.table.rowCount() self.table.insertRow(row_pos) col = 0 item = QTableWidgetItem(str(row_pos)) if self.edit_type == self.edit_patterns: self.table.setItem(row_pos, col, item) item.setFlags(QtCore.Qt.ItemIsSelectable)
def onBtnSearchClicked(self, checked=False): handleSubstr = self.txtSearch.text() if handleSubstr: results = self.model.findHandlesBySubstr(handleSubstr) self.tblResults.setRowCount(len(results)) for row, res in enumerate(results): for col, prop in enumerate(res): item = QTableWidgetItem(str(prop)) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.tblResults.setItem(row, col, item)
def _setconfigtable(self, content): """""" # head = self.masarConfigTableWidget.horizontalHeader() self.masarConfigTableWidget.clearContents() # self.masarConfigTableWidget.setHorizontalHeaderLabels(head) if len(content) > 1: self.masarConfigTableWidget.setRowCount(len(content) - 1) n = 0 data = sorted(content[1:], key=itemgetter(0), reverse=True) for res in data: m = 0 for item in res: if not isinstance(item, basestring): item = str(item) if item: if m == 5: newitem = QtGui.QComboBox() newitem.addItem("active") newitem.addItem("inactive") if item == "active": newitem.setCurrentIndex(0) else: newitem.setCurrentIndex(1) newitem.row = n newitem.column = m self.masarConfigTableWidget.setCellWidget( n, m, newitem) self.comboxboxSignalMapper.setMapping( newitem, newitem) newitem.currentIndexChanged.connect( self.comboxboxSignalMapper.map) updatebutton = QtGui.QPushButton() updatebutton.setText("Update") updatebutton.setEnabled(False) updatebutton.row = n updatebutton.column = m + 1 self.pushbuttonSignalMapper.setMapping( updatebutton, updatebutton) self.masarConfigTableWidget.setCellWidget( n, m + 1, updatebutton) updatebutton.clicked.connect( self.pushbuttonSignalMapper.map) else: newitem = QTableWidgetItem(item) newitem.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) self.masarConfigTableWidget.setItem(n, m, newitem) m += 1 n += 1 self.masarConfigTableWidget.resizeColumnsToContents()
def initWithExtents(self, axes, shape, start, stop): self.setColumnCount(3) self.setHorizontalHeaderLabels(["range", "[start,", "stop)"]) self.resizeColumnsToContents() tagged_shape = collections.OrderedDict(zip(axes, shape)) tagged_start = collections.OrderedDict(zip(axes, start)) tagged_stop = collections.OrderedDict(zip(axes, stop)) self._tagged_shape = tagged_shape self.setRowCount(len(tagged_shape)) self.setVerticalHeaderLabels(tagged_shape.keys()) self._boxes.clear() for row, (axis_key, extent) in enumerate(tagged_shape.items()): # Init 'full' checkbox checkbox_item = QTableWidgetItem("All") if tagged_start[axis_key] is None: checkbox_item.setCheckState(Qt.Checked) else: checkbox_item.setCheckState(Qt.Unchecked) checkbox_item.setFlags( Qt.ItemFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)) self.setItem(row, 0, checkbox_item) # Init min/max spinboxes default_start = tagged_start[axis_key] or 0 default_stop = tagged_stop[axis_key] or extent or DEFAULT_MAX_EXTENT extent = extent or DEFAULT_MAX_EXTENT startBox = RoiSpinBox(self, 0, extent - 1, 0) stopBox = RoiSpinBox(self, 1, extent, extent) startBox.setPartner(stopBox) stopBox.setPartner(startBox) startBox.setEnabled(tagged_start[axis_key] is not None) stopBox.setEnabled(tagged_stop[axis_key] is not None) if startBox.isEnabled(): startBox.setValue(default_start) if stopBox.isEnabled(): stopBox.setValue(default_stop) startBox.valueChanged.connect(self._updateRoi) stopBox.valueChanged.connect(self._updateRoi) self.setCellWidget(row, 1, startBox) self.setCellWidget(row, 2, stopBox) self._boxes[axis_key] = (checkbox_item, startBox, stopBox) self._updateRoi() self.resizeColumnsToContents()
def onAddVariableClicked(self): ''' Add a variable to the list from the text input when the user clicks on the corresponding button ''' if not self.initDone: return # Get table and row count tw = self.dlg.twVariableList twRowCount = tw.rowCount() # Get input data vname = unicode(self.dlg.inVariableName.text()).strip(' \t') vvalue = unicode(self.dlg.inVariableValue.text()).strip(' \t') # Check if the variable if not already in the list if vname in self.variableList: self.updateLog( self.tr(u'This variable is already in the list') ) return # Add constraint of possible input values p = re.compile('^[a-zA-Z]+$') if not p.match( vname ): self.updateLog( self.tr(u'The variable must contain only lower case ascii letters !') ) return # Set table properties tw.setRowCount(twRowCount + 1) tw.setColumnCount( 2 ) # Empty the name text input self.dlg.inVariableName.setText(u'') # Add the new "variable" item to the table # name newItem = QTableWidgetItem() newItem.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled ) newItem.setData( Qt.EditRole, vname ) tw.setItem(twRowCount, 0, newItem) # value newItem = QTableWidgetItem() newItem.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEditable | Qt.ItemIsEnabled ) newItem.setData( Qt.EditRole, vvalue ) tw.setItem(twRowCount, 1, newItem) # Add variable to the list self.variableList.append( vname ) # Add variable to the project p = QgsProject.instance() p.writeEntry( 'PluginDynamicLayers', 'VariableList', self.variableList ) p.setDirty( True )
def populate(self, modules): i = 0 for k, v in modules.iteritems(): item = QTableWidgetItem(str(k)) item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) item.setCheckState(Qt.Checked) itemv = QTableWidgetItem(str(v)) itemv.setFlags(Qt.ItemIsEnabled) self.setItem(i, 0, item) self.setItem(i, 1, itemv) i += 1
def initWithExtents(self, axes, shape, start, stop): self.setColumnCount( 3 ) self.setHorizontalHeaderLabels(["range", "[start,", "stop)"]) self.resizeColumnsToContents() tagged_shape = collections.OrderedDict( zip(axes, shape) ) tagged_start = collections.OrderedDict( zip(axes, start) ) tagged_stop = collections.OrderedDict( zip(axes, stop) ) self._tagged_shape = tagged_shape self.setRowCount( len(tagged_shape) ) self.setVerticalHeaderLabels( tagged_shape.keys() ) self._boxes.clear() for row, (axis_key, extent) in enumerate(tagged_shape.items()): # Init 'full' checkbox checkbox_item = QTableWidgetItem("All") if tagged_start[axis_key] is None: checkbox_item.setCheckState( Qt.Checked ) else: checkbox_item.setCheckState( Qt.Unchecked ) checkbox_item.setFlags( Qt.ItemFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) ) self.setItem(row, 0, checkbox_item) # Init min/max spinboxes default_start = tagged_start[axis_key] or 0 default_stop = tagged_stop[axis_key] or extent or DEFAULT_MAX_EXTENT extent = extent or DEFAULT_MAX_EXTENT startBox = RoiSpinBox(self, 0, extent-1, 0 ) stopBox = RoiSpinBox(self, 1, extent, extent ) startBox.setPartner( stopBox ) stopBox.setPartner( startBox ) startBox.setEnabled( tagged_start[axis_key] is not None ) stopBox.setEnabled( tagged_stop[axis_key] is not None ) if startBox.isEnabled(): startBox.setValue( default_start ) if stopBox.isEnabled(): stopBox.setValue( default_stop ) startBox.valueChanged.connect( self._updateRoi ) stopBox.valueChanged.connect( self._updateRoi ) self.setCellWidget( row, 1, startBox ) self.setCellWidget( row, 2, stopBox ) self._boxes[axis_key] = (checkbox_item, startBox, stopBox) self._updateRoi() self.resizeColumnsToContents()
def viewTableUpdate(self, id): write = int(str(self.gtable.cellWidget(id, 0).currentText()), 16) t = self.tables.tablesIdWriteMap[id][write] l = t.blockList for x in xrange(0, len(t.blockList[0])): block = t.blockList[0][x] c = ((x) % 20) r = ((x) / 20) item = QTableWidgetItem(QString(hex(block))) tipBlock = (id * 960) + x item.setToolTip(QString(hex(tipBlock))) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.vtable.setItem(r ,c, item)
def fill_first_tlb(self): self.IDB.TWTableNames.setRowCount(len(self.tbl_names)) self.IDB.TWTableNames.setColumnCount(1) self.IDB.TWTableNames.setSelectionBehavior( QAbstractItemView.SelectRows) for i, row in enumerate(self.tbl_names): item1 = QTableWidgetItem(row) item1.setFlags(xor(item1.flags(), Qt.ItemIsEditable)) self.IDB.TWTableNames.setItem(i, 0, item1) #self.combo[i].view().pressed.connect(self.change_col_type) self.IDB.TWTableNames.itemDoubleClicked.connect( self._change_example) self.add_to_DB_row_count = i
def addFilter(self, name, query): filt = Filter(self, name, query) currow = self.table.rowCount() self.table.setRowCount(self.table.rowCount() + 1) name = QTableWidgetItem(QString(name)) name.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.table.setItem(currow, 0, name) check = QCheckBox() check.setChecked(True) self.filters.append(filt) self.emit(SIGNAL("filterAdded")) self.table.horizontalHeader().setResizeMode( 1, QHeaderView.ResizeToContents)
def viewTableUpdate(self, id): write = int(str(self.gtable.cellWidget(id, 0).currentText()), 16) t = self.tables.tablesIdWriteMap[id][write] l = t.blockList for x in xrange(0, len(t.blockList[0])): block = t.blockList[0][x] c = ((x) % 20) r = ((x) / 20) item = QTableWidgetItem(QString(hex(block))) tipBlock = (id * 960) + x item.setToolTip(QString(hex(tipBlock))) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.vtable.setItem(r, c, item)
def populateList(self): dicts = self.manager.dictionnaries() currow = 0 for _dict in dicts.iterkeys(): self.dicos.setRowCount(currow + 1) item = QTableWidgetItem(QString.fromUtf8(dicts[_dict].fileName())) item.setFlags(Qt.ItemIsUserCheckable|Qt.ItemIsEnabled|Qt.ItemIsSelectable) item.setCheckState(Qt.Unchecked) self.dicos.setItem(currow, 0, item) name = QTableWidgetItem(QString.fromUtf8(_dict)) name.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable) self.dicos.setItem(currow, 1, name) currow += 1
def focusInEvent(self, event): self.selectAll() self.setSelection(0, len(self.title)) if hasattr(self, 'selectedItemIndex'): strText = str(self.tableWidget.item(self.selectedItemIndex, 0).text()) splittedText = strText.split('-') if len(splittedText) == 2: item = QTableWidgetItem(QString(splittedText[0] + ' '+self.text()+ ' '+ splittedText[1])) item.setFlags(Qt.ItemFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)) self.tableWidget.setItem(self.selectedItemIndex, 0, item) else: print ('Select the Sentence First')
def addFilter(self, name, query): filt = Filter(self, name, query) currow = self.table.rowCount() self.table.setRowCount(self.table.rowCount() + 1) name = QTableWidgetItem(QString(name)) name.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled) self.table.setItem(currow, 0, name) check = QCheckBox() check.setChecked(True) self.filters.append(filt) self.emit(SIGNAL("filterAdded")) self.table.horizontalHeader().setResizeMode(1, QHeaderView.ResizeToContents) self.refreshQueryEdit()
def get_columns_names(self): """A function that retrieves the name of the columns from the .csv file and returns a list with name""" self.ISD.TWColumnNames.clear() shp_file = shp.Reader(self.file_name_with_path + '.shp') f_row = True try: if len(shp_file.shapes()[0].points) > 1: self.isPolyon = True else: self.isPolyon = False except: QMessageBox.information(None, self.tr("Error:"), self.tr('No shapes was found in the file')) _types = [] for name, type_, length, precision in shp_file.fields: if f_row: f_row = False continue self.col_names.append(name) _types.append(type_) if type_ == 'N': self.col_types.append(0) if type_ == 'F': self.col_types.append(1) if type_ == 'C': self.col_types.append(2) second_row = shp_file.iterRecords().next() combo_box_options = ["Integer", "Decimal value", "Character"] self.ISD.TWColumnNames.setRowCount(len(self.col_names)) self.ISD.TWColumnNames.setColumnCount(3) self.ISD.TWColumnNames.setSelectionBehavior( QAbstractItemView.SelectRows) for i, row in enumerate(self.col_names): item1 = QTableWidgetItem(row) item1.setFlags(xor(item1.flags(), QtCore.Qt.ItemIsEditable)) item2 = QTableWidgetItem(str(second_row[i])) item2.setFlags(xor(item2.flags(), QtCore.Qt.ItemIsEditable)) self.combo.append(RadioComboBox()) for nr, t in enumerate(combo_box_options): self.combo[i].addItem(t) item = self.combo[i].model().item(nr, 0) if self.col_types[i] == nr: item.setCheckState(QtCore.Qt.Checked) self.combo[i].setCurrentIndex(nr) else: item.setCheckState(QtCore.Qt.Unchecked) self.ISD.TWColumnNames.setItem(i, 0, item1) self.ISD.TWColumnNames.setItem(i, 1, item2) self.ISD.TWColumnNames.setCellWidget(i, 2, self.combo[i]) self.add_to_DB_row_count = i
def _gotRevision(self, backend, revision): """ Callback for loadHistory's QtDo """ if not backend: # The last revision has been processed self.process = None self.ui.loadHistoryButton.setEnabled(True) self.ui.loadHistoryButton.setText("Reload") return # we set the flags to Qt.ItemIsEnabled so that the items # are not modifiable (they are modifiable by default) item_revision = QTableWidgetItem(revision.id) item_revision.setFlags(Qt.ItemIsEnabled) item_time = QTableWidgetItem(revision.timestamp.strftime('%Y-%m-%d %H:%M:%S')) item_time.setFlags(Qt.ItemIsEnabled) item_author = QTableWidgetItem(revision.author) item_author.setFlags(Qt.ItemIsEnabled) item_summary = QTableWidgetItem(revision.comment) item_summary.setFlags(Qt.ItemIsEnabled) row = self.ui.historyTable.currentRow() + 1 self.ui.historyTable.insertRow(row) self.ui.historyTable.setItem(row, 0, item_revision) self.ui.historyTable.setItem(row, 1, item_time) self.ui.historyTable.setItem(row, 2, item_author) self.ui.historyTable.setItem(row, 3, item_summary) self.ui.historyTable.setCurrentCell(row, 0)
def _gotRevision(self, backend, revision): """ Callback for loadHistory's QtDo """ if not backend: # The last revision has been processed self.process = None self.ui.loadHistoryButton.setEnabled(True) self.ui.loadHistoryButton.setText("Reload") return # we set the flags to Qt.ItemIsEnabled so that the items # are not modifiable (they are modifiable by default) item_revision = QTableWidgetItem(revision.id) item_revision.setFlags(Qt.ItemIsEnabled) item_time = QTableWidgetItem( revision.timestamp.strftime('%Y-%m-%d %H:%M:%S')) item_time.setFlags(Qt.ItemIsEnabled) item_author = QTableWidgetItem(revision.author) item_author.setFlags(Qt.ItemIsEnabled) item_summary = QTableWidgetItem(revision.comment) item_summary.setFlags(Qt.ItemIsEnabled) row = self.ui.historyTable.currentRow() + 1 self.ui.historyTable.insertRow(row) self.ui.historyTable.setItem(row, 0, item_revision) self.ui.historyTable.setItem(row, 1, item_time) self.ui.historyTable.setItem(row, 2, item_author) self.ui.historyTable.setItem(row, 3, item_summary) self.ui.historyTable.setCurrentCell(row, 0)
def add_layer(self): i = self.dlg.table.rowCount() self.dlg.table.insertRow(i) layer = QgsMapLayerComboBox() layer.setFilters(QgsMapLayerProxyModel.RasterLayer) band = QTableWidgetItem('1') band.setFlags(Qt.ItemIsEnabled) mean = QDoubleSpinBox() mean.setRange(-10000.00, 10000.00) self.dlg.table.setCellWidget(i, 0, layer) self.dlg.table.setItem(i, 1, band) self.dlg.table.setCellWidget(i, 2, mean)