For some languages (or more precisely scripts) the GUI should be mirrored to reflect the reading direction. Gtk handles that automatically, but... (see the patches).
Once Gtk provides a function to get default widget direction for current language configuration [1], we will get rid of the hacky parts.
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1008821
Vratislav Podzimek (2): Mirror the GUI if an RTL language is chosen (#1008397) Render the right arrow based on the widget direction (#1008397)
data/pixmaps/left-arrow-icon.png | Bin 0 -> 286 bytes .../ui/gui/spokes/lib/lang_locale_handler.py | 9 ++++--- pyanaconda/ui/gui/spokes/welcome.py | 5 +++- pyanaconda/ui/gui/utils.py | 29 +++++++++++++++++++++ widgets/src/MountpointSelector.c | 15 ++++++++++- 5 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 data/pixmaps/left-arrow-icon.png
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@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())
LTR langauges should have a right arrow, RTL languages should have a left arrow.
Signed-off-by: Vratislav Podzimek vpodzime@redhat.com --- data/pixmaps/left-arrow-icon.png | Bin 0 -> 286 bytes pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py | 9 ++++++--- widgets/src/MountpointSelector.c | 15 ++++++++++++++- 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 data/pixmaps/left-arrow-icon.png
diff --git a/data/pixmaps/left-arrow-icon.png b/data/pixmaps/left-arrow-icon.png new file mode 100644 index 0000000..fc25a91 Binary files /dev/null and b/data/pixmaps/left-arrow-icon.png differ
diff --git a/pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py b/pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py index dea6bef..86c2cd0 100644 --- a/pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py +++ b/pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py @@ -27,7 +27,7 @@ screens handling languages or locales configuration. from gi.repository import Gtk, Pango from pyanaconda import localization from pyanaconda.iutil import strip_accents -from pyanaconda.ui.gui.utils import set_treeview_selection +from pyanaconda.ui.gui.utils import set_treeview_selection, get_default_widget_direction
class LangLocaleHandler(object): """ @@ -51,8 +51,11 @@ class LangLocaleHandler(object): self._localeSelection = None
def initialize(self): - # Render a right arrow for the chosen language - self._right_arrow = Gtk.Image.new_from_file("/usr/share/anaconda/pixmaps/right-arrow-icon.png") + # Render an arrow for the chosen language + if get_default_widget_direction() == Gtk.TextDirection.LTR: + self._right_arrow = Gtk.Image.new_from_file("/usr/share/anaconda/pixmaps/right-arrow-icon.png") + else: + self._right_arrow = Gtk.Image.new_from_file("/usr/share/anaconda/pixmaps/left-arrow-icon.png") self._langSelectedColumn.set_cell_data_func(self._langSelectedRenderer, self._render_lang_selected)
diff --git a/widgets/src/MountpointSelector.c b/widgets/src/MountpointSelector.c index 726b42e..9c8e61c 100644 --- a/widgets/src/MountpointSelector.c +++ b/widgets/src/MountpointSelector.c @@ -21,6 +21,7 @@ #include <gdk/gdk.h> #include <glib.h> #include <glib/gstdio.h> +#include <gettext.h>
#include "MountpointSelector.h" #include "intl.h" @@ -166,6 +167,15 @@ static void format_name_label(AnacondaMountpointSelector *widget, const char *va g_free(markup); }
+/* XXX: this should be provided by the Gtk itself (#1008821) */ +static GtkTextDirection get_default_widget_direction() { + const char *xlated = g_dgettext("gtk30", "default:LTR"); + if (strcmp (xlated, "default:RTL") == 0) + return GTK_TEXT_DIR_RTL; + else + return GTK_TEXT_DIR_LTR; +} + static void anaconda_mountpoint_selector_init(AnacondaMountpointSelector *mountpoint) { mountpoint->priv = G_TYPE_INSTANCE_GET_PRIVATE(mountpoint, ANACONDA_TYPE_MOUNTPOINT_SELECTOR, @@ -192,7 +202,10 @@ static void anaconda_mountpoint_selector_init(AnacondaMountpointSelector *mountp * gtk_image_new_from_file will just display a broken image icon in that * case. That's good enough error notification. */ - mountpoint->priv->arrow = gtk_image_new_from_file("/usr/share/anaconda/pixmaps/right-arrow-icon.png"); + if (get_default_widget_direction() == GTK_TEXT_DIR_LTR) + mountpoint->priv->arrow = gtk_image_new_from_file("/usr/share/anaconda/pixmaps/right-arrow-icon.png"); + else + mountpoint->priv->arrow = gtk_image_new_from_file("/usr/share/anaconda/pixmaps/left-arrow-icon.png"); gtk_widget_set_no_show_all(GTK_WIDGET(mountpoint->priv->arrow), TRUE);
/* Set some properties. */
@@ -51,8 +51,11 @@ class LangLocaleHandler(object): self._localeSelection = None
def initialize(self):
# Render a right arrow for the chosen languageself._right_arrow = Gtk.Image.new_from_file("/usr/share/anaconda/pixmaps/right-arrow-icon.png")
# Render an arrow for the chosen languageif get_default_widget_direction() == Gtk.TextDirection.LTR:self._right_arrow = Gtk.Image.new_from_file("/usr/share/anaconda/pixmaps/right-arrow-icon.png")else:self._right_arrow = Gtk.Image.new_from_file("/usr/share/anaconda/pixmaps/left-arrow-icon.png") self._langSelectedColumn.set_cell_data_func(self._langSelectedRenderer, self._render_lang_selected)
It'd be a little less confusing to just have the variable named self._arrow here, but ACK otherwise.
- Chris
On Tue, 2013-09-17 at 17:24 -0400, Chris Lumens wrote:
@@ -51,8 +51,11 @@ class LangLocaleHandler(object): self._localeSelection = None
def initialize(self):
# Render a right arrow for the chosen languageself._right_arrow = Gtk.Image.new_from_file("/usr/share/anaconda/pixmaps/right-arrow-icon.png")
# Render an arrow for the chosen languageif get_default_widget_direction() == Gtk.TextDirection.LTR:self._right_arrow = Gtk.Image.new_from_file("/usr/share/anaconda/pixmaps/right-arrow-icon.png")else:self._right_arrow = Gtk.Image.new_from_file("/usr/share/anaconda/pixmaps/left-arrow-icon.png") self._langSelectedColumn.set_cell_data_func(self._langSelectedRenderer, self._render_lang_selected)It'd be a little less confusing to just have the variable named self._arrow here, but ACK otherwise.
Good point, fixing locally.
By the way, this is how the hub looks with Arabic chosen:
http://vpodzime.fedorapeople.org/anaconda_mirrored.png
anaconda-patches@lists.fedorahosted.org