+ def show_metal_graphs(self, widget, path, column, model):
+ metal = model[path][1]
+ metal_urls = self.get_metal_graphs_urls(metal)
+ options = []
+ for i in metal_urls:
+ options.append(i[0])
+
+ win = hildon.StackableWindow()
+ #self.create_menu(win)
+ win.set_title(metal)
+
+ vbox = gtk.VBox()
+ #toolbar = self.main_toolbar(False, True, None, '', '', False)
+
+ self.metalgraph_title = gtk.Label(metal)
+ color = gtk.gdk.color_parse("#03A5FF")
+ self.metalgraph_title.modify_fg(gtk.STATE_NORMAL, color)
+
+ parea = hildon.PannableArea()
+ parea.set_property("mov-mode", hildon.MOVEMENT_MODE_BOTH)
+
+ vbox1 = gtk.VBox()
+
+ hbox = gtk.HBox()
+ hbox.set_homogeneous(True)
+
+ button = hildon.Button(fhsize, horbtn)
+ button.set_label('live')
+ button.connect("clicked", self.show_metalgraph, 'live', win, metal_urls)
+ if 'live' in options:
+ hbox.pack_start(button)
+
+ button = hildon.Button(fhsize, horbtn)
+ button.set_label('30d')
+ button.connect("clicked", self.show_metalgraph, '30d', win, metal_urls)
+ if '30d' in options:
+ hbox.pack_start(button)
+
+ button = hildon.Button(fhsize, horbtn)
+ button.set_label('60d')
+ button.connect("clicked", self.show_metalgraph, '60d', win, metal_urls)
+ if '60d' in options:
+ hbox.pack_start(button)
+
+ button = hildon.Button(fhsize, horbtn)
+ button.set_label('6m')
+ button.connect("clicked", self.show_metalgraph, '6m', win, metal_urls)
+ if '6m' in options:
+ hbox.pack_start(button)
+
+ vbox1.pack_start(hbox, False, False, 0)
+ hbox = gtk.HBox()
+ hbox.set_homogeneous(True)
+
+ button = hildon.Button(fhsize, horbtn)
+ button.set_label('1y')
+ button.connect("clicked", self.show_metalgraph, '1y', win, metal_urls)
+ if '1y' in options:
+ hbox.pack_start(button)
+
+ button = hildon.Button(fhsize, horbtn)
+ button.set_label('5y')
+ button.connect("clicked", self.show_metalgraph, '5y', win, metal_urls)
+ if '5y' in options:
+ hbox.pack_start(button)
+
+ button = hildon.Button(fhsize, horbtn)
+ button.set_label('10y')
+ button.connect("clicked", self.show_metalgraph, '10y', win, metal_urls)
+ if '10y' in options:
+ hbox.pack_start(button)
+
+ vbox1.pack_start(hbox, False, False, 0)
+
+ self.metalgraph = gtk.Image()
+ vbox1.pack_start(self.metalgraph, True, True, 0)
+
+ parea.add_with_viewport(vbox1)
+
+ vbox.pack_start(self.metalgraph_title, False, False, 0)
+ vbox.pack_start(gtk.HSeparator(), False, False, 0)
+ vbox.pack_start(parea, True, True, 0)
+ vbox.pack_start(gtk.HSeparator(), False, False, 5)
+ #vbox.pack_start(toolbar, False, False, 0)
+
+ win.add(vbox)
+ win.show_all()
+
+ self.show_metalgraph(None, options[0], win, metal_urls)
+
+ def show_metalgraph(self, widget, option, win, metal_urls):
+ import thread
+ winprogind(win, 1)
+ thread.start_new_thread(self.get_metalgraph_data, (option, win, metal_urls))
+
+ def get_metalgraph_data(self, option, win, metal_urls):
+ for i in metal_urls:
+ if i[0] == option:
+ print i[1]
+ url = i[1]
+
+ try:
+ myimg = urllib2.urlopen(url)
+ imgdata = myimg.read()
+
+ pbl = gtk.gdk.PixbufLoader()
+ pbl.write(imgdata)
+
+
+ pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, 475, 235)
+ pixbuf.fill(0xffffffff)
+
+
+ pbuf = pbl.get_pixbuf()
+ pbuf = pbuf.scale_simple(475, 235, gtk.gdk.INTERP_TILES)
+
+ pixbuf.composite(pbuf, 0, 0, pixbuf.props.width, pixbuf.props.height, 0, 0, 1.0, 1.0, gtk.gdk.INTERP_HYPER, 55)
+
+
+ pbl.close()
+ self.metalgraph.set_from_pixbuf(pbuf)
+ winprogind(win, 0)
+ except:
+ logger.exception("Getting graph data: %s" % url)
+ winprogind(win, 0)
+ self.metalgraph_title.set_label('Failed to get data')
+ self.metalgraph.destroy()
+
+ def get_metal_graphs_urls(self, metal):
+ metal_urls = []
+ liveurl = 'http://www.kitco.com/images/live/%s'
+ graphurl = 'http://www.kitco.com/LFgif/%s'
+ t24url = 'http://www.kitconet.com/charts/metals/base/%s'
+ if metal == 'Gold':
+ metal_urls.append(['live', liveurl % 'gold.gif'])
+ metal_urls.append(['30d', graphurl % 'au0030lnb.gif'])
+ metal_urls.append(['60d', graphurl % 'au0060lnb.gif'])
+ metal_urls.append(['6m', graphurl % 'au0182nyb.gif'])
+ metal_urls.append(['1y', graphurl % 'au0365nyb.gif'])
+ metal_urls.append(['5y', graphurl % 'au1825nyb.gif'])
+ metal_urls.append(['10y', graphurl % 'au3650nyb.gif'])
+ elif metal == 'Silver':
+ metal_urls.append(['live', liveurl % 'silver.gif'])
+ metal_urls.append(['30d', graphurl % 'ag0030lnb.gif'])
+ metal_urls.append(['60d', graphurl % 'ag0060lnb.gif'])
+ metal_urls.append(['6m', graphurl % 'ag0182nyb.gif'])
+ metal_urls.append(['1y', graphurl % 'ag0365nyb.gif'])
+ metal_urls.append(['5y', graphurl % 'ag1825nyb.gif'])
+ metal_urls.append(['10y', graphurl % 'ag3650nyb.gif'])
+ elif metal == 'Platinum':
+ metal_urls.append(['live', liveurl % 'plati.gif'])
+ metal_urls.append(['30d', graphurl % 'pt0030lnb.gif'])
+ metal_urls.append(['60d', graphurl % 'pt0060lnb.gif'])
+ metal_urls.append(['6m', graphurl % 'pt0182nyb.gif'])
+ metal_urls.append(['1y', graphurl % 'pt0365nyb.gif'])
+ metal_urls.append(['5y', graphurl % 'pt1825nyb.gif'])
+ elif metal == 'Palladium':
+ metal_urls.append(['live', liveurl % 'plad.gif'])
+ metal_urls.append(['30d', graphurl % 'pd0030lnb.gif'])
+ metal_urls.append(['60d', graphurl % 'pd0060lnb.gif'])
+ metal_urls.append(['6m', graphurl % 'pd0182nyb.gif'])
+ metal_urls.append(['1y', graphurl % 'pd0365nyb.gif'])
+ metal_urls.append(['5y', graphurl % 'pd1825nyb.gif'])
+ elif metal == 'Rhodium':
+ metal_urls.append(['30d', graphurl % 'rh0030lnb.gif'])
+ metal_urls.append(['60d', graphurl % 'rh0060lnb.gif'])
+ metal_urls.append(['6m', graphurl % 'rh0182lnb.gif'])
+ metal_urls.append(['1y', graphurl % 'rh0365lnb.gif'])
+ metal_urls.append(['5y', graphurl % 'rh1825lnb.gif'])
+ elif metal == 'Copper':
+ metal_urls.append(['live', t24url % 't24_cp450x275.gif'])
+ elif metal == 'Nickel':
+ metal_urls.append(['live', t24url % 't24_nk450x275.gif'])
+ elif metal == 'Aluminium':
+ metal_urls.append(['live', t24url % 't24_al450x275.gif'])
+ elif metal == 'Zinc':
+ metal_urls.append(['live', t24url % 't24_zc450x275.gif'])
+ elif metal == 'Lead':
+ metal_urls.append(['live', t24url % 't24_ld450x275.gif'])
+
+ return metal_urls
+