def updateTable(self, args): cell_color, font_color = self.setTableColor(args[4]) j = 0 for data in args: item = QTableWidgetItem(data) self.table.setItem(self.i, j, item) item.setBackground(cell_color) item.setForeground(font_color) j += 1 self.i += 1
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 set_col(table, row, col, val, fmt=None, color=None, align=None, editable=None, data=None): item = QTableWidgetItem(fmt % val if fmt else str(val)) if color: item.setForeground(QtGui.QColor(color)) if align=="right": item.setTextAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) if align=="center": item.setTextAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter) if not(editable is None): if editable: item.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable) else: item.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) if data: item.setData(99, data) table.setItem(row, col, item) return item
def on_messageTable_clicked(self, index): """ Displays the message keys and values. @param index QModelIndex instance; filterModel index, not messageModel. @return None """ firstIndex = index.sibling(index.row(), 0) messageIndex, validIndex = firstIndex.data().toInt() messageTime, message = self.messagesModel.message(messageIndex) messageDetail = self.messageDetail messageDetail.clearContents() typeName = message.typeName itemBrush = QBrush(self.brushMap[typeName]) items = [('index', messageIndex), ('type', typeName), ('received', ctime(messageTime))] + list( sorted(message.items())) messageDetail.setRowCount(len(items)) for row, pair in enumerate(items): for col, text in enumerate(pair): item = QTableWidgetItem(str(text)) item.setForeground(itemBrush) messageDetail.setItem(row, col, item)
def load_movies_run(self, filepaths): renaming_rule = utils.preferences.value("renaming_rule").toString() # loop on file paths for filepath in filepaths: # set loading label text, show current file name self.ui.label_loading.setText(QApplication.translate('GUI', "Getting information from ")\ + os.path.split(filepath)[1]) # create a new movie object movie = Movie(filepath) # generate new movie name based on renaming rule movie.generate_new_name(renaming_rule) # add movie to list self.movies.append(movie) # insert a new row in movie table self.ui.table_movies.insertRow(self.ui.table_movies.rowCount()) # create a table item with original movie file name item_original_name = QTableWidgetItem(movie.original_file_name()) item_original_name.setForeground(QBrush(Qt.black)) self.ui.table_movies.setItem(self.ui.table_movies.rowCount() - 1, 0, item_original_name) # create a table item with new movie file name item_new_name = QTableWidgetItem(movie.new_file_name()) item_new_name.setForeground(QBrush(Qt.black)) self.ui.table_movies.setItem(self.ui.table_movies.rowCount() - 1, 1, item_new_name) self.load_movies_finished.emit()
def on_messageTable_clicked(self, index): """ Displays the message keys and values. @param index QModelIndex instance; filterModel index, not messageModel. @return None """ firstIndex = index.sibling(index.row(), 0) messageIndex, validIndex = firstIndex.data().toInt() messageTime, message = self.messagesModel.message(messageIndex) messageDetail = self.messageDetail messageDetail.clearContents() typeName = message.typeName itemBrush = QBrush(self.brushMap[typeName]) items = [ ('index', messageIndex), ('type', typeName), ('received', ctime(messageTime)) ] + list(sorted(message.items())) messageDetail.setRowCount(len(items)) for row, pair in enumerate(items): for col, text in enumerate(pair): item = QTableWidgetItem(str(text)) item.setForeground(itemBrush) messageDetail.setItem(row, col, item)
def addAutoFieldToAutoFieldsTable(self, autoFieldId, autoField, freezeSorting=True): """ Add a whole row to the AutoFields table """ if self.chkOnlyEnabledAutoFields.isChecked( ) and not autoField['enabled']: return if freezeSorting: self.tblAutoFields.setSortingEnabled(False) row = self.tblAutoFields.rowCount() self.tblAutoFields.insertRow(row) name = autoField['layer'] if 'layerId' in autoField: lyr = QgsMapLayerRegistry.instance().mapLayer(autoField['layerId']) name = lyr.name() item = QTableWidgetItem(name) item.setData(Qt.UserRole, autoFieldId) item.setData(Qt.ToolTipRole, autoField['layer']) if not autoField['enabled']: item.setForeground(QBrush(Qt.gray)) self.tblAutoFields.setItem(row, 0, item) item = QTableWidgetItem(autoField['field']) if not autoField['enabled']: item.setForeground(QBrush(Qt.gray)) self.tblAutoFields.setItem(row, 1, item) item = QTableWidgetItem(autoField['expression']) if not autoField['enabled']: item.setForeground(QBrush(Qt.gray)) self.tblAutoFields.setItem(row, 2, item) item = QTableWidgetItem( QApplication.translate("AutoFieldsDockWidgetPy", "Enabled" ) if autoField['enabled'] else QApplication. translate("AutoFieldsDockWidgetPy", "Disabled")) item.setData(Qt.UserRole, 'enabled' if autoField['enabled'] else 'disabled') if not autoField['enabled']: item.setForeground(QBrush(Qt.gray)) self.tblAutoFields.setItem(row, 3, item) if freezeSorting: self.tblAutoFields.setSortingEnabled(True)
def addAutoFieldToAutoFieldsTable( self, autoFieldId, autoField, freezeSorting=True ): """ Add a whole row to the AutoFields table """ if self.chkOnlyEnabledAutoFields.isChecked() and not autoField['enabled']: return if freezeSorting: self.tblAutoFields.setSortingEnabled( False ) row = self.tblAutoFields.rowCount() self.tblAutoFields.insertRow( row ) name = autoField['layer'] if 'layerId' in autoField: lyr = QgsMapLayerRegistry.instance().mapLayer( autoField['layerId'] ) name = lyr.name() item = QTableWidgetItem( name ) item.setData( Qt.UserRole, autoFieldId ) item.setData( Qt.ToolTipRole, autoField['layer'] ) if not autoField['enabled']: item.setForeground( QBrush( Qt.gray ) ) self.tblAutoFields.setItem( row, 0, item ) item = QTableWidgetItem( autoField['field'] ) if not autoField['enabled']: item.setForeground( QBrush( Qt.gray ) ) self.tblAutoFields.setItem( row, 1, item ) item = QTableWidgetItem( autoField['expression'] ) if not autoField['enabled']: item.setForeground( QBrush( Qt.gray ) ) self.tblAutoFields.setItem( row, 2, item ) item = QTableWidgetItem( QApplication.translate( "AutoFieldsDockWidgetPy", "Enabled" ) if autoField['enabled'] else QApplication.translate( "AutoFieldsDockWidgetPy", "Disabled" ) ) item.setData( Qt.UserRole, 'enabled' if autoField['enabled'] else 'disabled' ) if not autoField['enabled']: item.setForeground( QBrush( Qt.gray ) ) self.tblAutoFields.setItem( row, 3, item ) if freezeSorting: self.tblAutoFields.setSortingEnabled( True )