more markets, bugfixing
[stockthis] / stockthis.py
index f5178e3..de12beb 100644 (file)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2.5
+#!/usr/bin/env python
 # -*- coding: UTF8 -*-
 # Copyright (C) 2008 by Daniel Martin Yerga
 # <dyerga@gmail.com>
@@ -134,6 +134,7 @@ class StocksPy:
         toolbar = self.main_toolbar(False, False, None, '', '')
 
         parea = hildon.PannableArea()
+        parea.connect("horizontal-movement", self.horizontal_mov)
         tv = hildon.GtkTreeView(ui_normal)
         model = self.__create_model(names, ids)
         tv.connect("row-activated", self.show_quotes_view, model, False)
@@ -148,6 +149,20 @@ class StocksPy:
         window.add(vbox)
         window.show_all()
 
+    def horizontal_mov(self, parea, direction, initial_x, initial_y):
+        #direction = 2 right-to-left
+        #direction = 3 lefto-to-right
+
+        if direction == 2:
+            parea.scroll_to(-1, initial_y-400)
+        elif direction == 3:
+            parea.scroll_to(-1, initial_y+400)
+
+        print direction
+        print initial_x
+        print initial_y
+
+
     def show_quotes_view(self, widget, path, column, model, portfolio):
         quote = model[path][0], model[path][1]
         #print "quote:", quote[0]
@@ -236,7 +251,7 @@ class StocksPy:
         label.set_markup('<b><big>52 week high:</big></b>')
         l52whigh = gtk.Label('')
         hbox.pack_start(label, False, False, 20)
-        hbox.pack_start(l52whigh, False, False, 110)
+        hbox.pack_start(l52whigh, False, False, 125)
         vbox1.pack_start(hbox, True, True, 0)
 
         hbox = gtk.HBox()
@@ -244,7 +259,7 @@ class StocksPy:
         label.set_markup('<b><big>52 week low:</big></b>')
         l52wlow = gtk.Label('')
         hbox.pack_start(label, False, False, 20)
-        hbox.pack_start(l52wlow, False, False, 125)
+        hbox.pack_start(l52wlow, False, False, 140)
         vbox1.pack_start(hbox, True, True, 0)
 
         hbox = gtk.HBox()
@@ -268,21 +283,21 @@ class StocksPy:
         label.set_markup('<b><big>Shares:</big></b>')
         lshares = gtk.Label(shares)
         hbox1.pack_start(label, False, False, 20)
-        hbox1.pack_start(lshares, False, False, 215)
+        hbox1.pack_start(lshares, False, False, 220)
 
         hbox2 = gtk.HBox()
         label = gtk.Label('')
         label.set_markup('<b><big>Holdings Value:</big></b>')
         holdingsvalue = gtk.Label("")
         hbox2.pack_start(label, False, False, 20)
-        hbox2.pack_start(holdingsvalue, False, False, 85)
+        hbox2.pack_start(holdingsvalue, False, False, 105)
 
         hbox3 = gtk.HBox()
         label = gtk.Label('')
         label.set_markup("<b><big>Day's Value Change:</big></b>")
         dayvaluechange = gtk.Label("")
         hbox3.pack_start(label, False, False, 20)
-        hbox3.pack_start(dayvaluechange, False, False, 10)
+        hbox3.pack_start(dayvaluechange, False, False, 45)
 
         if not portfolio:
             vbox1.pack_start(hbox, False, False, 0)
@@ -600,6 +615,11 @@ class StocksPy:
         hbox.pack_start(button, True, True, 0)
 
         button = hildon.Button(fhsize, horbtn)
+        button.set_title("Add manually")
+        button.connect("clicked", self.add_item_dlg)
+        hbox.pack_start(button, True, True, 0)
+
+        button = hildon.Button(fhsize, horbtn)
         button.set_title("Remove")
         button.connect("clicked", self.remove_item)
         hbox.pack_start(button, True, True, 0)
@@ -609,6 +629,48 @@ class StocksPy:
         win.add(vbox)
         win.show_all()
 
+    def add_item_dlg(self, widget):
+        dlg = gtk.Dialog(title='Add to portfolio', parent=None, flags=0)
+        dlg.set_has_separator(False)
+
+        button1 = hildon.PickerButton(fhsize, horbtn)
+        data = ["50", "100", "200", "300", "400", "500", "600", "700", "800",
+                "900", "1000"]
+        selector = self.create_selector(data, True)
+        button1.set_selector(selector)
+        button1.set_title("Your shares")
+        button1.set_value("0")
+        dlg.vbox.pack_start(button1, False, False, 0)
+
+        entry1 = hildon.Entry(fhsize)
+        entry1.set_placeholder("Name")
+        dlg.vbox.pack_start(entry1, False, False, 0)
+
+        entry2 = hildon.Entry(fhsize)
+        entry2.set_placeholder("Yahoo Finance symbol")
+        dlg.vbox.pack_start(entry2, False, False, 0)
+
+        button = hildon.Button(fhsize, horbtn)
+        button.set_label("Add")
+        button.connect("clicked", self.add_item, dlg, button1, entry1, entry2)
+        dlg.vbox.pack_start(button, False, False, 0)
+
+        dlg.show_all()
+        dlg.run()
+        dlg.destroy()
+
+
+    def add_item(self, widget, dlg, button, entry1, entry2):
+        symbol = entry2.get_text()
+        name = entry1.get_text()
+        shares = button.get_value()
+
+        self.add_to_portfolio(widget, button, symbol, name)
+        dlg.destroy()
+
+        niter = self.portfolio_model.append()
+        self.portfolio_model.set(niter, 0, symbol, 1, name, 2, shares, 3, "-")
+
     def remove_item(self, widget):
         win = hildon.StackableWindow()
         win.fullscreen()
@@ -775,7 +837,7 @@ class About:
         hbox1.pack_start(button, True, True, 0)
 
         button = hildon.Button(fhsize, horbtn)
-        button.set_title(' Vote ')
+        button.set_title(' Rate ')
         button.connect("clicked", self.show_info, 'vote')
         hbox1.pack_start(button, True, True, 0)
 
@@ -832,16 +894,16 @@ stockthis.garage.maemo.org"""
         elif kind == 'donate':
             self.action_btn.show()
             self.image.hide()
-            self.action_btn.set_title('I want donate')
+            self.action_btn.set_title('Make donation')
             if self.id:
                 self.action_btn.disconnect(self.id)
             self.id = self.action_btn.connect("clicked", self.do_action, "donate")
             info = """<small><b>StockThis</b> is a free (and gratis) software application.
 Developing good software takes time and hard work.
 
-<b>StockThis's author</b> develops the program in him spare time.
+<b>StockThis's author</b> develops the program in his spare time.
 If you like the program and it's helpful, consider donating a small amount of money.
-Donations are a great incentive and help to feel that the hard work is appreciated.</small>
+Donations are a great incentive and help the developer feel that the hard work is appreciated.</small>
 """
 
         elif kind == 'report':
@@ -860,7 +922,7 @@ If the application is raising an error when you're using it, you have two choice
             self.action_btn.show()
             self.image.show()
             self.image.set_from_file(imgdir + "maemoorg.png")
-            self.action_btn.set_title('Vote for StockThis')
+            self.action_btn.set_title('Rate StockThis')
             if self.id:
                 self.action_btn.disconnect(self.id)
             self.id = self.action_btn.connect("clicked", self.do_action, "vote")