def __init__(self, parent, app):
qwrappers.WindowWrapper.__init__(self, parent, app)
self._window.setWindowTitle("%s" % constants.__pretty_app_name__)
+ self._window.resized.connect(self._on_window_resized)
self._errorLog = self._app.errorLog
self._session = session.Session(self._errorLog, constants._data_path_)
self._initialize_tab(self._tabWidget.currentIndex())
self.set_fullscreen(self._app.fullscreenAction.isChecked())
- self.set_orientation(self._app.orientationAction.isChecked())
+ self.update_orientation(self._app.orientation)
def set_default_credentials(self, username, password):
self._defaultCredentials = username, password
def load_settings(self, config):
blobs = "", ""
isFullscreen = False
- isPortrait = qui_utils.screen_orientation() == QtCore.Qt.Vertical
+ orientation = self._app.orientation
tabIndex = 0
try:
blobs = [
]
isFullscreen = config.getboolean(constants.__pretty_app_name__, "fullscreen")
tabIndex = config.getint(constants.__pretty_app_name__, "tab")
- isPortrait = config.getboolean(constants.__pretty_app_name__, "portrait")
+ orientation = config.get(constants.__pretty_app_name__, "orientation")
except ConfigParser.NoOptionError, e:
_moduleLogger.info(
"Settings file %s is missing option %s" % (
)
self.set_default_credentials(*creds)
self._app.fullscreenAction.setChecked(isFullscreen)
- self._app.orientationAction.setChecked(isPortrait)
+ self.update_orientation(orientation)
self.set_current_tab(tabIndex)
backendId = 2 # For backwards compatibility
config.add_section(constants.__pretty_app_name__)
config.set(constants.__pretty_app_name__, "tab", str(self.get_current_tab()))
config.set(constants.__pretty_app_name__, "fullscreen", str(self._app.fullscreenAction.isChecked()))
- config.set(constants.__pretty_app_name__, "portrait", str(self._app.orientationAction.isChecked()))
+ config.set(constants.__pretty_app_name__, "orientation", str(self._app.orientation))
for i, value in enumerate(self.get_default_credentials()):
blob = base64.b64encode(value)
config.set(constants.__pretty_app_name__, "bin_blob_%i" % i, blob)
for settingName, settingValue in tabSettings.iteritems():
config.set(sectionName, settingName, settingValue)
- def set_orientation(self, isPortrait):
- qwrappers.WindowWrapper.set_orientation(self, isPortrait)
- if isPortrait:
- self._tabWidget.setTabPosition(QtGui.QTabWidget.South)
- else:
+ def update_orientation(self, orientation):
+ qwrappers.WindowWrapper.update_orientation(self, orientation)
+ windowOrientation = self.idealWindowOrientation
+ if windowOrientation == QtCore.Qt.Horizontal:
self._tabWidget.setTabPosition(QtGui.QTabWidget.West)
+ else:
+ self._tabWidget.setTabPosition(QtGui.QTabWidget.South)
def _initialize_tab(self, index):
assert index < self.MAX_TABS, "Invalid tab"
@qt_compat.Slot()
@misc_utils.log_exception(_moduleLogger)
+ def _on_window_resized(self):
+ with qui_utils.notify_error(self._app.errorLog):
+ windowOrientation = self.idealWindowOrientation
+ if windowOrientation == QtCore.Qt.Horizontal:
+ self._tabWidget.setTabPosition(QtGui.QTabWidget.West)
+ else:
+ self._tabWidget.setTabPosition(QtGui.QTabWidget.South)
+
+ @qt_compat.Slot()
+ @misc_utils.log_exception(_moduleLogger)
def _on_new_message_alert(self):
with qui_utils.notify_error(self._errorLog):
if self._app.alarmHandler.alarmType == self._app.alarmHandler.ALARM_APPLICATION:
self._update_letter_count()
self._update_target_fields()
self.set_fullscreen(self._app.fullscreenAction.isChecked())
- self.set_orientation(self._app.orientationAction.isChecked())
+ self.update_orientation(self._app.orientation)
def close(self):
if self._window is None:
except RuntimeError:
_moduleLogger.exception("Oh well")
- def set_orientation(self, isPortrait):
- qwrappers.WindowWrapper.set_orientation(self, isPortrait)
+ def update_orientation(self, orientation):
+ qwrappers.WindowWrapper.update_orientation(self, orientation)
self._scroll_to_bottom()
def _update_letter_count(self):
@qt_compat.Slot()
@misc_utils.log_exception(_moduleLogger)
- def _on_window_resized(self, checked = True):
+ def _on_window_resized(self):
with qui_utils.notify_error(self._app.errorLog):
self._scroll_to_bottom()
set_stackable = _null_set_stackable
-def _null_set_autorient(window, isStackable):
+def _null_set_autorient(window, doAutoOrient):
pass
-def _maemo_set_autorient(window, isStackable):
- window.setAttribute(QtCore.Qt.WA_Maemo5AutoOrientation, isStackable)
+def _maemo_set_autorient(window, doAutoOrient):
+ window.setAttribute(QtCore.Qt.WA_Maemo5AutoOrientation, doAutoOrient)
try:
def _maemo_set_window_orientation(window, orientation):
if orientation == QtCore.Qt.Vertical:
- oldHint = QtCore.Qt.WA_Maemo5LandscapeOrientation
- newHint = QtCore.Qt.WA_Maemo5PortraitOrientation
+ window.setAttribute(QtCore.Qt.WA_Maemo5LandscapeOrientation, False)
+ window.setAttribute(QtCore.Qt.WA_Maemo5PortraitOrientation, True)
elif orientation == QtCore.Qt.Horizontal:
- oldHint = QtCore.Qt.WA_Maemo5PortraitOrientation
- newHint = QtCore.Qt.WA_Maemo5LandscapeOrientation
- window.setAttribute(oldHint, False)
- window.setAttribute(newHint, True)
+ window.setAttribute(QtCore.Qt.WA_Maemo5LandscapeOrientation, True)
+ window.setAttribute(QtCore.Qt.WA_Maemo5PortraitOrientation, False)
+ elif orientation is None:
+ window.setAttribute(QtCore.Qt.WA_Maemo5LandscapeOrientation, True)
+ window.setAttribute(QtCore.Qt.WA_Maemo5PortraitOrientation, True)
+ else:
+ raise RuntimeError("Unknown orientation: %r" % orientation)
try:
class ApplicationWrapper(object):
+ DEFAULT_ORIENTATION = "Default"
+ AUTO_ORIENTATION = "Auto"
+ LANDSCAPE_ORIENTATION = "Landscape"
+ PORTRAIT_ORIENTATION = "Portrait"
+
def __init__(self, qapp, constants):
self._constants = constants
self._qapp = qapp
self._fullscreenAction.setShortcut(QtGui.QKeySequence("CTRL+Enter"))
self._fullscreenAction.toggled.connect(self._on_toggle_fullscreen)
+ self._orientation = self.DEFAULT_ORIENTATION
self._orientationAction = QtGui.QAction(None)
- self._orientationAction.setText("Orientation")
+ self._orientationAction.setText("Next Orientation")
self._orientationAction.setCheckable(True)
self._orientationAction.setShortcut(QtGui.QKeySequence("CTRL+o"))
- self._orientationAction.toggled.connect(self._on_toggle_orientation)
+ self._orientationAction.triggered.connect(self._on_next_orientation)
self._logAction = QtGui.QAction(None)
self._logAction.setText("Log")
return self._orientationAction
@property
+ def orientation(self):
+ return self._orientation
+
+ @property
def logAction(self):
return self._logAction
def quitAction(self):
return self._quitAction
+ @classmethod
+ def _next_orientation(cls, current):
+ return {
+ cls.DEFAULT_ORIENTATION: cls.AUTO_ORIENTATION,
+ cls.AUTO_ORIENTATION: cls.LANDSCAPE_ORIENTATION,
+ cls.LANDSCAPE_ORIENTATION: cls.PORTRAIT_ORIENTATION,
+ cls.PORTRAIT_ORIENTATION: cls.DEFAULT_ORIENTATION,
+ }[current]
+
def _close_windows(self):
if self._mainWindow is not None:
self.save_settings()
self._mainWindow.set_fullscreen(checked)
@misc_utils.log_exception(_moduleLogger)
- def _on_toggle_orientation(self, checked = False):
+ def _on_next_orientation(self, checked = False):
with qui_utils.notify_error(self._errorLog):
- self._mainWindow.set_orientation(checked)
+ self._orientation = self._next_orientation(self._orientation)
+ self._mainWindow.update_orientation(self._orientation)
@misc_utils.log_exception(_moduleLogger)
def _on_about(self, checked = True):
def window(self):
return self._window
+ @property
+ def windowOrientation(self):
+ geom = self._window.size()
+ if geom.width() <= geom.height():
+ return QtCore.Qt.Vertical
+ else:
+ return QtCore.Qt.Horizontal
+
+ @property
+ def idealWindowOrientation(self):
+ if self._app.orientation == self._app.LANDSCAPE_ORIENTATION:
+ windowOrientation = QtCore.Qt.Horizontal
+ elif self._app.orientation == self._app.PORTRAIT_ORIENTATION:
+ windowOrientation = QtCore.Qt.Vertical
+ else:
+ windowOrientation = self.windowOrientation
+ return windowOrientation
+
def walk_children(self):
return ()
for child in self.walk_children():
child.set_fullscreen(isFullscreen)
- def set_orientation(self, isPortrait):
- if isPortrait:
+ def update_orientation(self, orientation):
+ if orientation == self._app.DEFAULT_ORIENTATION:
+ qui_utils.set_autorient(self.window, False)
+ qui_utils.set_window_orientation(self.window, None)
+ elif orientation == self._app.AUTO_ORIENTATION:
+ qui_utils.set_autorient(self.window, True)
+ qui_utils.set_window_orientation(self.window, None)
+ elif orientation == self._app.LANDSCAPE_ORIENTATION:
+ qui_utils.set_autorient(self.window, False)
+ qui_utils.set_window_orientation(self.window, QtCore.Qt.Horizontal)
+ elif orientation == self._app.PORTRAIT_ORIENTATION:
+ qui_utils.set_autorient(self.window, False)
qui_utils.set_window_orientation(self.window, QtCore.Qt.Vertical)
else:
- qui_utils.set_window_orientation(self.window, QtCore.Qt.Horizontal)
+ raise RuntimeError("Unknown orientation: %r" % orientation)
for child in self.walk_children():
- child.set_orientation(isPortrait)
+ child.update_orientation(orientation)
@misc_utils.log_exception(_moduleLogger)
def _on_child_close(self, obj = None):