Adding rotation support through updated hildon support
authorEd Page <eopage@byu.net>
Thu, 25 Mar 2010 02:40:53 +0000 (21:40 -0500)
committerEd Page <eopage@byu.net>
Thu, 25 Mar 2010 02:41:18 +0000 (21:41 -0500)
src/backends/gvoice.py
src/dc_glade.py
src/gv_views.py
src/hildonize.py
src/null_views.py

index 5952853..19275f8 100755 (executable)
@@ -48,7 +48,7 @@ except ImportError:
 import browser_emu
 
 
-_moduleLogger = logging.getLogger("gvoice")
+_moduleLogger = logging.getLogger(__name__)
 
 
 class NetworkError(RuntimeError):
index 40b5508..47d72eb 100755 (executable)
@@ -119,6 +119,7 @@ class Dialcentral(object):
                self._smsEntryWindow = None
 
                self._isFullScreen = False
+               self.__isPortrait = False
                self._app = hildonize.get_app_class()()
                self._window = hildonize.hildonize_window(self._app, self._window)
                hildonize.hildonize_text_entry(self._widgetTree.get_widget("usernameentry"))
@@ -519,6 +520,7 @@ class Dialcentral(object):
 
                self._accountViews[self._selectedBackendId].update()
                self._refresh_active_tab()
+               self._refresh_orientation()
 
        def load_settings(self, config):
                """
@@ -545,6 +547,14 @@ class Dialcentral(object):
                        isFullscreen = config.getboolean(constants.__pretty_app_name__, "fullscreen")
                        if isFullscreen:
                                self._window.fullscreen()
+
+                       isPortrait = config.getboolean(constants.__pretty_app_name__, "portrait")
+                       if isPortrait ^ self.__isPortrait:
+                               if isPortrait:
+                                       orientation = gtk.ORIENTATION_VERTICAL
+                               else:
+                                       orientation = gtk.ORIENTATION_HORIZONTAL
+                               self.set_orientation(orientation)
                except ConfigParser.NoOptionError, e:
                        _moduleLogger.exception(
                                "Settings file %s is missing section %s" % (
@@ -585,27 +595,6 @@ class Dialcentral(object):
                                        ),
                                )
 
-               try:
-                       previousOrientation = config.getint(constants.__pretty_app_name__, "orientation")
-                       if previousOrientation == gtk.ORIENTATION_HORIZONTAL:
-                               hildonize.window_to_landscape(self._window)
-                       elif previousOrientation == gtk.ORIENTATION_VERTICAL:
-                               hildonize.window_to_portrait(self._window)
-               except ConfigParser.NoOptionError, e:
-                       _moduleLogger.exception(
-                               "Settings file %s is missing section %s" % (
-                                       constants._user_settings_,
-                                       e.section,
-                               ),
-                       )
-               except ConfigParser.NoSectionError, e:
-                       _moduleLogger.exception(
-                               "Settings file %s is missing section %s" % (
-                                       constants._user_settings_,
-                                       e.section,
-                               ),
-                       )
-
        def save_settings(self, config):
                """
                @note Thread Agnostic
@@ -619,7 +608,7 @@ class Dialcentral(object):
 
                config.add_section(constants.__pretty_app_name__)
                config.set(constants.__pretty_app_name__, "active", str(backend))
-               config.set(constants.__pretty_app_name__, "orientation", str(int(gtk_toolbox.get_screen_orientation())))
+               config.set(constants.__pretty_app_name__, "portrait", str(self.__isPortrait))
                config.set(constants.__pretty_app_name__, "fullscreen", str(self._isFullScreen))
                for i, value in enumerate(self._credentials):
                        blob = base64.b64encode(value)
@@ -661,6 +650,36 @@ class Dialcentral(object):
                        if self._ledHandler is not None:
                                self._ledHandler.off()
 
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       hildonize.window_to_portrait(self._window)
+                       self._notebook.set_property("tab-pos", gtk.POS_BOTTOM)
+                       self.__isPortrait = True
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       hildonize.window_to_landscape(self._window)
+                       self._notebook.set_property("tab-pos", gtk.POS_LEFT)
+                       self.__isPortrait = False
+               else:
+                       raise NotImplementedError(orientation)
+
+       def get_orientation(self):
+               return gtk.ORIENTATION_VERTICAL if self.__isPortrait else gtk.ORIENTATION_HORIZONTAL
+
+       def _toggle_rotate(self):
+               if self.__isPortrait:
+                       self.set_orientation(gtk.ORIENTATION_HORIZONTAL)
+               else:
+                       self.set_orientation(gtk.ORIENTATION_VERTICAL)
+
+       def _refresh_orientation(self):
+               """
+               Mostly meant to be used when switching backends
+               """
+               if self.__isPortrait:
+                       self.set_orientation(gtk.ORIENTATION_VERTICAL)
+               else:
+                       self.set_orientation(gtk.ORIENTATION_HORIZONTAL)
+
        @gtk_toolbox.log_exception(_moduleLogger)
        def _on_close(self, *args, **kwds):
                try:
@@ -755,6 +774,9 @@ class Dialcentral(object):
                                event.get_state() & gtk.gdk.CONTROL_MASK
                        ):
                                self._window.destroy()
