def on_search(self): self.searchList.clear() text = self.searchBar.text() symbol = Utils.symbol_from_name(text) if text.upper() in Companies.get_available_symbols(): self.searchList.clear() self.searchedWid = ui_company_listing.CompanyListing(self) stock = Companies.get_stock(text) self.searchedWid.populate(stock, text.upper()) self.searchedSymbol = text elif symbol is not None: self.searchList.clear() self.searchedWid = ui_company_listing.CompanyListing(self) stock = Companies.get_stock(symbol) self.searchedWid.populate(stock, symbol) self.searchedSymbol = text else: self.searchList.clear() item = QListWidgetItem() item.setText("Company " + text + " not found.") self.searchList.addItem(item) self.searchedSymbol = None return self.searchedItem = QListWidgetItem() self.searchedItem.setSizeHint(QtCore.QSize(100, 100)) self.searchList.addItem(self.searchedItem) self.searchList.setItemWidget(self.searchedItem, self.searchedWid) self.searchList.update()
def on_select_tile(self, listWidget): self.trade_frame.hide() self.active_list_widget = listWidget item = listWidget.currentItem() if item is not None: self.active_widget = listWidget.itemWidget(item) symbol = self.active_widget.companyLabel.text() self.company_selected = symbol #print(self.company_selected) self.companyLabel.setText(self.company_selected) #turn get_company_name(symbol) into Util function self.companyFullNameLabel.setText(Companies.get_stock(self.company_selected)["companyName"]) self.priceLabel.setText("Share Price: $" + str("{:,}".format(Companies.get_stock(self.company_selected)["latestPrice"]))) self.numSharesOwnedLabel.setText("Shares Owned: " + str(pf.get_num_owned(self.company_selected))) self.trade_frame.show()
def loadQuickAccessAndCompanySearch(self): self.quickAccessList.clear() for symbol in pf.quick_access_companies: wid = ui_company_listing.CompanyListing(self) stock = Companies.get_stock(symbol) if stock is not None: wid.populate(stock, symbol) wid2 = QListWidgetItem() wid2.setSizeHint(QtCore.QSize(100, 100)) self.quickAccessList.addItem(wid2) self.quickAccessList.setItemWidget(wid2, wid)
def on_update_trade_text(self, text): if self.company_selected is None: return False try: number = int(text) except Exception: self.totalPriceLabel.setText("-") return False else: total_price = Companies.get_stock(self.company_selected)["latestPrice"] * int(text) self.totalPriceLabel.setText("$" + str("{:,}".format(total_price)))
def loadPortfolio(self): self.loggedInAsUser.setText(pf.username) self.currentBalance.setText("$" + str("{:,}".format(round(pf.num_credits, 2)))) db.update_credit(pf.username, pf.num_credits) self.loadTotalValue() for symbol, num_stock in pf.owned_stocks.items(): stock = Companies.get_stock(symbol) wid = ui_portfolioTile.PortfolioTile(self) wid.populate(stock, num_stock) wid2 = QListWidgetItem() wid2.setSizeHint(QtCore.QSize(300, 75)) self.listWidget.addItem(wid2) self.listWidget.setItemWidget(wid2, wid) stocklist = db.find_stock_of_user(pf.username) check = False for i in stocklist: if symbol == i[1]: check = True db.update_stock(pf.username, symbol, num_stock) if check == False: db.insert_stock(pf.username, symbol, num_stock)