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 / applet.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-08-31  |  7.7 KB  |  238 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. from gettext import gettext as _
  13. import gconf
  14. import invest
  15. import invest.about as invest
  16. import invest.chart as invest
  17. import invest.preferences as invest
  18. from invest.quotes import get_quotes_updater
  19. from invest.widgets import *
  20.  
  21. class InvestAppletPreferences:
  22.     
  23.     def __init__(self, applet):
  24.         self.GCONF_APPLET_DIR = invest.GCONF_DIR
  25.         self.GCONF_CLIENT = gconf.client_get_default()
  26.         path = applet.get_preferences_key()
  27.         if path != None:
  28.             self.GCONF_APPLET_DIR = path
  29.             self.GCONF_CLIENT = gconf.client_get_default()
  30.             print 'Using per-applet gconf key:', self.GCONF_APPLET_DIR
  31.             gtik_settings = self.GCONF_CLIENT.get_string(self.GCONF_APPLET_DIR + '/prefs/tik_syms')
  32.             if gtik_settings != None and gtik_settings != '':
  33.                 self.GCONF_CLIENT.set_string(self.GCONF_APPLET_DIR + '/prefs/tik_syms', '')
  34.                 for sym in gtik_settings.split('+'):
  35.                     invest.STOCKS[sym].append({
  36.                         'amount': 0,
  37.                         'bought': 0,
  38.                         'comission': 0 })
  39.                 
  40.             
  41.         
  42.  
  43.  
  44.  
  45. class InvestApplet:
  46.     
  47.     def __init__(self, applet):
  48.         self.applet = applet
  49.         self.prefs = InvestAppletPreferences(applet)
  50.         self.investwidget = InvestWidget()
  51.         self.investticker = InvestTrend()
  52.         self.pw = ProgramWindow(applet, self.investticker)
  53.         self.pw.add(self.investwidget)
  54.         self.tb = ToggleButton(applet, self.pw)
  55.         self.investwidget.connect('row-activated', (lambda treeview, path, view_column: self.tb.set_active(False)))
  56.         get_quotes_updater().connect('quotes-updated', self._on_quotes_updated)
  57.         box = gtk.HBox()
  58.         box.add(self.tb)
  59.         box.add(self.investticker)
  60.         self.applet.add(box)
  61.         self.applet.setup_menu_from_file(invest.SHARED_DATA_DIR, 'Invest_Applet.xml', None, [
  62.             ('About', self.on_about),
  63.             ('Prefs', self.on_preferences),
  64.             ('Refresh', self.on_refresh)])
  65.         self.applet.show_all()
  66.         get_quotes_updater().refresh()
  67.  
  68.     
  69.     def on_about(self, component, verb):
  70.         invest.about.show_about()
  71.  
  72.     
  73.     def on_preferences(self, component, verb):
  74.         invest.preferences.show_preferences(self)
  75.         get_quotes_updater().refresh()
  76.  
  77.     
  78.     def on_refresh(self, component, verb):
  79.         get_quotes_updater().refresh()
  80.  
  81.     
  82.     def _on_quotes_updated(self, updater):
  83.         pass
  84.  
  85.  
  86.  
  87. class ToggleButton(gtk.ToggleButton):
  88.     
  89.     def __init__(self, applet, pw):
  90.         gtk.ToggleButton.__init__(self)
  91.         self.pw = pw
  92.         self.connect('toggled', self.toggled)
  93.         self.set_relief(gtk.RELIEF_NONE)
  94.         image = gtk.Image()
  95.         
  96.         try:
  97.             pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(join(invest.ART_DATA_DIR, 'invest-button.png'), -1, -1)
  98.             image.set_from_pixbuf(pixbuf)
  99.         except Exception:
  100.             msg = None
  101.             image.set_from_icon_name('stock_chart', gtk.ICON_SIZE_BUTTON)
  102.  
  103.         hbox = gtk.HBox()
  104.         hbox.pack_start(image)
  105.         orient = applet.get_orient()
  106.         arrow_dir = gtk.ARROW_DOWN
  107.         if orient == gnomeapplet.ORIENT_RIGHT:
  108.             arrow_dir = gtk.ARROW_RIGHT
  109.         elif orient == gnomeapplet.ORIENT_LEFT:
  110.             arrow_dir = gtk.ARROW_LEFT
  111.         elif orient == gnomeapplet.ORIENT_DOWN:
  112.             arrow_dir = gtk.ARROW_DOWN
  113.         elif orient == gnomeapplet.ORIENT_UP:
  114.             arrow_dir = gtk.ARROW_UP
  115.         
  116.         hbox.pack_start(gtk.Arrow(arrow_dir, gtk.SHADOW_NONE))
  117.         self.add(hbox)
  118.  
  119.     
  120.     def toggled(self, togglebutton):
  121.         if togglebutton.get_active():
  122.             self.pw.update_position()
  123.             self.pw.show_all()
  124.             self.pw.grab_focus()
  125.         else:
  126.             self.pw.hide()
  127.  
  128.  
  129. gobject.type_register(ToggleButton)
  130.  
  131. class ProgramWindow(gtk.Window):
  132.     '''
  133. \tBorderless window aligning itself to a given widget.
  134. \tUse CuemiacWindow.update_position() to align it.
  135. \t'''
  136.     
  137.     def __init__(self, applet, widgetToAlignWith):
  138.         '''
  139. \t\talignment should be one of
  140. \t\t\tgnomeapplet.ORIENT_{DOWN,UP,LEFT,RIGHT}
  141. \t\t
  142. \t\tCall CuemiacWindow.update_position () to position the window.
  143. \t\t'''
  144.         gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
  145.         self.set_decorated(False)
  146.         self.stick()
  147.         self.set_keep_above(True)
  148.         self.set_skip_pager_hint(True)
  149.         self.set_skip_taskbar_hint(True)
  150.         self.widgetToAlignWith = widgetToAlignWith
  151.         self.applet = applet
  152.         self.alignment = applet.get_orient()
  153.         self.realize_status = None
  154.         self.connect('realize', (lambda win: self._ProgramWindow__register_realize()))
  155.         self.connect('size-allocate', self._ProgramWindow__resize_event)
  156.  
  157.     
  158.     def __resize_event(self, event, data):
  159.         self.update_position()
  160.  
  161.     
  162.     def update_position(self):
  163.         '''
  164. \t\tCalculates the position and moves the window to it.
  165. \t\tIMPORATNT: widgetToAlignWith should be realized!
  166. \t\t'''
  167.         if self.realize_status == None:
  168.             self.realize_status = False
  169.             self.realize()
  170.             return None
  171.         
  172.         if self.realize_status == False:
  173.             return None
  174.         
  175.         (wx, wy) = self.window.get_origin()
  176.         (ax, ay) = self.widgetToAlignWith.window.get_origin()
  177.         (ww, wh) = self.window.get_size()
  178.         (aw, ah) = self.widgetToAlignWith.window.get_size()
  179.         screen = self.get_screen()
  180.         monitor = screen.get_monitor_geometry(screen.get_monitor_at_window(self.applet.window))
  181.         if self.alignment == gnomeapplet.ORIENT_LEFT:
  182.             x = ax - ww
  183.             y = ay
  184.             if y + wh > monitor.y + monitor.height:
  185.                 y = monitor.y + monitor.height - wh
  186.             
  187.             if y < 0:
  188.                 y = 0
  189.             
  190.             if y + wh > monitor.height / 2:
  191.                 gravity = gtk.gdk.GRAVITY_SOUTH_WEST
  192.             else:
  193.                 gravity = gtk.gdk.GRAVITY_NORTH_WEST
  194.         elif self.alignment == gnomeapplet.ORIENT_RIGHT:
  195.             x = ax + aw
  196.             y = ay
  197.             if y + wh > monitor.y + monitor.height:
  198.                 y = monitor.y + monitor.height - wh
  199.             
  200.             if y < 0:
  201.                 y = 0
  202.             
  203.             if y + wh > monitor.height / 2:
  204.                 gravity = gtk.gdk.GRAVITY_SOUTH_EAST
  205.             else:
  206.                 gravity = gtk.gdk.GRAVITY_NORTH_EAST
  207.         elif self.alignment == gnomeapplet.ORIENT_DOWN:
  208.             x = ax
  209.             y = ay + ah
  210.             if x + ww > monitor.x + monitor.width:
  211.                 x = monitor.x + monitor.width - ww
  212.             
  213.             if x < 0:
  214.                 x = 0
  215.             
  216.             gravity = gtk.gdk.GRAVITY_NORTH_WEST
  217.         elif self.alignment == gnomeapplet.ORIENT_UP:
  218.             x = ax
  219.             y = ay - wh
  220.             if x + ww > monitor.x + monitor.width:
  221.                 x = monitor.x + monitor.width - ww
  222.             
  223.             if x < 0:
  224.                 x = 0
  225.             
  226.             gravity = gtk.gdk.GRAVITY_SOUTH_WEST
  227.         
  228.         self.move(x, y)
  229.         self.set_gravity(gravity)
  230.  
  231.     
  232.     def __register_realize(self):
  233.         self.realize_status = True
  234.         self.update_position()
  235.  
  236.  
  237. gobject.type_register(ProgramWindow)
  238.