Esempio n. 1
0
	def __init__(self):
		self.state = STATE_UNKNOWN
		self.statechange_callback = None

		try:
			# get an event loop
			loop = DBusGMainLoop()

			# get the NetworkManager object from D-Bus
			invest.debug("Connecting to Network Manager via D-Bus")
			bus = dbus.SystemBus(mainloop=loop)
			nmobj = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager')
			nm = dbus.Interface(nmobj, 'org.freedesktop.NetworkManager')

			# connect the signal handler to the bus
			bus.add_signal_receiver(self.handler, None,
					'org.freedesktop.NetworkManager',
					'org.freedesktop.NetworkManager',
					'/org/freedesktop/NetworkManager')

			# get the current status of the network manager
			self.state = nm.state()
			invest.debug("Current Network Manager status is %d" % self.state)
		except Exception, msg:
			invest.error("Could not connect to the Network Manager: %s" % msg )
Esempio n. 2
0
	def on_index_quote_retriever_completed(self, retriever, index):
		if retriever.retrieved == False:
			invest.error("Failed to retrieve quotes for index %s!" % index)
		else:
			self.save_index_quotes(index, retriever.data)
			self.load_index_quotes(index)
			self.retrieve_currencies()
Esempio n. 3
0
	def on_currency_retriever_completed(self, retriever):
		if retriever.retrieved == False:
			invest.error("Failed to retrieve currency rates!")
		else:
			self.save_currencies(retriever.data)
			self.load_currencies()
		self.update_tooltip()
Esempio n. 4
0
	def show_run_hide(self, explanation = ""):
		expl = self.ui.get_object("explanation")
		expl.set_markup(explanation)
		self.dialog.show_all()
		if explanation == "":
			expl.hide()
		self.dialog.run()
		self.dialog.destroy()

		invest.STOCKS = {}

		def save_symbol(model, path, iter):
			#if int(model[iter][1]) == 0 or float(model[iter][2]) < 0.0001:
			#	return

			if not model[iter][0] in invest.STOCKS:
				invest.STOCKS[model[iter][0]] = { 'label': model[iter][1], 'purchases': [] }
				
			invest.STOCKS[model[iter][0]]["purchases"].append({
				"amount": float(model[iter][2]),
				"bought": float(model[iter][3]),
				"comission": float(model[iter][4]),
			})
		self.model.foreach(save_symbol)
		try:
			cPickle.dump(invest.STOCKS, file(invest.STOCKS_FILE, 'w'))
			invest.debug('Stocks written to file')
		except Exception, msg:
			invest.error('Could not save stocks file: %s' % msg)
Esempio n. 5
0
	def save_currencies(self, data):
		invest.debug("Storing currencies to %s" % invest.CURRENCIES_FILE)
		try:
			f = open(invest.CURRENCIES_FILE, 'w')
			f.write(data)
			f.close()
		except Exception, msg:
			invest.error("Could not save the retrieved currencies to %s: %s" % (invest.CURRENCIES_FILE, msg) )
Esempio n. 6
0
	def save_quotes(self, data):
		invest.debug("Storing quotes")
		try:
			f = open(invest.QUOTES_FILE, 'w')
			f.write(data)
			f.close()
		except Exception, msg:
			invest.error("Could not save the retrieved quotes file to %s: %s" % (invest.QUOTES_FILE, msg) )
Esempio n. 7
0
	def set_color(self, color, opacity=0xFF):
		if self.pixbuf != None:
			try:
				color = Pango.Color(color)
				factor = float(0xFF)/0xFFFF
				self.pixbuf.fill(
					int(color.red*factor)<<24|int(color.green*factor)<<16|int(color.blue*factor)<<8|opacity)
				self.set_from_pixbuf(self.pixbuf)
			except Exception, msg:
				invest.error("Could not set color: %s" % msg)
Esempio n. 8
0
	def load_currencies(self):
		invest.debug("Loading currencies from %s" % invest.CURRENCIES_FILE)
		try:
			f = open(invest.CURRENCIES_FILE, 'r')
			data = f.readlines()
			f.close()

			self.convert_currencies(self.parse_yahoo_csv(csv.reader(data)))
		except Exception, msg:
			invest.error("Could not load the currencies from %s: %s" % (invest.CURRENCIES_FILE, msg) )
