def setCurrentItemSettings(self, row): itemID = self.getSelectedItemId(row) system = self.systemLineEdit.text() systemID = self.mydb.getSystemIDbyName(system) station = self.stationLineEdit.text() stationID = self.mydb.getStationID(systemID, station) if not stationID: return price = self.mydb.getFullPriceData( stationID, itemID) if price: #print(price.keys()) self.tableWidget.item(row, self.headerList.index("Sell")).setText( str(price['StationBuy']) ) self.tableWidget.item(row, self.headerList.index("Buy")).setText( str(price['StationSell']) ) self.tableWidget.item(row, self.headerList.index("Stock")).setText( str(price['Stock']) ) checkBox = guitools.getChildByType(self.tableWidget.cellWidget(row, self.headerList.index("Blackmarket")), QtGui.QCheckBox) if checkBox: if price['blackmarket']: checkBox.setChecked(True) else: checkBox.setChecked(False) checkBox = guitools.getChildByType(self.tableWidget.cellWidget(row, self.headerList.index("Ignore")), QtGui.QCheckBox) if checkBox: if price['ignore']: checkBox.setChecked(True) else: checkBox.setChecked(False) checkBox = guitools.getChildByType(self.tableWidget.cellWidget(row, self.headerList.index("Fake")), QtGui.QCheckBox) if checkBox: if price['fake']: checkBox.setChecked(True) else: checkBox.setChecked(False) else: ''' no price? reset all fields''' self.tableWidget.item(row, self.headerList.index("Sell")).setText( "0" ) self.tableWidget.item(row, self.headerList.index("Buy")).setText( "0" ) self.tableWidget.item(row, self.headerList.index("Stock")).setText( "0" ) checkBox = guitools.getChildByType(self.tableWidget.cellWidget(row, self.headerList.index("Blackmarket")), QtGui.QCheckBox) checkBox.setChecked(False) checkBox = guitools.getChildByType(self.tableWidget.cellWidget(row, self.headerList.index("Ignore")), QtGui.QCheckBox) checkBox.setChecked(False) checkBox = guitools.getChildByType(self.tableWidget.cellWidget(row, self.headerList.index("Fake")), QtGui.QCheckBox) checkBox.setChecked(False)
def saveItems(self): self.parent.lockDB() failColor = QtGui.QColor(255, 0, 0, 180) system = self.systemLineEdit.text() systemID = self.mydb.getSystemIDbyName(system) station = self.stationLineEdit.text() stationID = self.mydb.getStationID(systemID, station) if not stationID: self.parent.unlockDB() return cur = self.mydb.cursor() modifiedDate = datetime.utcnow() for row in range(0, self.tableWidget.rowCount()): itemID = self.getSelectedItemId(row) stationBuy = self.tableWidget.item(row, self.headerList.index("Sell")).text() stationSell = self.tableWidget.item(row, self.headerList.index("Buy")).text() stock = self.tableWidget.item(row, self.headerList.index("Stock")).text() if not itemID or not guitools.isInt( stationBuy ) or not guitools.isInt( stationSell ) or not guitools.isInt( stock ): #print("fail", stationBuy, stationSell, stock) if not guitools.isInt( stationBuy ): self.tableWidget.item(row, self.headerList.index("Sell")).setBackground( failColor ) if not guitools.isInt( stationSell ): self.tableWidget.item(row, self.headerList.index("Buy")).setBackground( failColor ) if not guitools.isInt( stock ): self.tableWidget.item(row, self.headerList.index("Stock")).setBackground( failColor ) self.tableWidget.dataChanged(self.tableWidget.indexFromItem(self.tableWidget.item(row, 0)), self.tableWidget.indexFromItem(self.tableWidget.item(row, len(self.headerList)))) msg = "Save Fail" msgBox = QtGui.QMessageBox(QtGui.QMessageBox.Information, "Error", msg, QtGui.QMessageBox.NoButton, self) msgBox.exec_() self.parent.unlockDB() return else: cur.execute( "UPDATE price SET StationBuy=?, StationSell=?, Stock=?, modified=?, source=6 where StationID=? AND ItemID=?", (stationBuy, stationSell, stock, modifiedDate, stationID, itemID)) if cur.rowcount <= 0: print("no update, insert") cur.execute("insert or IGNORE into price (SystemID, StationID, ItemID, StationBuy, StationSell, Stock, modified, source) values (?,?,?,?,?,?,?,6) ", (systemID, stationID, itemID, stationBuy, stationSell, stock, modifiedDate)) cur.execute("select id from price where StationID = ? AND ItemID = ? limit 1", ( stationID, itemID)) priceID = cur.fetchone()[0] ''' blackmarket ''' blackmarkedCheckBox = guitools.getChildByType(self.tableWidget.cellWidget(row, self.headerList.index("Blackmarket")), QtGui.QCheckBox) if blackmarkedCheckBox.isChecked(): self.mydb.setBlackmarketPrice(priceID) else: self.mydb.removeBlackmarketPrice(priceID) ''' ignore ''' ignoreCheckBox = guitools.getChildByType(self.tableWidget.cellWidget(row, self.headerList.index("Ignore")), QtGui.QCheckBox) if ignoreCheckBox.isChecked(): self.mydb.setIgnorePriceTemp(priceID) else: self.mydb.removeIgnorePrice(priceID) ''' fake ''' fakeCheckBox = guitools.getChildByType(self.tableWidget.cellWidget(row, self.headerList.index("Fake")), QtGui.QCheckBox) if fakeCheckBox.isChecked(): self.mydb.setFakePrice(priceID) else: self.mydb.removeFakePrice(priceID) self.mydb.addSystemsInDistanceToDealsInDistancesCacheQueue(systemID, itemID) self.mydb.addSystemToDealsInDistancesCacheQueue( [{'id': systemID}] ) self.mydb.con.commit() cur.close() self.parent.unlockDB()