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)
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()
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)
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 )
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()
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) )
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) )
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) )
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)
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
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) )
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)
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()