Ejemplo n.º 1
0
    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()
Ejemplo n.º 2
0
def update(updater_thread):
    while 1:
        time.sleep(time_delta)
        Companies.update_company_information()
        update_lock.acquire()
        try:
            pf.total_value = pf.calculate_total_value()
        finally:
            update_lock.release()
Ejemplo n.º 3
0
def sell(symbol, quantity):
	global num_credits
	quantity = float(quantity)
	num_credits = float(num_credits)
	price_per = Companies.get_latest_price(symbol)
	old_num_credits = num_credits
	total_price = total_price = round(float(quantity) * float(price_per), 2)

	if symbol not in owned_stocks or quantity > owned_stocks[symbol]:
		return False, "You can't sell what you don't have"
	else:
		ret = 0
		credits_after_sell = num_credits + total_price
		if credits_after_sell < num_credits:
			return False, ''
		trade_lock.acquire()
		try:
			num_credits = credits_after_sell
			ret = remove_stock(symbol, int(quantity))
		finally:
			trade_lock.release()
			if ret:
				return True, ''
			else:
				num_credits = old_num_credits
	return False, "Error"
Ejemplo n.º 4
0
def buy(symbol, quantity):
	global num_credits
	num_credits = float(num_credits)
	quantity = float(quantity)
	price_per = Companies.get_latest_price(symbol)
	old_num_credits = num_credits
	total_price = round(float(quantity) * float(price_per), 2)

	if total_price > num_credits:
		return False, "Not enough credits."
	else:
		ret = 0
		credits_after_buy = num_credits - total_price
		if credits_after_buy < 0:
			return False, ''
		trade_lock.acquire()
		try:
			num_credits = credits_after_buy
			ret = add_stock(symbol, int(quantity))
		finally:
			trade_lock.release()
			if ret:
				return True, ''
			else:
				num_credits = old_num_credits
		return False, "Error"
Ejemplo n.º 5
0
 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()
Ejemplo n.º 6
0
def calculate_total_value():
    total_value = 0
    for symbol in owned_stocks:
        total_value += (Companies.get_latest_price(symbol) *
                        owned_stocks[symbol])
    total_value += num_credits
    return total_value
Ejemplo n.º 7
0
	def __init__(self, eventManager):

                self.EventKeyDown=6

                # initialize base class
                eventManager.addEventHandler("GameStart", self.onGameStart) #Stability
                eventManager.addEventHandler("BeginGameTurn", self.onBeginGameTurn) #Stability
                eventManager.addEventHandler("cityAcquired", self.onCityAcquired) #Stability
                eventManager.addEventHandler("cityRazed", self.onCityRazed) #Stability
                eventManager.addEventHandler("cityBuilt", self.onCityBuilt) #Stability
                eventManager.addEventHandler("combatResult", self.onCombatResult) #Stability
                eventManager.addEventHandler("changeWar", self.onChangeWar)
                eventManager.addEventHandler("religionFounded",self.onReligionFounded) #Victory
                eventManager.addEventHandler("buildingBuilt",self.onBuildingBuilt) #Victory
                eventManager.addEventHandler("projectBuilt",self.onProjectBuilt) #Victory
                eventManager.addEventHandler("BeginPlayerTurn", self.onBeginPlayerTurn)
                eventManager.addEventHandler("kbdEvent",self.onKbdEvent)
                eventManager.addEventHandler("OnLoad",self.onLoadGame) #edead: StoredData
                eventManager.addEventHandler("techAcquired",self.onTechAcquired) #Stability
                eventManager.addEventHandler("religionSpread",self.onReligionSpread) #Stability
                eventManager.addEventHandler("firstContact",self.onFirstContact)
                eventManager.addEventHandler("OnPreSave",self.onPreSave) #edead: StoredData
		eventManager.addEventHandler("vassalState", self.onVassalState)
		eventManager.addEventHandler("revolution", self.onRevolution)
		eventManager.addEventHandler("cityGrowth", self.onCityGrowth)
		eventManager.addEventHandler("unitPillage", self.onUnitPillage)
		eventManager.addEventHandler("cityCaptureGold", self.onCityCaptureGold)
		eventManager.addEventHandler("playerGoldTrade", self.onPlayerGoldTrade)
		eventManager.addEventHandler("tradeMission", self.onTradeMission)
		eventManager.addEventHandler("playerSlaveTrade", self.onPlayerSlaveTrade)
		eventManager.addEventHandler("playerChangeStateReligion", self.onPlayerChangeStateReligion)
		                
		#Leoreth
		eventManager.addEventHandler("greatPersonBorn", self.onGreatPersonBorn)
		eventManager.addEventHandler("unitCreated", self.onUnitCreated)
		eventManager.addEventHandler("unitBuilt", self.onUnitBuilt)
		eventManager.addEventHandler("plotFeatureRemoved", self.onPlotFeatureRemoved)
		eventManager.addEventHandler("goldenAge", self.onGoldenAge)
		eventManager.addEventHandler("releasedPlayer", self.onReleasedPlayer)
		eventManager.addEventHandler("cityAcquiredAndKept", self.onCityAcquiredAndKept)
		eventManager.addEventHandler("blockade", self.onBlockade)
		eventManager.addEventHandler("peaceBrokered", self.onPeaceBrokered)
               
                self.eventManager = eventManager

                self.rnf = RiseAndFall.RiseAndFall()
                self.barb = Barbs.Barbs()
                self.rel = Religions.Religions()
                self.res = Resources.Resources()
                self.up = UniquePowers.UniquePowers()
                self.aiw = AIWars.AIWars()
                self.pla = Plague.Plague()
                self.com = Communications.Communications()
                self.corp = Companies.Companies()

		self.dc = DynamicCivs.DynamicCivs()
