[PATCH 1/2] Mirror the GUI if an RTL language is chosen (#1008397)
Vratislav Podzimek
vpodzime at redhat.com
Tue Sep 17 07:47:54 UTC 2013
Some languages (or more precisely scripts) use left-to-right reading direction,
some use right-to-left reading direction. The UI should reflect that fact and
widgets should be arranged as if being mirrored.
Gtk itself handles the right direction for a chosen language, but it is set only
when the toolkit is initialized (Gtk.init()). Since we change language in the
GUI we need to set the direction manually later.
Until Gtk exports a function to get the default direction for the chosen
language [1], we need to use the same hack as the Gtk itself uses internally.
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1008821
Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
pyanaconda/ui/gui/spokes/welcome.py | 5 ++++-
pyanaconda/ui/gui/utils.py | 29 +++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/pyanaconda/ui/gui/spokes/welcome.py b/pyanaconda/ui/gui/spokes/welcome.py
index 7e79dc3..c6f411d 100644
--- a/pyanaconda/ui/gui/spokes/welcome.py
+++ b/pyanaconda/ui/gui/spokes/welcome.py
@@ -26,7 +26,7 @@ import langtable
from pyanaconda.ui.gui.hubs.summary import SummaryHub
from pyanaconda.ui.gui.spokes import StandaloneSpoke
-from pyanaconda.ui.gui.utils import enlightbox
+from pyanaconda.ui.gui.utils import enlightbox, setup_gtk_direction
from pyanaconda.ui.gui.spokes.lib.lang_locale_handler import LangLocaleHandler
from pyanaconda import localization
@@ -81,6 +81,9 @@ class WelcomeLanguageSpoke(LangLocaleHandler, StandaloneSpoke):
# current language
self.data.timezone.timezone = loc_timezones[0]
+ # setup Gtk direction (RTL/LTR) now that we have the language
+ # configuration applied
+ setup_gtk_direction()
self._set_keyboard_defaults(self.data.lang.lang)
def _set_keyboard_defaults(self, locale):
diff --git a/pyanaconda/ui/gui/utils.py b/pyanaconda/ui/gui/utils.py
index aa4078d..f7ad413 100644
--- a/pyanaconda/ui/gui/utils.py
+++ b/pyanaconda/ui/gui/utils.py
@@ -26,6 +26,7 @@ from pyanaconda.threads import threadMgr
from contextlib import contextmanager
from gi.repository import Gtk, GLib, AnacondaWidgets
import Queue
+import gettext
def gtk_call_once(func, *args):
"""Wrapper for GLib.idle_add call that ensures the func is called
@@ -194,3 +195,31 @@ def set_treeview_selection(treeview, item, col=0):
treeview.scroll_to_cell(path, use_align=True, row_align=0.5)
return itr
+
+def get_default_widget_direction():
+ """
+ Function to get default widget direction (RTL/LTR) for the current language
+ configuration.
+
+ XXX: this should be provided by the Gtk itself (#1008821)
+
+ :return: either Gtk.TextDirection.LTR or Gtk.TextDirection.RTL
+ :rtype: GtkTextDirection
+
+ """
+
+ # this is quite a hack, but it's exactly the same check Gtk uses internally
+ xlated = gettext.ldgettext("gtk30", "default:LTR")
+ if xlated == "default:LTR":
+ return Gtk.TextDirection.LTR
+ else:
+ return Gtk.TextDirection.RTL
+
+def setup_gtk_direction():
+ """
+ Set the right direction (RTL/LTR) of the Gtk widget's and their layout based
+ on the current language configuration.
+
+ """
+
+ Gtk.Widget.set_default_direction(get_default_widget_direction())
--
1.7.11.7
More information about the anaconda-patches
mailing list