From: Daniel Martin Yerga Date: Sat, 24 Oct 2009 14:09:15 +0000 (+0200) Subject: added portrait mode X-Git-Url: https://vcs.maemo.org/git/?p=stockthis;a=commitdiff_plain;h=9914d57a3d4c29213512e20b131e9e974f10e209 added portrait mode --- diff --git a/changelog b/changelog index 1f7ced2..010c5a3 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,12 @@ +2009-10-24 Daniel Martin Yerga + + * Improved the alignment of the labels in quotes view. + * Made all views agnostic to portrait/landscape orientation. + +2009-10-23 Daniel Martin Yerga + + * Adding support for portrait mode. Need some tweaking. + 2009-10-03 Daniel Martin Yerga * Using maemo-optify to save root space in the N900. diff --git a/portrait.py b/portrait.py new file mode 100644 index 0000000..46f5fed --- /dev/null +++ b/portrait.py @@ -0,0 +1,168 @@ +# -*- coding: utf-8 -*- +# +# gPodder - A media aggregator and podcast client +# Copyright (c) 2005-2009 Thomas Perl and the gPodder Team +# +# gPodder is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# gPodder is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import dbus +import dbus.glib + +import hildon +import osso + + + +class FremantleRotation(object): + """thp's screen rotation for Maemo 5 + + Simply instantiate an object of this class and let it auto-rotate + your StackableWindows depending on the device orientation. + + If you need to relayout a window, connect to its "configure-event" + signal and measure the ratio of width/height and relayout for that. + + You can set the mode for rotation to AUTOMATIC (default), NEVER or + ALWAYS with the set_mode() method. + """ + AUTOMATIC, NEVER, ALWAYS = range(3) + + # Human-readable captions for the above constants + MODE_CAPTIONS = ('Automatic', 'Landscape', 'Portrait') + + # Privately-used constants + _PORTRAIT, _LANDSCAPE = ('portrait', 'landscape') + _ENABLE_ACCEL = 'req_accelerometer_enable' + _DISABLE_ACCEL = 'req_accelerometer_disable' + + # Defined in mce/dbus-names.h + _MCE_SERVICE = 'com.nokia.mce' + _MCE_REQUEST_PATH = '/com/nokia/mce/request' + _MCE_REQUEST_IF = 'com.nokia.mce.request' + + def __init__(self, app_name, main_window=None, version='1.0', mode=0): + """Create a new rotation manager + + app_name ... The name of your application (for osso.Context) + main_window ... The root window (optional, hildon.StackableWindow) + version ... The version of your application (optional, string) + mode ... Initial mode for this manager (default: AUTOMATIC) + """ + self._orientation = None + self._main_window = main_window + self._stack = hildon.WindowStack.get_default() + self._mode = -1 + self._last_dbus_orientation = None + app_id = '-'.join((app_name, self.__class__.__name__)) + self._osso_context = osso.Context(app_id, version, False) + program = hildon.Program.get_instance() + program.connect('notify::is-topmost', self._on_topmost_changed) + system_bus = dbus.Bus.get_system() + system_bus.add_signal_receiver(self._on_orientation_signal, \ + signal_name='sig_device_orientation_ind', \ + dbus_interface='com.nokia.mce.signal', \ + path='/com/nokia/mce/signal') + self.set_mode(mode) + + def get_mode(self): + """Get the currently-set rotation mode + + This will return one of three values: AUTOMATIC, ALWAYS or NEVER. + """ + return self._mode + + def set_mode(self, new_mode): + """Set the rotation mode + + You can set the rotation mode to AUTOMATIC (use hardware rotation + info), ALWAYS (force portrait) and NEVER (force landscape). + """ + if new_mode not in (self.AUTOMATIC, self.ALWAYS, self.NEVER): + raise ValueError('Unknown rotation mode') + + if self._mode != new_mode: + if self._mode == self.AUTOMATIC: + # Remember the current "automatic" orientation for later + self._last_dbus_orientation = self._orientation + # Tell MCE that we don't need the accelerometer anymore + self._send_mce_request(self._DISABLE_ACCEL) + + if new_mode == self.NEVER: + self._orientation_changed(self._LANDSCAPE) + elif new_mode == self.ALWAYS: + self._orientation_changed(self._PORTRAIT) + elif new_mode == self.AUTOMATIC: + # Restore the last-known "automatic" orientation + self._orientation_changed(self._last_dbus_orientation) + # Tell MCE that we need the accelerometer again + self._send_mce_request(self._ENABLE_ACCEL) + + self._mode = new_mode + + def _send_mce_request(self, request): + rpc = osso.Rpc(self._osso_context) + rpc.rpc_run(self._MCE_SERVICE, \ + self._MCE_REQUEST_PATH, \ + self._MCE_REQUEST_IF, \ + request, \ + use_system_bus=True) + + def _on_topmost_changed(self, program, property_spec): + # XXX: This seems to never get called on Fremantle(?) + if self._mode == self.AUTOMATIC: + if program.get_is_topmost(): + self._send_mce_request(self._ENABLE_ACCEL) + else: + self._send_mce_request(self._DISABLE_ACCEL) + + def _get_main_window(self): + if self._main_window: + # If we have gotten the main window as parameter, return it and + # don't try "harder" to find another window using the stack + return self._main_window + else: + # The main window is at the "bottom" of the window stack, and as + # the list we get with get_windows() is sorted "topmost first", we + # simply take the last item of the list to get our main window + windows = self._stack.get_windows() + if windows: + return windows[-1] + else: + return None + + def _orientation_changed(self, orientation): + if self._orientation == orientation: + # Ignore repeated requests + return + + flags = hildon.PORTRAIT_MODE_SUPPORT + if orientation == self._PORTRAIT: + flags |= hildon.PORTRAIT_MODE_REQUEST + + window = self._get_main_window() + if window is not None: + hildon.hildon_gtk_window_set_portrait_flags(window, flags) + + self._orientation = orientation + + def _on_orientation_signal(self, orientation, stand, face, x, y, z): + if orientation in (self._PORTRAIT, self._LANDSCAPE): + if self._mode == self.AUTOMATIC: + # Automatically set the rotation based on hardware orientation + self._orientation_changed(orientation) + else: + # Ignore orientation changes for non-automatic modes, but save + # the current orientation for "automatic" mode later on + self._last_dbus_orientation = orientation diff --git a/stockthis.py b/stockthis.py index 86fb395..c2a8b01 100644 --- a/stockthis.py +++ b/stockthis.py @@ -16,8 +16,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # -# StocksPy: Application to get stocks data from Yahoo Finance. -# Version 0.1 +# StocksThis: Application to get stocks data from Yahoo Finance. # _version = "StockThis 0.3 beta1 rev1" @@ -31,6 +30,8 @@ import settings import logging import sys +from portrait import FremantleRotation + import osso osso_c = osso.Context("net.yerga.stockthis", "0.3", False) @@ -88,6 +89,8 @@ class StocksPy: self.program.add_window(self.window) self.window.connect("destroy", gtk.main_quit) + FremantleRotation('StockThis', None, "0.3", 0) + self.create_menu(self.window) vbox = gtk.VBox() @@ -221,51 +224,75 @@ class StocksPy: ltitle.modify_fg(gtk.STATE_NORMAL, color) parea = hildon.PannableArea() + parea.set_property("mov-mode", hildon.MOVEMENT_MODE_BOTH) vbox1 = gtk.VBox() hbox = gtk.HBox() label = gtk.Label('') - label.set_markup('Price:') + label.set_markup('%39s:' % 'Price') lprice = gtk.Label('') - hbox.pack_start(label, False, False, 20) - hbox.pack_start(lprice, False, False, 245) + hbox.pack_start(label, False, False, 0) + #if self.is_portrait(): + hbox.pack_start(lprice, False, False, 25) + #else: + # hbox.pack_start(lprice, False, False, 245) + vbox1.pack_start(hbox, True, True, 0) hbox = gtk.HBox() label = gtk.Label('') - label.set_markup('Change:') + label.set_markup('%35s:' % 'Change') lchange = gtk.Label('') lpercent = gtk.Label('') - hbox.pack_start(label, False, False, 20) - hbox.pack_start(lchange, False, False, 205) + hbox.pack_start(label, False, False, 0) + #if self.is_portrait(): + hbox.pack_start(lchange, False, False, 25) hbox.pack_start(lpercent, False, False, 0) + #else: + # hbox.pack_start(lchange, False, False, 205) + # hbox.pack_start(lpercent, False, False, 0) + vbox1.pack_start(hbox, True, True, 0) hbox = gtk.HBox() label = gtk.Label('') - label.set_markup('Volume:') + label.set_markup('%35s:' % 'Volume') lvolume = gtk.Label('') - hbox.pack_start(label, False, False, 20) - hbox.pack_start(lvolume, False, False, 207) + hbox.pack_start(label, False, False, 0) + #if self.is_portrait(): + hbox.pack_start(lvolume, False, False, 25) + #else: + # hbox.pack_start(lvolume, False, False, 207) + vbox1.pack_start(hbox, True, True, 0) hbox = gtk.HBox() label = gtk.Label('') - label.set_markup('52 week high:') + label.set_markup('%30s:' % '52 week high') l52whigh = gtk.Label('') - hbox.pack_start(label, False, False, 20) - hbox.pack_start(l52whigh, False, False, 125) + hbox.pack_start(label, False, False, 0) + #if self.is_portrait(): + hbox.pack_start(l52whigh, False, False, 25) + #else: + # hbox.pack_start(l52whigh, False, False, 125) + vbox1.pack_start(hbox, True, True, 0) hbox = gtk.HBox() label = gtk.Label('') - label.set_markup('52 week low:') + label.set_markup('%30s:' % '52 week low') l52wlow = gtk.Label('') - hbox.pack_start(label, False, False, 20) - hbox.pack_start(l52wlow, False, False, 140) + hbox.pack_start(label, False, False, 0) + #if self.is_portrait(): + hbox.pack_start(l52wlow, False, False, 26) + #else: + # hbox.pack_start(l52wlow, False, False, 140) vbox1.pack_start(hbox, True, True, 0) + #if self.is_portrait(): + # hbox = gtk.VBox() + #else: hbox = gtk.HBox() button1 = hildon.PickerButton(fhsize, horbtn) data = ["50", "100", "200", "300", "400", "500", "600", "700", "800", @@ -284,24 +311,33 @@ class StocksPy: hbox1 = gtk.HBox() label = gtk.Label('') - label.set_markup('Shares:') + label.set_markup('%37s:' % 'Shares') lshares = gtk.Label(shares) - hbox1.pack_start(label, False, False, 20) - hbox1.pack_start(lshares, False, False, 220) + hbox1.pack_start(label, False, False, 0) + #if self.is_portrait(): + hbox1.pack_start(lshares, False, False, 25) + #else: + # hbox1.pack_start(lshares, False, False, 220) hbox2 = gtk.HBox() label = gtk.Label('') - label.set_markup('Holdings Value:') + label.set_markup('%29s:' % 'Holdings Value') holdingsvalue = gtk.Label("") - hbox2.pack_start(label, False, False, 20) - hbox2.pack_start(holdingsvalue, False, False, 105) + hbox2.pack_start(label, False, False, 0) + #if self.is_portrait(): + hbox2.pack_start(holdingsvalue, False, False, 25) + #else: + # hbox2.pack_start(holdingsvalue, False, False, 105) hbox3 = gtk.HBox() label = gtk.Label('') - label.set_markup("Day's Value Change:") + label.set_markup("%25s:" % "Day's Value Change") dayvaluechange = gtk.Label("") - hbox3.pack_start(label, False, False, 20) - hbox3.pack_start(dayvaluechange, False, False, 45) + hbox3.pack_start(label, False, False, 0) + #if self.is_portrait(): + hbox3.pack_start(dayvaluechange, False, False, 25) + #else: + # hbox3.pack_start(dayvaluechange, False, False, 45) if not portfolio: vbox1.pack_start(hbox, False, False, 0) @@ -328,6 +364,14 @@ class StocksPy: win.show_all() self.show_data(quote[0], widgets, shares) + def is_portrait(self): + width = gtk.gdk.screen_width() + height = gtk.gdk.screen_height() + if width > height: + return False + else: + return True + def get_shares_from_symbol(self, symbol): shares = "0" try: @@ -449,6 +493,9 @@ class StocksPy: self.graphs_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) @@ -473,6 +520,10 @@ class StocksPy: button.connect("clicked", self.show_graph, '6m', win, symbol) 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_graph, '1y', win, symbol) @@ -493,7 +544,6 @@ class StocksPy: button.connect("clicked", self.show_graph, 'max', win, symbol) hbox.pack_start(button) - vbox1 = gtk.VBox() vbox1.pack_start(hbox, False, False, 0) self.graph = gtk.Image() @@ -543,6 +593,7 @@ class StocksPy: pbl.write(imgdata) pbuf = pbl.get_pixbuf() + pbuf = pbuf.scale_simple(475, 235, gtk.gdk.INTERP_TILES) pbl.close() self.graph.set_from_pixbuf(pbuf) winprogind(win, 0) @@ -734,6 +785,7 @@ class StocksPy: vbox = gtk.VBox() parea = hildon.PannableArea() + parea.set_property("mov-mode", hildon.MOVEMENT_MODE_BOTH) tv = hildon.GtkTreeView(ui_normal) tv.set_headers_visible(True) self.portfolio_model = self._create_portfolio_model(data)