From: Stefanos Harhalakis Date: Sun, 8 Aug 2010 15:10:04 +0000 (+0000) Subject: Restore portrait.py's abilities to rotate windows. X-Git-Url: http://vcs.maemo.org/git/?p=drlaunch;a=commitdiff_plain;h=6ffc68fd975169aa7dda7387a28118cbfd49701a Restore portrait.py's abilities to rotate windows. Disable animations in configuration window. Set the size request of about dialog to 800x800 to support portrait mode. Pass the parent to about dialog and set it as needed to support postrait mode. Add credits for postrait.py too. Clear animation cache when animations are disabled. Add code for portrait mode support: Disabled for now since it isn't reliable. --- diff --git a/src/about.py b/src/about.py index 8156bd3..d70a67f 100755 --- a/src/about.py +++ b/src/about.py @@ -25,22 +25,28 @@ __version__ = "$Id: 0.py 2265 2010-02-21 19:16:26Z v13 $" from gtk import AboutDialog import config from about0 import HeAboutDialog +from portrait import FremantleRotation -class DlgAbout(HeAboutDialog): - def __init__(self, *args): - HeAboutDialog.__init__(self, *args) +class DlgAbout(HeAboutDialog, FremantleRotation): + def __init__(self): + HeAboutDialog.__init__(self) + FremantleRotation.__init__(self, "DrlaunchPlugin", + mode=FremantleRotation.AUTOMATIC) @classmethod - def present2(cls): + def present2(cls, parent): _copyright="""\ Copyright (C) 2010 Stefanos Harhalakis -Copyright (C) 2005-2010 Thomas Perl and the gPodder Team (for about0.py) +Copyright (C) 2005-2010 Thomas Perl and the gPodder Team (for about0.py +and portrait.py) """ _description=""" DrLaunch is a desktop launcher widget that supports portrait mode by rotating program icons. Whenever the device is rotated, icons are also rotated. + +Thanks to Thomas Perl and the gPodder Team. """ _license="""\ @@ -60,7 +66,9 @@ You should have received a copy of the GNU General Public License along with DrLaunch. If not, see . DrLaunch uses a modified version of about.py from gpodder which is also -distributed under the terms of the GPLv3 license. +distributed under the terms of the GPLv3 license. It also uses a +modified version of portrait.py from gpodder which is also distributed +under the terms of the GPLv3 license. """ args={ @@ -69,12 +77,13 @@ distributed under the terms of the GPLv3 license. "copyright": _copyright + "\n" + _license, "description": _description, "bugtracker_url": "mailto:v13@v13.gr", + "parent": parent, } cls.present(**args) def set_icon_name(self, icon_name): - print "koko" + pass # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent: diff --git a/src/about0.py b/src/about0.py index bd09e25..eeb6ae3 100644 --- a/src/about0.py +++ b/src/about0.py @@ -1,4 +1,5 @@ -# -*- coding: utf-8 -*- +#!/usr/bin/env python +# coding=UTF-8 # # gPodder - A media aggregator and podcast client # Copyright (c) 2005-2010 Thomas Perl and the gPodder Team @@ -61,7 +62,7 @@ class HeAboutDialog(gtk.Dialog): self.image_icon.set_padding(5, 5) #content_area = self.get_content_area() # Starting with PyGTK 2.14 - self.set_size_request(800,480) + self.set_size_request(800,800) pa=hildon.PannableArea() pa.set_property('mov-mode', hildon.MOVEMENT_MODE_HORIZ | hildon.MOVEMENT_MODE_VERT ) diff --git a/src/icon.py b/src/icon.py index 32f4f84..f6a6099 100755 --- a/src/icon.py +++ b/src/icon.py @@ -105,9 +105,12 @@ class Icon(gobject.GObject): self.name=dt['id'] self.icon=dt['icon2'] self.sicon=None - self.cached_icons={} + self.clearAnimationCache() self.invalidate() + def clearAnimationCache(self): + self.cached_icons={} + def getSize(self): return(self.config.iconsize+self.config.iconspace) diff --git a/src/icongrid.py b/src/icongrid.py index ed592e6..fab0898 100755 --- a/src/icongrid.py +++ b/src/icongrid.py @@ -131,7 +131,7 @@ class IconGrid(object): #(gobject.GObject): def setAnimationEnable(self, value): if value: self.enableAnimation() - else + else: self.disableAnimation() def timerAngle(self): @@ -220,6 +220,12 @@ class IconGrid(object): #(gobject.GObject): return(ret) + def clearAnimationCache(self): + """ Clear animation cache, freeing memory """ + for x,y in self.icons: + ic=self.icons.get(x,y) + ic.clearAnimationCache() + def do_expose_event(self, event): cr=self.window.cairo_create() diff --git a/src/portrait.py b/src/portrait.py index 8e0b2e7..ea58c4b 100644 --- a/src/portrait.py +++ b/src/portrait.py @@ -24,8 +24,7 @@ import hildon import osso # Replace this with your own gettext() functionality -#import gpodder -#_ = gpodder.gettext +_ = str class FremantleRotation(object): @@ -40,10 +39,10 @@ class FremantleRotation(object): You can set the mode for rotation to AUTOMATIC (default), NEVER or ALWAYS with the set_mode() method. """ - AUTOMATIC, NEVER, ALWAYS = range(3) - MODE_CAPTIONS = ('Automatic', 'Landscape', 'Portrait') + # Human-readable captions for the above constants + MODE_CAPTIONS = (_('Automatic'), _('Landscape'), _('Portrait')) # Privately-used constants _PORTRAIT, _LANDSCAPE = ('portrait', 'landscape') @@ -60,16 +59,20 @@ class FremantleRotation(object): _KBD_OPEN = 'open' _KBD_CLOSED = 'closed' - def __init__(self, app_name, main_window=None, version='1.0', mode=0): + def __init__(self, app_name, main_window=None, version='1.0', mode=0, + dontrotate=False): """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) + dontrotate ... Don't rotate the window. (def: False) """ + self.dontrotate = dontrotate # V13 self._orientation = None self._main_window = main_window + self._stack = hildon.WindowStack.get_default() self._mode = -1 self._last_dbus_orientation = None self._keyboard_state = self._get_keyboard_state() @@ -88,11 +91,6 @@ class FremantleRotation(object): path='/org/freedesktop/Hal/devices/platform_slide') self.set_mode(mode) - self._send_mce_request(self._ENABLE_ACCEL) - - def set_mode(self, new_mode): - self._mode=new_mode - def get_mode(self): """Get the currently-set rotation mode @@ -100,6 +98,35 @@ class FremantleRotation(object): """ 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 and \ + self._keyboard_state != self._KBD_OPEN: + 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, \ @@ -116,7 +143,7 @@ class FremantleRotation(object): else: self._send_mce_request(self._DISABLE_ACCEL) - def NO_get_main_window(self): + 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 @@ -136,9 +163,6 @@ class FremantleRotation(object): # Ignore repeated requests return - if orientation == None: - return - flags = 0 if orientation != self._LANDSCAPE: @@ -147,14 +171,17 @@ class FremantleRotation(object): 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) + window = self._get_main_window() + if window is not None and self.dontrotate==False: + hildon.hildon_gtk_window_set_portrait_flags(window, flags) self._orientation = orientation self.on_orientation_changed(orientation) + def on_orientation_changed(self, orientation): + pass + def _get_keyboard_state(self): # For sbox, if the device does not exist assume that it's closed try: diff --git a/src/widget.py b/src/widget.py index 15f99d5..ac912e5 100755 --- a/src/widget.py +++ b/src/widget.py @@ -65,7 +65,8 @@ class DrlaunchPlugin(IconGrid, HomePluginItem, FremantleRotation): def __init__(self): IconGrid.__init__(self) HomePluginItem.__init__(self) - FremantleRotation.__init__(self, 'DrlaunchPlugin') + FremantleRotation.__init__(self, 'DrlaunchPlugin', + mode=FremantleRotation.AUTOMATIC, dontrotate=True) self.winConfig=None @@ -166,6 +167,10 @@ class DrlaunchPlugin(IconGrid, HomePluginItem, FremantleRotation): self.setSize(dt['size']) self.reloadIcons() + # Free memory that is used for animations if animations are disabled + if not dt['animate']: + self.clearAnimationCache() + self.queue_draw() def handle_click(self, sender, icon): diff --git a/src/win_config.py b/src/win_config.py index a003723..0d98eaa 100755 --- a/src/win_config.py +++ b/src/win_config.py @@ -31,36 +31,46 @@ from hildon import StackableWindow #from portrait import FremantleRotation #from xdg.IconTheme import getIconPath -#import config +import config import apps from icon import Icon, getIcon from icongrid import IconGridWidget from about import DlgAbout +from portrait import FremantleRotation -class WinConfig(StackableWindow): +class WinConfig(StackableWindow): #, FremantleRotation): def __init__(self, config, *args): StackableWindow.__init__(self) +# FremantleRotation.__init__(self, "DrlaunchPlugin", +# mode=FremantleRotation.AUTOMATIC) self.config=config self.setupUi() def setupUi(self): - self.set_title("DrLaunch Configuration") + """ + self.pa Main Pannable Area + self.col1 A VBox for the first column + self.col2 A VBox for the second column + self.w_igw The IGW in an alignment + """ + self.set_title("DrLaunch v" + config.version) self.pa=hildon.PannableArea() - self.add(self.pa) +# self.add(self.pa) self.pa.set_property('mov-mode', hildon.MOVEMENT_MODE_HORIZ) - hbox=gtk.HBox() - self.pa.add_with_viewport(hbox) +#1 hbox=gtk.HBox() +#1 self.pa.add_with_viewport(hbox) # Add the first column of options al=gtk.Alignment(yscale=0) - hbox.add(al) +#1 hbox.add(al) vbox=gtk.VBox() al.add(vbox) + self.col1=al maxsz=self.config.getMaxSize() @@ -122,7 +132,8 @@ class WinConfig(StackableWindow): vbox=gtk.VBox() al=gtk.Alignment(xalign=0, yalign=1, xscale=1) al.add(vbox) - hbox.add(al) + self.col2=al +#1 hbox.add(al) but=hildon.Button( gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL) @@ -139,7 +150,8 @@ class WinConfig(StackableWindow): al=gtk.Alignment(xalign=0, xscale=0) al.add(self.igw) al.set_padding(0, 0, 20, 0) - hbox.add(al) + self.w_igw=al +#1 hbox.add(al) self.igw.connect('long-press', self.slotLongpress) self.igw.connect('click', self.slotLongpress) @@ -151,6 +163,81 @@ class WinConfig(StackableWindow): self.setLongpress(self.config.getLongpress()) self.setAnimate(self.config.getAnimate()) + hbox=gtk.HBox() + hbox.add(self.col1) + hbox.add(self.col2) + hbox.add(self.w_igw) + self.pa.add_with_viewport(hbox) + + self.add(self.pa) + +# def setupUi(self, orientation): +# +# self.setupUi0() +# +# hbox=gtk.HBox() +# +# if orientation=='l': +# hbox.add(self.col1) +# hbox.add(self.col2) +# hbox.add(self.w_igw) +# else: +# vbox=gtk.VBox() +# hbox.add(vbox) +# vbox.add(self.col1) +# vbox.add(self.col2) +# hbox.add(self.w_igw) +# +# self.pa.add_with_viewport(hbox) +# +# if self.get_child()!=None: +# self.remove(self.get_child()) +# self.add(self.pa) +# self.pa.show_all() + + def setLayoutPortrait(self): + print "lo: p" + hbox=gtk.HBox() + + vbox=gtk.VBox() + hbox.add(vbox) + self.col1.reparent(vbox) + self.col2.reparent(vbox) + self.w_igw.reparent(hbox) + + r=self.pa.get_children()[0] + self.pa.remove(r) + r.destroy() + self.pa.add_with_viewport(hbox) + + self.pa.show_all() + + def setLayoutLandscape(self): + print "lo: l" + hbox=gtk.HBox() + + self.col1.reparent(hbox) + self.col2.reparent(hbox) + self.w_igw.reparent(hbox) + + r=self.pa.get_children()[0] + self.pa.remove(r) + r.destroy() + self.pa.add_with_viewport(hbox) + + self.pa.show_all() + + def on_orientation_changed(self, orientation): + # This is disabled for now since I've not found any reliable + # way for supporting orientation changes (#$#%$#*&% GTK) + return + + print "orch:", orientation + if orientation=='portrait': + self.setLayoutPortrait() + else: + self.setLayoutLandscape() + def slotLongpress(self, sender, icon): self.doConfig(icon) @@ -176,7 +263,7 @@ class WinConfig(StackableWindow): print "about" #dlg=DlgAbout() #dlg.run() - DlgAbout.present2() + DlgAbout.present2(self) # def slotButtonLongpress(self, sender): # but=self.buttonRequireLongpress