Esempio n. 9
0
	def load_index_quotes(self, index):
		# load the file
		try:
			filename = invest.INDEX_QUOTES_FILE_TEMPLATE.replace('#', index)
			filename = join(invest.USER_INVEST_DIR, filename)
			f = open(filename, 'r')
			data = f.readlines()
			f.close()
		except Exception, msg:
			invest.error("Could not load index quotes file %s of index %s: %s" % (filename, index, msg) )
			return
Esempio n. 10
0
 def set_color(self, color, opacity=0xFF):
     if self.pixbuf != None:
         try:
             color = pango.Color(color)
             factor = float(0xFF) / 0xFFFF
             self.pixbuf.fill(
                 int(color.red * factor) << 24
                 | int(color.green * factor) << 16
                 | int(color.blue * factor) << 8 | opacity)
             self.set_from_pixbuf(self.pixbuf)
         except Exception, msg:
             invest.error("Could not set color: %s" % msg)
Esempio n. 11
0
	def save_index_quotes(self, index, data):
		# store the index quotes
		invest.debug("Storing quotes of index %s" % index)
		try:
			filename = invest.INDEX_QUOTES_FILE_TEMPLATE.replace('#', index)
			filename = join(invest.USER_INVEST_DIR, filename)
			f = open(filename, 'w')
			f.write(data)
			f.close()
		except Exception, msg:
			invest.error("Could not save the retrieved index quotes file of %s to %s: %s" % (index, filename, msg) )
			return
Esempio n. 12
0
	def load_quotes(self):
		invest.debug("Loading quotes");
		try:
			f = open(invest.QUOTES_FILE, 'r')
			data = f.readlines()
			f.close()

			self.populate(self.parse_yahoo_csv(csv.reader(data)))
			self.updated = True
			self.last_updated = datetime.datetime.fromtimestamp(getmtime(invest.QUOTES_FILE))
			self.update_tooltip()
		except Exception, msg:
			invest.error("Could not load the cached quotes file %s: %s" % (invest.QUOTES_FILE, msg) )
Esempio n. 13
0
	def on_cell_edited(self, cell, path, new_text, col, typ):
		if col != 0 and self.is_group(self.model.get_iter(path)):
			return

		try:
			if col == 0 and self.is_stock(self.model.get_iter(path)):    # stock symbols must be uppercase
				new_text = str.upper(new_text)
			if col < 2:
				self.model[path][col] = new_text
			else:
				value = locale.atof(new_text)
				self.model[path][col] = value
		except Exception, msg:
			invest.error('Exception while processing cell change: %s' % msg)
			pass
Esempio n. 14
0
	def show_run_hide(self, explanation = ""):
		expl = self.ui.get_object("explanation")
		expl.set_markup(explanation)
		self.dialog.show_all()
		if explanation == "":
			expl.hide()
		# returns 1 if help is clicked
		while self.dialog.run() == 1:
			pass
		self.dialog.destroy()


		# transform the stocks treestore into the STOCKS list
		invest.STOCKS = self.to_list(self.model.get_iter_first())

		# store the STOCKS into the pickles file
		try:
			cPickle.dump(invest.STOCKS, file(invest.STOCKS_FILE, 'w'))
			invest.debug('Stocks written to file')
		except Exception, msg:
			invest.error('Could not save stocks file: %s' % msg)
Esempio n. 15
0
    def show_run_hide(self, explanation=""):
        expl = self.ui.get_object("explanation")
        expl.set_markup(explanation)
        self.dialog.show_all()
        if explanation == "":
            expl.hide()
        self.dialog.run()
        self.dialog.destroy()

        invest.STOCKS = {}

        def save_symbol(model, path, iter):
            #if int(model[iter][1]) == 0 or float(model[iter][2]) < 0.0001:
            #	return

            if not model[iter][0] in invest.STOCKS:
                invest.STOCKS[model[iter][0]] = {
                    'label': model[iter][1],
                    'purchases': []
                }

            invest.STOCKS[model[iter][0]]["purchases"].append({
                "amount":
                float(model[iter][2]),
                "bought":
                float(model[iter][3]),
                "comission":
                float(model[iter][4]),
            })

        self.model.foreach(save_symbol)
        try:
            cPickle.dump(invest.STOCKS, file(invest.STOCKS_FILE, 'w'))
            invest.debug('Stocks written to file')
        except Exception, msg:
            invest.error('Could not save stocks file: %s' % msg)