home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / python2.4 / site-packages / invest / widgets.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2006-08-31  |  5.1 KB  |  151 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. import os
  5. import time
  6. from os.path import *
  7. import gnomeapplet
  8. import gtk
  9. import gtk.gdk as gtk
  10. import gconf
  11. import gobject
  12. import pango
  13. from gettext import gettext as _
  14. import gtk
  15. import gtk.glade as gtk
  16. import egg.trayicon as egg
  17. import gobject
  18. import gnomevfs
  19. import csv
  20. import os
  21. from gettext import gettext as _
  22. import invest
  23. import invest.about as invest
  24. import invest.chart as invest
  25. from invest.quotes import get_quotes_updater
  26. from invest import *
  27. COLORSCALE_POSITIVE = [
  28.     'white',
  29.     '#ad7fa8',
  30.     '#75507b',
  31.     '#5c3566',
  32.     '#729fcf',
  33.     '#3465a4',
  34.     '#204a87',
  35.     '#8ae234',
  36.     '#73d216',
  37.     '#4e9a06']
  38. GREEN = COLORSCALE_POSITIVE[-1]
  39. COLORSCALE_NEGATIVE = [
  40.     'white',
  41.     '#fce94f',
  42.     '#e9b96e',
  43.     '#fcaf3e',
  44.     '#c17d11',
  45.     '#f57900',
  46.     '#ce5c00',
  47.     '#ef2929',
  48.     '#cc0000',
  49.     '#a40000']
  50. RED = COLORSCALE_NEGATIVE[-1]
  51.  
  52. class InvestWidget(gtk.TreeView):
  53.     
  54.     def __init__(self):
  55.         gtk.TreeView.__init__(self)
  56.         self.set_property('headers-visible', False)
  57.         self.set_property('rules-hint', True)
  58.         self.set_reorderable(True)
  59.         cell = gtk.CellRendererText()
  60.         self.column_description = gtk.TreeViewColumn('Description', cell)
  61.         self.column_description.set_cell_data_func(cell, self._get_cell_data)
  62.         self.append_column(self.column_description)
  63.         self.connect('row-activated', self.on_row_activated)
  64.         self.set_model(get_quotes_updater())
  65.  
  66.     
  67.     def _get_cell_data(self, column, cell, model, iter):
  68.         if model[iter][model.TICKER_ONLY]:
  69.             color = GREEN
  70.             if model[iter][model.VARIATION] < 0:
  71.                 color = RED
  72.             
  73.             cell.set_property('markup', "<span face='Monospace'>%s: <span foreground='%s'>%+.2f</span> (<span foreground='%s'>%+.2f%%</span>)</span>" % (model[iter][model.SYMBOL], color, model[iter][model.VALUE], color, model[iter][model.VARIATION]))
  74.         else:
  75.             color = GREEN
  76.             if model[iter][model.BALANCE] < 0:
  77.                 color = RED
  78.             
  79.             cell.set_property('markup', "<span face='Monospace'>%s: <span foreground='%s'>%.2f</span> (<span foreground='%s'>%+.2f%%</span>) %.2f</span>" % (model[iter][model.SYMBOL], color, model[iter][model.BALANCE], color, model[iter][model.BALANCE_PCT], model[iter][model.VALUE]))
  80.  
  81.     
  82.     def on_row_activated(self, treeview, path, view_column):
  83.         ticker = self.get_model()[self.get_model().get_iter(path)][0]
  84.         if ticker == None:
  85.             return None
  86.         
  87.         invest.chart.show_chart([
  88.             ticker])
  89.  
  90.  
  91. gobject.type_register(InvestWidget)
  92.  
  93. class InvestTrend(gtk.Image):
  94.     
  95.     def __init__(self):
  96.         gtk.Image.__init__(self)
  97.         self.pixbuf = None
  98.         self.previous_allocation = (0, 0)
  99.         self.connect('size-allocate', self.on_size_allocate)
  100.         get_quotes_updater().connect('quotes-updated', self.on_quotes_update)
  101.  
  102.     
  103.     def on_size_allocate(self, widget, allocation):
  104.         if self.previous_allocation == (allocation.width, allocation.height):
  105.             return None
  106.         
  107.         self.pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, allocation.height, allocation.height)
  108.         self.set_color('grey')
  109.         self.previous_allocation = (allocation.width, allocation.height)
  110.  
  111.     
  112.     def set_color(self, color, opacity = 255):
  113.         if self.pixbuf != None:
  114.             
  115.             try:
  116.                 color = pango.Color(color)
  117.                 factor = float(255) / 65535
  118.                 self.pixbuf.fill(int(color.red * factor) << 24 | int(color.green * factor) << 16 | int(color.blue * factor) << 8 | opacity)
  119.                 self.set_from_pixbuf(self.pixbuf)
  120.             except Exception:
  121.                 e = None
  122.                 print e
  123.             except:
  124.                 None<EXCEPTION MATCH>Exception
  125.             
  126.  
  127.         None<EXCEPTION MATCH>Exception
  128.  
  129.     
  130.     def on_quotes_update(self, updater):
  131.         start_total = 0
  132.         now_total = 0
  133.         for row in updater:
  134.             if row[updater.TICKER_ONLY]:
  135.                 continue
  136.             
  137.             var = row[updater.VARIATION] / 100
  138.             now = row[updater.VALUE]
  139.             start = now / (1 + var)
  140.             portfolio_number = []([ purchase['amount'] for purchase in invest.STOCKS[row[updater.SYMBOL]] ])
  141.             start_total += start * portfolio_number
  142.             now_total += now * portfolio_number
  143.         
  144.         day_var = ((now_total - start_total) / start_total) * 100
  145.         color = int(2 * day_var)
  146.         opacity = min(255, int(abs(127.5 * day_var)))
  147.         self.set_color(color, opacity)
  148.  
  149.  
  150. gobject.type_register(InvestTrend)
  151.