def on_AddButton_2_clicked(self): """ Now it's time to add those files we were avoiding to emiting extra signals, right? xD """ files = QFileDialog.getOpenFileNames(\ None, self.trUtf8("Select files to add to the convert queue"), self.settings.value("lastphotodir",QVariant(os.path.expanduser("~"))).toString(), QString(), None) # A cute QFileDialog asks the user for the files to convert, for both videos and images. if not files.isEmpty(): #If nothing, do nothing. try: self.settings.setValue("lastphotodir", QVariant(os.path.split(toPython(files[0]))[0])) #Remembering last used dir comes always in handy. except: print files #Debugging stuff... for file in files: currentrow = self.tableWidget_2.rowCount() self.tableWidget_2.insertRow(currentrow) filewidget = QTableWidgetItem() filewidget.setText(file) try: filewidget.setIcon(QIcon(file)) except: print "Could not load a thumbnail of the album art" outputitem = QTableWidgetItem() outputitem.setText(self.output) self.tableWidget_2.setItem(currentrow,0,filewidget) self.tableWidget_2.setItem(currentrow,1,outputitem) self.tableWidget_2.resizeColumnsToContents()
def setAsCurrentDatabase(self): if len(self.tables) == 0: self.refreshTables() self.applicationWindow.showDatabaseTab() mainWindow = self.applicationWindow.mainWindow databaseTab = mainWindow.databaseTab twMachineTabs = mainWindow.twMachineTabs twMachineTabs.setTabText(twMachineTabs.indexOf(databaseTab), "Database: %s" % self.name) twMachineTabs.setCurrentWidget(databaseTab) databaseTable = mainWindow.databaseInfoTable for i in reversed(range(databaseTable.rowCount())): databaseTable.removeRow(i) for table in self.tables: index = databaseTable.rowCount() databaseTable.insertRow(index) nameItem = QTableWidgetItem(table.name) nameItem.setIcon(QIcon('../resources/icons/table.png')) databaseTable.setItem(index, 0, nameItem) databaseTable.setItem(index, 1, QTableWidgetItem(str(table.rows))) databaseTable.setItem( index, 2, QTableWidgetItem(byteSizedStrings(table.size))) databaseTable.setItem(index, 3, QTableWidgetItem(table.getCreateTime())) databaseTable.setItem(index, 4, QTableWidgetItem(table.getUpdatedTime())) databaseTable.setItem(index, 5, QTableWidgetItem(table.engine)) databaseTable.setItem(index, 6, QTableWidgetItem(table.comment)) databaseTable.setItem(index, 7, QTableWidgetItem('table')) self.applicationWindow.tableTab.populateDefaultCollationField( self.server)
def setAsCurrentDatabase(self): if len(self.tables) == 0: self.refreshTables() self.applicationWindow.showDatabaseTab() mainWindow = self.applicationWindow.mainWindow databaseTab = mainWindow.databaseTab twMachineTabs = mainWindow.twMachineTabs twMachineTabs.setTabText(twMachineTabs.indexOf(databaseTab), "Database: %s" % self.name) twMachineTabs.setCurrentWidget(databaseTab) databaseTable = mainWindow.databaseInfoTable for i in reversed(range(databaseTable.rowCount())): databaseTable.removeRow(i) for table in self.tables: index = databaseTable.rowCount() databaseTable.insertRow(index) nameItem = QTableWidgetItem(table.name) nameItem.setIcon(QIcon('../resources/icons/table.png')) databaseTable.setItem(index, 0, nameItem) databaseTable.setItem(index, 1, QTableWidgetItem(str(table.rows))) databaseTable.setItem(index, 2, QTableWidgetItem(byteSizedStrings(table.size))) databaseTable.setItem(index, 3, QTableWidgetItem(table.getCreateTime())) databaseTable.setItem(index, 4, QTableWidgetItem(table.getUpdatedTime())) databaseTable.setItem(index, 5, QTableWidgetItem(table.engine)) databaseTable.setItem(index, 6, QTableWidgetItem(table.comment)) databaseTable.setItem(index, 7, QTableWidgetItem('table')) self.applicationWindow.tableTab.populateDefaultCollationField(self.server)
def set_data(self, data): self.setColumnCount(8) self.setRowCount(len(data)) for r, comb in enumerate(data): m = 0 # 0 <= m < 8 for n in [8, 4, 2, 1]: if comb[n] != 0: qty = QTableWidgetItem() qty.setSizeHint(QSize(100, 100)) icon = QIcon( get_absolute_path("./images/{}x.png".format(comb[n]))) qty.setIcon(icon) self.setItem(r, m, qty) block = QTableWidgetItem() block.setSizeHint(QSize(100, 100)) icon = QIcon( get_absolute_path("./images/boblo{}.png".format(n))) block.setIcon(icon) self.setItem(r, m + 1, block) m += 2 self.resizeColumnsToContents() self.resizeRowsToContents()
def place_entries(self, entries): table = self.ui.table j = -1 for h in entries: j += 1 if not '_details' in h: h['_details'] = json.loads(h['details']) if h['details'] else { "short": h['description'], "plus": "", "minus": "", "icon": None } # TODO: remove this block if not ('icon' in h['_details']): # h['_details']['icon'] = None # if not ('_icon' in h): h['_icon'] = ":/op/images/op/" + h['_details'][ 'icon'] + ".png" if h['_details']['icon'] else None description = h["_details"]["short"] or h['description'] table.insertRow(j) item = QTableWidgetItem(str(h["date"])) item.setData(99, h) table.setItem(j, 0, item) icon = qicon(h["_icon"]) item.setIcon(icon) set_col(table, j, 1, description) set_col(table, j, 2, h["_details"]["plus"], color=COLOR_GREEN, align="right") set_col(table, j, 3, h["_details"]["minus"], color=COLOR_RED, align="right") if h["memo"] > 0: icon = qicon(":/icons/images/memo.png") table.item(j, 1).setIcon(icon)
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 writeModeData(self,data): '''get data output and add on QtableWidgets ''' Headers = [] data = data.split() self.THeaders['IP Address'].append(data[0]) self.THeaders['Method'].append(data[1]) self.THeaders['Path'].append(data[2]) self.setRowCount(len(self.THeaders['Path'])) for n, key in enumerate(self.THeaders.keys()): Headers.append(key) for m, item in enumerate(self.THeaders[key]): item = QTableWidgetItem(item) if key == 'Path': item.setIcon(QIcon('icons/accept.png')) else: item.setTextAlignment(Qt.AlignVCenter | Qt.AlignCenter) self.setItem(m, n, item) self.setHorizontalHeaderLabels(self.THeaders.keys()) self.scrollToBottom()
def writeModeData(self, data): '''get data output and add on QtableWidgets ''' Headers = [] data = data.split() self.THeaders['IP Address'].append(data[0]) self.THeaders['Method'].append(data[1]) self.THeaders['Path'].append(data[2]) self.setRowCount(len(self.THeaders['Path'])) for n, key in enumerate(self.THeaders.keys()): Headers.append(key) for m, item in enumerate(self.THeaders[key]): item = QTableWidgetItem(item) if key == 'Path': item.setIcon(QIcon('icons/accept.png')) else: item.setTextAlignment(Qt.AlignVCenter | Qt.AlignCenter) self.setItem(m, n, item) self.setHorizontalHeaderLabels(self.THeaders.keys()) self.scrollToBottom()
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 updateList(self): self.setHorizontalHeaderLabels(['Kind','Timestamp','Message']) self.setColumnWidth(0,30) self.setColumnWidth(1,60) self.verticalHeader().setResizeMode(QHeaderView.ResizeToContents) self.clearContents() itemNumber = 0 for logItem in self.logModel.logItems: if logItem.level <= self.maximumLevel: # if self.rowCount <= itemNumber: self.insertRow(itemNumber) levelItem = QTableWidgetItem(log.logLevels[logItem.level]) levelItem.setIcon(self.iconForItem(logItem)) self.setItem(itemNumber,0,levelItem) self.setItem(itemNumber,1,QTableWidgetItem(logItem.timeStamp.strftime('%H:%m:%S'))) self.setItem(itemNumber,2,QTableWidgetItem(logItem.message)) itemNumber += 1 self.setRowCount(itemNumber)