Support always and never rotation on Fremantle
This is the backend code, UI support will be added later on.
This commit is contained in:
parent
9796f9ffa9
commit
6d3a100b0e
2 changed files with 83 additions and 15 deletions
|
@ -22,34 +22,102 @@ import dbus.glib
|
|||
|
||||
import hildon
|
||||
|
||||
class FremantleAutoRotation(object):
|
||||
"""thp's automatic screen rotation for Maemo 5
|
||||
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.
|
||||
"""
|
||||
def __init__(self):
|
||||
AUTOMATIC, NEVER, ALWAYS = range(3)
|
||||
|
||||
# Privately-used constants
|
||||
_PORTRAIT, _LANDSCAPE = ('portrait', 'landscape')
|
||||
|
||||
def __init__(self, main_window=None):
|
||||
self._orientation = None
|
||||
self._main_window = main_window
|
||||
self._stack = hildon.WindowStack.get_default()
|
||||
self._mode = self.AUTOMATIC
|
||||
self._last_dbus_orientation = None
|
||||
system_bus = dbus.Bus.get_system()
|
||||
system_bus.add_signal_receiver(self.on_orientation_signal, \
|
||||
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')
|
||||
|
||||
def orientation_changed(self, orientation):
|
||||
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
|
||||
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)
|
||||
|
||||
self._mode = new_mode
|
||||
|
||||
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 == 'portrait':
|
||||
if orientation == self._PORTRAIT:
|
||||
flags |= hildon.PORTRAIT_MODE_REQUEST
|
||||
for window in self._stack.get_windows():
|
||||
|
||||
window = self._get_main_window()
|
||||
if window is not None:
|
||||
hildon.hildon_gtk_window_set_portrait_flags(window, flags)
|
||||
|
||||
def on_orientation_signal(self, orientation, stand, face, x, y, z):
|
||||
if orientation in ('portrait', 'landscape'):
|
||||
if orientation != self._orientation:
|
||||
self.orientation_changed(orientation)
|
||||
self._orientation = orientation
|
||||
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
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@ elif gpodder.ui.fremantle:
|
|||
from gpodder.gtkui.interface.common import Orientation
|
||||
have_trayicon = False
|
||||
|
||||
from gpodder.gtkui.frmntl.portrait import FremantleAutoRotation
|
||||
from gpodder.gtkui.frmntl.portrait import FremantleRotation
|
||||
|
||||
from gpodder.gtkui.interface.welcome import gPodderWelcome
|
||||
from gpodder.gtkui.interface.progress import ProgressIndicator
|
||||
|
@ -169,8 +169,8 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
self.main_window.set_app_menu(appmenu)
|
||||
self._fremantle_update_banner = None
|
||||
|
||||
# Activate application-wide automatic portrait orientation
|
||||
FremantleAutoRotation()
|
||||
# Initialize portrait mode / rotation manager
|
||||
self._fremantle_rotation = FremantleRotation(self.main_window)
|
||||
|
||||
self.bluetooth_available = False
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue