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
            mate_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()
            mate_invest.debug("Current Network Manager status is %d" %
                              self.state)
        except Exception, msg:
            mate_invest.error("Could not connect to the Network Manager: %s" %
                              msg)
Example #2
0
 def on_currency_retriever_completed(self, retriever):
     if retriever.retrieved == False:
         mate_invest.error("Failed to retrieve currency rates!")
     else:
         self.convert_currencies(
             self.parse_yahoo_csv(csv.reader(retriever.data)))
     self.update_tooltip()
Example #3
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()

		mate_invest.STOCKS = {}

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

			if not model[iter][0] in mate_invest.STOCKS:
				mate_invest.STOCKS[model[iter][0]] = { 'label': model[iter][1], 'purchases': [] }
				
			mate_invest.STOCKS[model[iter][0]]["purchases"].append({
				"amount": float(model[iter][2]),
				"bought": float(model[iter][3]),
				"comission": float(model[iter][4]),
				"exchange": float(model[iter][5])
			})
		self.model.foreach(save_symbol, None)
		try:
			cPickle.dump(mate_invest.STOCKS, file(mate_invest.STOCKS_FILE, 'w'))
			mate_invest.debug('Stocks written to file')
		except Exception, msg:
			mate_invest.error('Could not save stocks file: %s' % msg)
Example #4
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
			mate_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()
			mate_invest.debug("Current Network Manager status is %d" % self.state)
		except Exception, msg:
			mate_invest.error("Could not connect to the Network Manager: %s" % msg )
Example #5
0
	def on_currency_retriever_completed(self, retriever):
		if retriever.retrieved == False:
			mate_invest.error("Failed to retrieve currency rates!")
		else:
			mate_invest.debug("CurrencyRetriever completed")
			self.save_currencies(retriever.data)
			self.load_currencies()
		self.update_tooltip()
Example #6
0
	def save_currencies(self, data):
		mate_invest.debug("Storing currencies to %s" % mate_invest.CURRENCIES_FILE)
		try:
			f = open(mate_invest.CURRENCIES_FILE, 'w')
			f.write(data)
			f.close()
		except Exception as msg:
			mate_invest.error("Could not save the retrieved currencies to %s: %s" % (mate_invest.CURRENCIES_FILE, msg) )
Example #7
0
	def on_currency_retriever_completed(self, retriever):
		if retriever.retrieved == False:
			mate_invest.error("Failed to retrieve currency rates!")
		else:
			mate_invest.debug("CurrencyRetriever completed")
			self.save_currencies(retriever.data)
			self.load_currencies()
		self.update_tooltip()
Example #8
0
	def save_quotes(self, data):
		mate_invest.debug("Storing quotes")
		try:
			f = open(mate_invest.QUOTES_FILE, 'w')
			f.write(data)
			f.close()
		except Exception, msg:
			mate_invest.error("Could not save the retrieved quotes file to %s: %s" % (mate_invest.QUOTES_FILE, msg) )
Example #9
0
	def save_currencies(self, data):
		mate_invest.debug("Storing currencies to %s" % mate_invest.CURRENCIES_FILE)
		try:
			f = open(mate_invest.CURRENCIES_FILE, 'w')
			f.write(data)
			f.close()
		except Exception as msg:
			mate_invest.error("Could not save the retrieved currencies to %s: %s" % (mate_invest.CURRENCIES_FILE, msg) )
Example #10
0
	def save_quotes(self, data):
		mate_invest.debug("Storing quotes")
		try:
			f = open(mate_invest.QUOTES_FILE, 'w')
			f.write(data)
			f.close()
		except Exception, msg:
			mate_invest.error("Could not save the retrieved quotes file to %s: %s" % (mate_invest.QUOTES_FILE, msg) )
Example #11
0
	def load_currencies(self):
		mate_invest.debug("Loading currencies from %s" % mate_invest.CURRENCIES_FILE)
		try:
			f = open(mate_invest.CURRENCIES_FILE, 'r')
			data = f.readlines()
			f.close()

			self.convert_currencies(self.parse_yahoo_csv(csv.reader(data)))
		except Exception as msg:
			mate_invest.error("Could not load the currencies from %s: %s" % (mate_invest.CURRENCIES_FILE, msg) )
Example #12
0
	def load_currencies(self):
		mate_invest.debug("Loading currencies from %s" % mate_invest.CURRENCIES_FILE)
		try:
			f = open(mate_invest.CURRENCIES_FILE, 'r')
			data = f.readlines()
			f.close()

			self.convert_currencies(self.parse_yahoo_csv(csv.reader(data)))
		except Exception as msg:
			mate_invest.error("Could not load the currencies from %s: %s" % (mate_invest.CURRENCIES_FILE, msg) )
Example #13
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:
				mate_invest.error("Could not set color: %s" % msg)
Example #14
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:
				mate_invest.error("Could not set color: %s" % msg)
Example #15
0
	def on_cell_edited(self, cell, path, new_text, col, typ):
		try:
			if col == 0:    # 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:
			mate_invest.error('Exception while processing cell change: %s' % msg)
			pass
Example #16
0
	def load_quotes(self):
		mate_invest.debug("Loading quotes");
		try:
			f = open(mate_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(mate_invest.QUOTES_FILE))
			self.update_tooltip()
		except Exception, msg:
			mate_invest.error("Could not load the cached quotes file %s: %s" % (mate_invest.QUOTES_FILE, msg) )
Example #17
0
 def on_cell_edited(self, cell, path, new_text, col, typ):
     try:
         if col == 0:  # 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:
         mate_invest.error('Exception while processing cell change: %s' %
                           msg)
         pass
Example #18
0
	def load_quotes(self):
		mate_invest.debug("Loading quotes");
		try:
			f = open(mate_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(mate_invest.QUOTES_FILE))
			self.update_tooltip()
		except Exception, msg:
			mate_invest.error("Could not load the cached quotes file %s: %s" % (mate_invest.QUOTES_FILE, msg) )
Example #19
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()

        mate_invest.STOCKS = {}

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

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

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

        self.model.foreach(save_symbol, None)
        try:
            cPickle.dump(mate_invest.STOCKS, file(mate_invest.STOCKS_FILE,
                                                  'w'))
            mate_invest.debug('Stocks written to file')
        except Exception, msg:
            mate_invest.error('Could not save stocks file: %s' % msg)
Example #20
0
	def on_currency_retriever_completed(self, retriever):
		if retriever.retrieved == False:
			mate_invest.error("Failed to retrieve currency rates!")
		else:
			self.convert_currencies(self.parse_yahoo_csv(csv.reader(retriever.data)))
		self.update_tooltip()