def contextMenuSlot(self, qPoint): """Handles right clicks in table widget""" # HACK TO STOP REPEATED CALL TO RIGHT CLICK HANDLER if self.prevContextMenuPos == qPoint: return self.prevContextMenuPos = qPoint # END HACK # CREATE MENU SHOW_DETAILS_LABEL = "show item transaction details" SHOW_IDS_LABEL = "show IDs" SHOW_PRICE_HISTOGRAM_LABEL = "plot price histogram" popMenu = QtGui.QMenu(self) popMenu.addAction(SHOW_DETAILS_LABEL) popMenu.addAction(SHOW_IDS_LABEL) popMenu.addAction(SHOW_PRICE_HISTOGRAM_LABEL) globalPos = self.table.mapToGlobal(qPoint) action = popMenu.exec_(globalPos) if action: row = self.table.currentRow() itemName = self.table.item(row, self.ITEM_NAME_COLUMN).text() if action.text() == SHOW_DETAILS_LABEL: # REQUESTS ITEM TRANSACTION DETAILS TABLE TO BE OPENED self.emit(QtCore.SIGNAL("signal_addDetailsTable(QString)"), itemName) elif action.text() == SHOW_IDS_LABEL: # DISPLAYS ITEM ID NUMBER IN A MESSAGE BOX idNum = tradesdbmanager.getItemIdFromName(itemName) mb = QtGui.QMessageBox(self) mb.setText("itemID: {:}".format(idNum)) mb.setWindowTitle(itemName) mb.exec_() elif action.text() == SHOW_PRICE_HISTOGRAM_LABEL: self.emit(QtCore.SIGNAL("signal_addPriceHistogramWidget(QString)"), itemName)
def contextMenuSlot(self, posPoint): """ Manages right click context menu showing item and location ID numbers""" #FIRTS HACK TO PREVENT FANTOM DOUBLE RIGHT CLICK if self.prevContextMenuPos == posPoint: return self.prevContextMenuPos = posPoint itemID = tradesdbmanager.getItemIdFromName(self.itemName) cRow = self.table.currentRow(); # locationName = self.table.item(cRow, self.LOCATION_COLUMN).text() locationID = tradesdbmanager.getLocationIdFromName(locationName) # setup dialog box mb = QtGui.QMessageBox(self) mb.setWindowTitle(self.itemName) msgStr = "trading "+ self.itemName+ " at \n"+ locationName+ "\n"+ "itemID : "+ str(itemID)+"\nlocationID : "+ str(locationID) mb.setText(msgStr) mb.exec_()
def plotData(self): """Plots sale and purchase prices for this item as histogram.""" self.plot.axes.cla() self.plot.draw() self.setPlotProperties() # GET ALL SALE PRICES itemId = tradesdbmanager.getItemIdFromName(self.itemName) maxHistoryEpoch = int(time.time()) - self.toolbar.getMaxHistory()*SECONDS_PER_DAY minHistoryEpoch = int(time.time()) - self.toolbar.getMinHistory()*SECONDS_PER_DAY with sqlite3.connect(dbinfo.DATABASE_FILE_NAME) as con: cur = con.cursor() assert isinstance(cur, sqlite3.Cursor) QUERY_TEXT_SALE = """SELECT price, SUM(quantity) FROM {0} WHERE typeID = {1} AND transactionType = {2} AND transactionDateTime > {3} AND transactionDateTime < {4} GROUP BY price """.format(dbinfo.TRADE_TABLE_NAME, itemId, dbinfo.TRANSACTION_TYPE_SELL, maxHistoryEpoch, minHistoryEpoch) QUERY_TEXT_BUY = """SELECT price, SUM(quantity) FROM {0} WHERE typeID = {1} AND transactionType = {2} AND transactionDateTime > {3} AND transactionDateTime < {4} GROUP BY price """.format(dbinfo.TRADE_TABLE_NAME, itemId, dbinfo.TRANSACTION_TYPE_BUY, maxHistoryEpoch, minHistoryEpoch) sales = [] if self.toolbar.sellCB.isChecked(): cur.execute(QUERY_TEXT_SALE) sales = cur.fetchall() buys = [] if self.toolbar.buyCB.isChecked(): cur.execute(QUERY_TEXT_BUY) buys = cur.fetchall() print "sql done" numSales = len(sales) numBuys = len(buys) salePrices = np.zeros(numSales) saleCounts = np.zeros(numSales) buyPrices = np.zeros(numBuys) buyCounts = np.zeros(numBuys) c = 0 for s in sales: salePrices[c] = s[0] saleCounts[c] = s[1] c+=1 c = 0 for b in buys: buyPrices[c] = -1*b[0] buyCounts[c] = b[1] c+=1 if numSales > 0: self.plot.addPriceData(salePrices,saleCounts ,'b') if numBuys > 0: self.plot.addPriceData(buyPrices,buyCounts , 'r') self.plot.draw()