Ejemplo n.º 8
0
    def __init__(self, eventManager):

        self.lastRegionID = -1
        self.bStabilityOverlay = False
        self.EventKeyDown = 6
        self.EventKeyUp = 7
        self.eventManager = eventManager

        # initialize base class
        eventManager.addEventHandler("GameStart", self.onGameStart)
        eventManager.addEventHandler("OnLoad", self.onLoadGame)
        eventManager.addEventHandler("OnPreSave", self.onPreSave)
        eventManager.addEventHandler("BeginGameTurn", self.onBeginGameTurn)
        eventManager.addEventHandler("EndGameTurn", self.onEndGameTurn)
        eventManager.addEventHandler("BeginPlayerTurn", self.onBeginPlayerTurn)
        eventManager.addEventHandler("EndPlayerTurn", self.onEndPlayerTurn)
        eventManager.addEventHandler("firstContact", self.onFirstContact)
        eventManager.addEventHandler("cityAcquired", self.onCityAcquired)
        eventManager.addEventHandler("goldenAge", self.onGoldenAge)  # srpt
        eventManager.addEventHandler("corporationSpread",
                                     self.onCorporationSpread)  # srpt
        eventManager.addEventHandler("cityAcquiredAndKept",
                                     self.onCityAcquiredAndKept)
        eventManager.addEventHandler("cityRazed", self.onCityRazed)
        eventManager.addEventHandler("cityBuilt", self.onCityBuilt)
        eventManager.addEventHandler("combatResult", self.onCombatResult)
        eventManager.addEventHandler("buildingBuilt", self.onBuildingBuilt)
        eventManager.addEventHandler("projectBuilt", self.onProjectBuilt)
        eventManager.addEventHandler("techAcquired", self.onTechAcquired)
        eventManager.addEventHandler("religionSpread", self.onReligionSpread)
        eventManager.addEventHandler("unitSpreadReligionAttempt",
                                     self.onUnitSpreadReligionAttempt)
        eventManager.addEventHandler("playerChangeStateReligion",
                                     self.onPlayerChangeStateReligion)
        eventManager.addEventHandler("vassalState", self.onVassalState)
        eventManager.addEventHandler("changeWar", self.onChangeWar)
        eventManager.addEventHandler("unitBuilt", self.onUnitBuilt)
        eventManager.addEventHandler("revolution", self.onRevolution)
        eventManager.addEventHandler("setPlayerAlive", self.onSetPlayerAlive)
        eventManager.addEventHandler("greatPersonBorn", self.onGreatPersonBorn)
        eventManager.addEventHandler("kbdEvent", self.onKbdEvent)

        self.rnf = RiseAndFall.RiseAndFall()
        self.cnm = CityNameManager.CityNameManager()
        self.res = Resources.Resources()
        self.rel = Religions.Religions()
        self.barb = Barbs.Barbs()
        self.aiw = AIWars.AIWars()
        self.vic = Victory.Victory()
        #self.pla = Plague.Plague()
        self.com = Communications.Communications()
        self.dc = DynamicCivs.DynamicCivs()
        self.corp = Companies.Companies()
        self.rfccwaiw = RFCCWAIWars.RFCCWAIWars()
Ejemplo n.º 9
0
 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)
Ejemplo n.º 10
0
 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)))
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
        self.ui.exec_()

    def perform_send_message(self):
        user = self.ui.userEdit.text()
        email = self.ui.emailEdit.text()
        subject = self.ui.subjectEdit.text()
        message = self.ui.messageEdit.text()
        print(user+'\n'+email+'\n'+subject+'\n'+message)
        ej.sendMessage(user, email, subject, message)        
               
if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    login = Login_UI()
    if login.exec_() == QtWidgets.QDialog.Accepted:
        mainApp = MainApp()
        mainApp.setWindowIcon(QtGui.QIcon('res/icon.png'))
        mainApp.show()
        
        try:
            Companies.update_company_information()
        except:
            QMessageBox.about(mainApp, "No Connection", "You must be connected to the Internet in order to get accurate data.")
        
        #This will continuously pull from the API and push all the data into the cache
        updater = UpdaterThread.UpdaterThread(1, "updater")
        updater.daemon = True
        updater.start()

        ret = app.exec_()
        sys.exit(ret)