+                       elif event.keyval == gtk.keysyms.o and event.get_state() & gtk.gdk.CONTROL_MASK:
+                               self._toggle_rotate()
+                               return True
                        elif event.keyval == gtk.keysyms.r and event.get_state() & gtk.gdk.CONTROL_MASK:
                                self._refresh_active_tab()
                        elif event.keyval == gtk.keysyms.i and event.get_state() & gtk.gdk.CONTROL_MASK:
index caf12ac..be6b127 100644 (file)
@@ -676,6 +676,14 @@ class Dialpad(object):
                """
                pass
 
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       pass
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       pass
+               else:
+                       raise NotImplementedError(orientation)
+
        def _on_key_press(self, widget, event):
                try:
                        if event.keyval == ord("v") and event.get_state() & gtk.gdk.CONTROL_MASK:
@@ -872,6 +880,14 @@ class AccountInfo(object):
                config.set(section, "notifyOnVoicemail", repr(self._notifyOnVoicemail))
                config.set(section, "notifyOnSms", repr(self._notifyOnSms))
 
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       pass
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       pass
+               else:
+                       raise NotImplementedError(orientation)
+
        def _populate_callback_combo(self):
                self._isPopulated = True
                del self._callbackList[:]
@@ -1168,6 +1184,14 @@ class CallHistoryView(object):
                """
                config.set(sectionName, "filter", self._selectedFilter)
 
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       pass
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       pass
+               else:
+                       raise NotImplementedError(orientation)
+
        def _is_history_visible(self, model, iter):
                try:
                        action = model.get_value(iter, self.ACTION_IDX)
@@ -1404,6 +1428,14 @@ class MessagesView(object):
                config.set(sectionName, "status", self._messageStatus)
                config.set(sectionName, "type", self._messageType)
 
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       pass
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       pass
+               else:
+                       raise NotImplementedError(orientation)
+
        def _is_message_visible(self, model, iter):
                try:
                        message = model.get_value(iter, self.MESSAGE_DATA_IDX)
@@ -1701,6 +1733,14 @@ class ContactsView(object):
        def save_settings(self, config, sectionName):
                config.set(sectionName, "selectedAddressbook", str(self._selectedComboIndex))
 
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       pass
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       pass
+               else:
+                       raise NotImplementedError(orientation)
+
        def _idly_populate_contactsview(self):
                with gtk_toolbox.gtk_lock():
                        banner = hildonize.show_busy_banner_start(self._window, "Loading Contacts")
index 09ee705..77d585a 100644 (file)
@@ -277,30 +277,16 @@ else:
        hildonize_text_entry = _null_hildonize_text_entry
 
 
-def _hildon_mark_window_rotatable(window):
-       # gtk documentation is unclear whether this does a "=" or a "|="
-       window.set_flags(hildon.HILDON_PORTRAIT_MODE_SUPPORT)
-
-
-def _null_mark_window_rotatable(window):
-       pass
-
-
-try:
-       hildon.HILDON_PORTRAIT_MODE_SUPPORT
-       mark_window_rotatable = _hildon_mark_window_rotatable
-except AttributeError:
-       mark_window_rotatable = _null_mark_window_rotatable
-
-
 def _hildon_window_to_portrait(window):
        # gtk documentation is unclear whether this does a "=" or a "|="
-       window.set_flags(hildon.HILDON_PORTRAIT_MODE_SUPPORT)
+       flags = hildon.PORTRAIT_MODE_SUPPORT | hildon.PORTRAIT_MODE_REQUEST
+       hildon.hildon_gtk_window_set_portrait_flags(window, flags)
 
 
 def _hildon_window_to_landscape(window):
        # gtk documentation is unclear whether this does a "=" or a "&= ~"
-       window.unset_flags(hildon.HILDON_PORTRAIT_MODE_REQUEST)
+       flags = hildon.PORTRAIT_MODE_SUPPORT
+       hildon.hildon_gtk_window_set_portrait_flags(window, flags)
 
 
 def _null_window_to_portrait(window):
@@ -312,8 +298,9 @@ def _null_window_to_landscape(window):
 
 
 try:
-       hildon.HILDON_PORTRAIT_MODE_SUPPORT
-       hildon.HILDON_PORTRAIT_MODE_REQUEST
+       hildon.PORTRAIT_MODE_SUPPORT
+       hildon.PORTRAIT_MODE_REQUEST
+       hildon.hildon_gtk_window_set_portrait_flags
 
        window_to_portrait = _hildon_window_to_portrait
        window_to_landscape = _hildon_window_to_landscape
index 777aba6..2299b28 100644 (file)
@@ -53,6 +53,14 @@ class Dialpad(object):
                """
                pass
 
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       pass
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       pass
+               else:
+                       raise NotImplementedError(orientation)
+
 
 class AccountInfo(object):
 
@@ -111,6 +119,14 @@ class AccountInfo(object):
                """
                pass
 
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       pass
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       pass
+               else:
+                       raise NotImplementedError(orientation)
+
 
 class CallHistoryView(object):
 
@@ -143,6 +159,14 @@ class CallHistoryView(object):
                """
                pass
 
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       pass
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       pass
+               else:
+                       raise NotImplementedError(orientation)
+
 
 class MessagesView(object):
 
@@ -178,6 +202,14 @@ class MessagesView(object):
                """
                pass
 
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       pass
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       pass
+               else:
+                       raise NotImplementedError(orientation)
+
 
 class ContactsView(object):
 
@@ -209,3 +241,11 @@ class ContactsView(object):
                @note Thread Agnostic
                """
                pass
+
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       pass
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       pass
+               else:
+                       raise NotImplementedError(orientation)