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 populate_usrn_table(self, esu_id): """ Populate the esu_id selector table widget with all linked usrn's :param esu_id: ESU ID """ street_records = self.query_for_usrn(esu_id) if street_records: # Set esu_id label text esu_label = self.street_sel_dlg.ui.esuLabel esu_label.setText(str("ESU: " + str(esu_id))) table_widget = self.street_sel_dlg.ui.usrnTableWidget # Clear table self.reset_table(table_widget) row_count = table_widget.rowCount() # loop to populate records for record in street_records: col = 0 table_widget.insertRow(row_count) for item in record: t_item = QTableWidgetItem() t_item.setText(str(item)) item_color = QColor(213, 234, 234) t_item.setBackgroundColor(item_color) t_item.setSelected(True) self.street_sel_dlg.ui.usrnTableWidget.setItem( row_count, col, t_item) col += 1 row_count += 1 table_widget.selectRow(0) self.street_sel_dlg.exec_() else: pass
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 _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 changeHabColor(self): currRow = self.habTableWidget.currentRow() color_item = QTableWidgetItem() new_qcolor = QColorDialog.getColor(parent=self) if new_qcolor.isValid(): color_item.setBackgroundColor(new_qcolor) color_item.setText(new_qcolor.name()) self.habTableWidget.setItem(currRow, 2, color_item)
def changeHabColor(self): currRow = self.habTableWidget.currentRow() color_item = QTableWidgetItem() new_qcolor = QColorDialog.getColor(parent=self) if new_qcolor.isValid(): color_item.setBackgroundColor( new_qcolor ) color_item.setText( new_qcolor.name() ) self.habTableWidget.setItem(currRow,2,color_item)
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 addToTableWidget(self, widget, rownum): self.setCode() self.setColor() itemlist = [self.code, self.name, self.color] #print itemlist for i, thing in enumerate(itemlist): item = QTableWidgetItem(str(thing)) if i == len(itemlist) - 1: item.setBackgroundColor(self.q_color) #print "Adding %s to row %i" % (item.text(),rownum) widget.setItem(rownum, i, item)
def addToTableWidget(self,widget,rownum): self.setCode() self.setColor() itemlist = [self.code,self.name,self.color] #print itemlist for i,thing in enumerate(itemlist): item = QTableWidgetItem( str(thing) ) if i==len(itemlist)-1: item.setBackgroundColor( self.q_color ) #print "Adding %s to row %i" % (item.text(),rownum) widget.setItem(rownum,i,item)
def fillHeader(self, row, chain): item = chain.createTableWidgetItem() self.table.setSpan(row, 0, 1, 3) self.table.setItem(row, 0, item) item = QTableWidgetItem() unsetFlag(item, Qt.ItemIsEditable) item.setText(tr("Translated to")) item.setTextAlignment(Qt.AlignHCenter) item.setBackgroundColor(DECISION_COLORS['ACCEPT']) self.table.setSpan(row, 4, 1, 3) self.table.setItem(row, 4, item)
def update_ui(console_instance): try: c = QColor("darkgray") b = console_instance.all_ball_needToBetList row = console_instance.viewEntry.rowCount() for k in range(len(b)): if console_instance.isLoseAdd == '0': # 输追加 if b[k][2] == 0: newItem = QTableWidgetItem(u'中') newItem.setBackgroundColor(c) newItem.setTextColor(QColor(255, 0, 0, 127)) else: newItem = QTableWidgetItem(u'不中') newItem.setBackgroundColor(c) else: if b[k][2] == 0: newItem = QTableWidgetItem(u'不中') newItem.setBackgroundColor(c) else: newItem = QTableWidgetItem(u'中') newItem.setBackgroundColor(c) newItem.setTextColor(QColor(255, 0, 0, 127)) console_instance.viewEntry.setItem(row - len(b) + k, 6, newItem) logging.info(u"load data2 finish 结算完毕。。。") except Exception, ex: logging.error(ex, exc_info=1)
def createAttributeItems(self, fullTableName, currentDict, qmlDict, count, colour = None): """ Creates a QTableWidgetItem for each attribute. The cell can have different types according to the data type used (i.e QCombobox, QLineEdit or QListWidget) """ if fullTableName in currentDict.keys(): for attr in currentDict[fullTableName]: self.attributeTableWidget.insertRow(count) item = QTableWidgetItem() item.setText(attr) if colour: item.setBackgroundColor(colour) self.attributeTableWidget.setItem(count, 0, item) #creating the specific cell widget. It can be a QCombobox, a QLineEdit or a QListWidget self.createCellWidget(qmlDict, attr, count) count+=1
def __init__(self, layer, parent=None): super(LayerColortableDialog, self).__init__(parent=parent) h = QHBoxLayout(self) t = QTableWidget(self) t.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) t.setRowCount(len(layer._colorTable)) t.setColumnCount(1) t.setVerticalHeaderLabels(["%d" %i for i in range(len(layer._colorTable))]) for i in range(len(layer._colorTable)): item = QTableWidgetItem(" ") t.setItem(i,0, item); item.setBackgroundColor(QColor.fromRgba(layer._colorTable[i])) item.setFlags(Qt.ItemIsSelectable) h.addWidget(t)
def __init__(self, layer, parent=None): super(LayerColortableDialog, self).__init__(parent=parent) h = QHBoxLayout(self) t = QTableWidget(self) t.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) t.setRowCount(len(layer._colorTable)) t.setColumnCount(1) t.setVerticalHeaderLabels(["%d" %i for i in range(len(layer._colorTable))]) for i in range(len(layer._colorTable)): item = QTableWidgetItem(" ") t.setItem(i,0, item); item.setBackgroundColor(QColor.fromRgba(layer._colorTable[i])) item.setFlags(Qt.ItemIsSelectable) h.addWidget(t)
def read_file(self, name): label = os.path.basename(name) idx = self.ui.compareList.rowCount() color = self._refl_color_list[idx % len(self._refl_color_list)] self.changing_table = True self.ui.compareList.setRowCount(idx + 1) item = QTableWidgetItem(label) item.setFlags(Qt.ItemIsEnabled) try: plotlabel = label.split("REF_M_", 1)[1] plotlabel = plotlabel.split("_Specular")[0] + " " + plotlabel.split("Specular_")[1].split(".")[0] except: plotlabel = label self.ui.compareList.setItem(idx, 0, item) item = QTableWidgetItem(color) item.setBackgroundColor(QColor(color)) item.setTextColor(QColor("#ffffff")) item.setFlags(Qt.ItemIsEnabled) self.ui.compareList.setItem(idx, 1, item) self.ui.compareList.setItem(idx, 2, QTableWidgetItem(plotlabel)) self.file_paths[label] = os.path.abspath(name) self.changing_table = False
def load_table(self, files): self._files = files r = 0 for file in files: self._table.insertRow(r) if len(file['name']) > 0: item = QTableWidgetItem(file['name']) else: item = QTableWidgetItem(file['file-name']) item.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled ) self._table.setItem(r, 1, item) item = QTableWidgetItem(str(file['file-size'] / 1024) + ' kb') item.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled ) self._table.setItem(r, 2, item) imageFile = config.type.get(file['type'], config.typeBlank) access = config.access[file['accesibility']] item = QTableWidgetItem(QIcon(imageFile), access[3]) item.setBackgroundColor(QColor(access[0], access[1], access[2])) item.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled ) self._table.setItem(r, 0, item) r += 1 self._table.resizeRowsToContents() self._table.resizeColumnsToContents() self._table.horizontalHeader().setStretchLastSection(True)
def refresh(self, dateSE, timeSE): if not self.sqlconn: self.sqlconn = sqlite3.connect(dbfile) self.curs = self.sqlconn.cursor() if not self.sqlconn or not self.curs: return ttype = "amounts_in" if str(self.parent.comboTrafType) == '0' else "amounts_out" q = "SELECT date,hour,amount FROM '{}' WHERE date > '{}'" q+= " AND date < '{}' AND hour > '{}' AND hour < '{}'" q = q.format(ttype, dateSE[0], dateSE[1], timeSE[0], timeSE[1]) self.curs.execute(q) #print("debug", ttype, q) irow = 1 fullsum = 0 self.myclear() for row in self.curs: self.setRowCount(irow + 1) fullsum += row[2] d = QTableWidgetItem(str(row[0])) h = QTableWidgetItem("{:02}:00".format(row[1])) s = QTableWidgetItem(self.parent.comboTrafSize.calc(row[2])) i = self.parent.comboTrafType.items[int(str(self.parent.comboTrafType))][1] s.setIcon(QtGui.QIcon(join(ipath, i))) if not irow % 2 == 0: d.setBackgroundColor(self.backcolor) h.setBackgroundColor(self.backcolor) s.setBackgroundColor(self.backcolor) self.setItem(irow, 0, d) self.setItem(irow, 1, h) self.setItem(irow, 2, s) irow += 1 s = QTableWidgetItem("Итого:") s.setTextAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.setItem(0, 1, s) s = QTableWidgetItem(self.parent.comboTrafSize.calc(fullsum)) s.setForeground(QtGui.QBrush(QtGui.QColor(244, 0, 0))) self.setItem(0, 2, s)
def _actualizarGantt(self): self.tablaGantt.insertColumn(self.columna) for i in range(len(self.contenedor)): item = QTableWidgetItem() if self.contenedor[i].ejecutando(): if isinstance(self.contenedor, MulticolasRetro): if self.contenedor[i].prioridad == 1: item.setBackgroundColor(QColor(0,128,0)) elif self.contenedor[i].prioridad == 2: item.setBackgroundColor(QColor(0,255,0)) elif self.contenedor[i].prioridad == 3: item.setBackgroundColor(QColor(128,255,128)) else: item.setBackgroundColor(Qt.green) elif self.contenedor[i].listo(): if isinstance(self.contenedor, MulticolasRetro): if self.contenedor[i].prioridad == 1: item.setBackgroundColor(QColor(128,0,0)) elif self.contenedor[i].prioridad == 2: item.setBackgroundColor(QColor(255,0,0)) elif self.contenedor[i].prioridad == 3: item.setBackgroundColor(QColor(255,128,128)) else: item.setBackgroundColor(Qt.red) elif self.contenedor[i].bloqueado(): item.setBackgroundColor(Qt.blue) self.tablaGantt.setItem(i, self.columna, item) self.columna += 1 self.tablaGantt.resizeColumnsToContents()