From df4c88e1a433f1a5c9d3443a448c580193a22c11 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 10 Jan 2011 18:43:32 -0600 Subject: [PATCH] Adjusting screen orientation code --- src/dialcentral_qt.py | 36 +++++++++++++++++++++++++++++++++++- src/dialogs.py | 5 +---- src/util/qui_utils.py | 49 +++++++++++++++++++++---------------------------- 3 files changed, 57 insertions(+), 33 deletions(-) diff --git a/src/dialcentral_qt.py b/src/dialcentral_qt.py index bb377c4..174f042 100755 --- a/src/dialcentral_qt.py +++ b/src/dialcentral_qt.py @@ -74,6 +74,12 @@ class Dialcentral(object): self._fullscreenAction.setShortcut(QtGui.QKeySequence("CTRL+Enter")) self._fullscreenAction.toggled.connect(self._on_toggle_fullscreen) + self._orientationAction = QtGui.QAction(None) + self._orientationAction.setText("Orientation") + self._orientationAction.setCheckable(True) + self._orientationAction.setShortcut(QtGui.QKeySequence("CTRL+o")) + self._orientationAction.toggled.connect(self._on_toggle_orientation) + self._logAction = QtGui.QAction(None) self._logAction.setText("Log") self._logAction.setShortcut(QtGui.QKeySequence("CTRL+l")) @@ -129,6 +135,7 @@ class Dialcentral(object): blobs = "", "" isFullscreen = False + isPortrait = qui_utils.screen_orientation() == QtCore.Qt.Vertical tabIndex = 0 try: blobs = [ @@ -137,6 +144,7 @@ class Dialcentral(object): ] isFullscreen = config.getboolean(constants.__pretty_app_name__, "fullscreen") tabIndex = config.getint(constants.__pretty_app_name__, "tab") + isPortrait = config.getboolean(constants.__pretty_app_name__, "portrait") except ConfigParser.NoOptionError, e: _moduleLogger.info( "Settings file %s is missing option %s" % ( @@ -183,6 +191,7 @@ class Dialcentral(object): ) self._mainWindow.set_default_credentials(*creds) self._fullscreenAction.setChecked(isFullscreen) + self._orientationAction.setChecked(isPortrait) self._mainWindow.set_current_tab(tabIndex) self._mainWindow.load_settings(config) @@ -193,6 +202,7 @@ class Dialcentral(object): config.add_section(constants.__pretty_app_name__) config.set(constants.__pretty_app_name__, "tab", str(self._mainWindow.get_current_tab())) config.set(constants.__pretty_app_name__, "fullscreen", str(self._fullscreenAction.isChecked())) + config.set(constants.__pretty_app_name__, "portrait", str(self._orientationAction.isChecked())) for i, value in enumerate(self._mainWindow.get_default_credentials()): blob = base64.b64encode(value) config.set(constants.__pretty_app_name__, "bin_blob_%i" % i, blob) @@ -231,6 +241,10 @@ class Dialcentral(object): return self._fullscreenAction @property + def orientationAction(self): + return self._orientationAction + + @property def logAction(self): return self._logAction @@ -284,6 +298,13 @@ class Dialcentral(object): @QtCore.pyqtSlot() @QtCore.pyqtSlot(bool) @misc_utils.log_exception(_moduleLogger) + def _on_toggle_orientation(self, checked = False): + for window in self._walk_children(): + window.set_orientation(checked) + + @QtCore.pyqtSlot() + @QtCore.pyqtSlot(bool) + @misc_utils.log_exception(_moduleLogger) def _on_log(self, checked = False): with open(constants._user_logpath_, "r") as f: logLines = f.xreadlines() @@ -473,7 +494,6 @@ class MainWindow(object): self._window = QtGui.QMainWindow(parent) self._window.setAttribute(QtCore.Qt.WA_DeleteOnClose, True) - qui_utils.set_autorient(self._window, True) qui_utils.set_stackable(self._window, True) self._window.setWindowTitle("%s" % constants.__pretty_app_name__) self._window.setCentralWidget(centralWidget) @@ -517,6 +537,7 @@ class MainWindow(object): self._window.addAction(self._closeWindowAction) self._window.addAction(self._app.quitAction) self._window.addAction(self._app.fullscreenAction) + self._window.addAction(self._app.orientationAction) else: fileMenu = self._window.menuBar().addMenu("&File") fileMenu.addAction(self._loginTabAction) @@ -532,10 +553,13 @@ class MainWindow(object): toolsMenu.addAction(self._importTabAction) toolsMenu.addAction(self._aboutAction) + self._window.addAction(self._app.orientationAction) + self._window.addAction(self._app.logAction) self._initialize_tab(self._tabWidget.currentIndex()) self.set_fullscreen(self._app.fullscreenAction.isChecked()) + self.set_orientation(self._app.orientationAction.isChecked()) @property def window(self): @@ -640,6 +664,16 @@ class MainWindow(object): for child in self.walk_children(): child.set_fullscreen(isFullscreen) + def set_orientation(self, isPortrait): + if isPortrait: + self._tabWidget.setTabPosition(QtGui.QTabWidget.South) + qui_utils.set_window_orientation(QtCore.Qt.Vertical) + else: + self._tabWidget.setTabPosition(QtGui.QTabWidget.West) + qui_utils.set_window_orientation(QtCore.Qt.Horizontal) + for child in self.walk_children(): + child.set_orientation(isPortrait) + def _initialize_tab(self, index): assert index < self.MAX_TABS, "Invalid tab" if not self._tabsContents[index].has_child(): diff --git a/src/dialogs.py b/src/dialogs.py index dcd6078..4bcf26c 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -43,7 +43,6 @@ class CredentialsDialog(object): self._dialog.setWindowTitle("Login") self._dialog.setLayout(self._layout) self._dialog.setAttribute(QtCore.Qt.WA_DeleteOnClose, False) - qui_utils.set_autorient(self._dialog, True) self._buttonLayout.accepted.connect(self._dialog.accept) self._buttonLayout.rejected.connect(self._dialog.reject) @@ -111,7 +110,6 @@ class AboutDialog(object): self._dialog = QtGui.QDialog() self._dialog.setWindowTitle("About") self._dialog.setLayout(self._layout) - qui_utils.set_autorient(self._dialog, True) self._buttonLayout.rejected.connect(self._dialog.reject) self._closeWindowAction = QtGui.QAction(None) @@ -210,7 +208,6 @@ class AccountDialog(object): self._dialog = QtGui.QDialog() self._dialog.setWindowTitle("Account") self._dialog.setLayout(self._layout) - qui_utils.set_autorient(self._dialog, True) self._buttonLayout.accepted.connect(self._dialog.accept) self._buttonLayout.rejected.connect(self._dialog.reject) @@ -418,7 +415,7 @@ class SMSEntryWindow(object): centralWidget.setLayout(self._layout) self._window = QtGui.QMainWindow(parent) - qui_utils.set_autorient(self._window, True) + qui_utils.set_window_orientation(QtCore.Qt.Horizontal) qui_utils.set_stackable(self._window, True) self._window.setWindowTitle("Contact") self._window.setCentralWidget(centralWidget) diff --git a/src/util/qui_utils.py b/src/util/qui_utils.py index d49eb75..2fd8e0c 100644 --- a/src/util/qui_utils.py +++ b/src/util/qui_utils.py @@ -272,7 +272,7 @@ def _null_set_autorient(window, isStackable): def _maemo_set_autorient(window, isStackable): - window.setAttribute(QtCore.Qt.WA_Maemo5StackedWindow, isStackable) + window.setAttribute(QtCore.Qt.WA_Maemo5AutoOrientation, isStackable) try: @@ -282,34 +282,35 @@ except AttributeError: set_autorient = _null_set_autorient -def _null_set_landscape(window, isStackable): - pass - - -def _maemo_set_landscape(window, isStackable): - window.setAttribute(QtCore.Qt.WA_Maemo5StackedWindow, isStackable) - - -try: - QtCore.Qt.WA_Maemo5LandscapeOrientation - set_landscape = _maemo_set_landscape -except AttributeError: - set_landscape = _null_set_landscape +def screen_orientation(): + geom = QtGui.QApplication.desktop().screenGeometry() + if geom.width() <= geom.height(): + return QtCore.Qt.Vertical + else: + return QtCore.Qt.Horizontal -def _null_set_portrait(window, isStackable): +def _null_set_window_orientation(window, orientation): pass -def _maemo_set_portrait(window, isStackable): - window.setAttribute(QtCore.Qt.WA_Maemo5StackedWindow, isStackable) +def _maemo_set_window_orientation(window, orientation): + if orientation == QtCore.Qt.Vertical: + newHint = QtCore.Qt.WA_Maemo5LandscapeOrientation + oldHint = QtCore.Qt.WA_Maemo5PortraitOrientation + elif orientation == QtCore.Qt.Horizontal: + oldHint = QtCore.Qt.WA_Maemo5LandscapeOrientation + newHint = QtCore.Qt.WA_Maemo5PortraitOrientation + window.setAttribute(oldHint, False) + window.setAttribute(newHint, True) try: + QtCore.Qt.WA_Maemo5LandscapeOrientation QtCore.Qt.WA_Maemo5PortraitOrientation - set_portrait = _maemo_set_portrait + set_window_orientation = _maemo_set_window_orientation except AttributeError: - set_portrait = _null_set_portrait + set_window_orientation = _null_set_window_orientation def _null_show_progress_indicator(window, isStackable): @@ -317,7 +318,7 @@ def _null_show_progress_indicator(window, isStackable): def _maemo_show_progress_indicator(window, isStackable): - window.setAttribute(QtCore.Qt.WA_Maemo5StackedWindow, isStackable) + window.setAttribute(QtCore.Qt.WA_Maemo5ShowProgressIndicator, isStackable) try: @@ -342,14 +343,6 @@ except AttributeError: mark_numbers_preferred = _null_mark_numbers_preferred -def screen_orientation(): - geom = QtGui.QApplication.desktop().screenGeometry() - if geom.width() <= geom.height(): - return QtCore.Qt.Vertical - else: - return QtCore.Qt.Horizontal - - def _null_get_theme_icon(iconNames, fallback = None): icon = fallback if fallback is not None else QtGui.QIcon() return icon -- 1.7.9.5