class LLH(unittest.TestCase):
    def setUp(self):
        self.llh = LangLocaleHandler()
        self.llh._languageStoreFilter = mock.Mock()
        self.llh._langSelectedRenderer = mock.Mock()
        self.llh._langSelectedColumn = mock.Mock()
        self.llh._add_language = mock.Mock()

        self.orig_anaconda_widgets_data = os.environ.get("ANACONDA_WIDGETS_DATA", "")
        if not "ANACONDA_WIDGETS_DATA" in os.environ:
            widgets_data = os.path.dirname(os.path.abspath(__file__))
            widgets_data = os.path.dirname(os.path.dirname(widgets_data))
            widgets_data = os.path.join(widgets_data, "widgets", "data")
            # pylint: disable=environment-modify
            os.environ["ANACONDA_WIDGETS_DATA"] = widgets_data

    def tearDown(self):
        # pylint: disable=environment-modify
        os.environ["ANACONDA_WIDGETS_DATA"] = self.orig_anaconda_widgets_data

    def anaconda_widgets_data_test(self):
        """Test if ANACONDA_WIDGETS_DATA is used if specified."""
        self.llh.initialize()
        self.assertEqual(self.llh._right_arrow.get_property('file').find("/usr/share/anaconda"), -1)
        self.assertEqual(self.llh._left_arrow.get_property('file').find("/usr/share/anaconda"), -1)
class LLH(unittest.TestCase):
    def setUp(self):
        self.llh = LangLocaleHandler()
        self.llh._languageStoreFilter = mock.Mock()
        self.llh._langSelectedRenderer = mock.Mock()
        self.llh._langSelectedColumn = mock.Mock()
        self.llh._add_language = mock.Mock()

        self.orig_anaconda_widgets_data = os.environ.get(
            "ANACONDA_WIDGETS_DATA", "")
        if not "ANACONDA_WIDGETS_DATA" in os.environ:
            widgets_data = os.path.dirname(os.path.abspath(__file__))
            widgets_data = os.path.dirname(os.path.dirname(widgets_data))
            widgets_data = os.path.join(widgets_data, "widgets", "data")
            # pylint: disable=environment-modify
            os.environ["ANACONDA_WIDGETS_DATA"] = widgets_data

    def tearDown(self):
        # pylint: disable=environment-modify
        os.environ["ANACONDA_WIDGETS_DATA"] = self.orig_anaconda_widgets_data

    def anaconda_widgets_data_test(self):
        """Test if ANACONDA_WIDGETS_DATA is used if specified."""
        self.llh.initialize()
        self.assertEqual(
            self.llh._right_arrow.get_property('file').find(
                "/usr/share/anaconda"), -1)
        self.assertEqual(
            self.llh._left_arrow.get_property('file').find(
                "/usr/share/anaconda"), -1)
Esempio n. 3
0
    def initialize(self):
        self._languageStore = self.builder.get_object("languageStore")
        self._languageEntry = self.builder.get_object("languageEntry")
        self._languageStoreFilter = self.builder.get_object(
            "languageStoreFilter")
        self._langView = self.builder.get_object("languageView")
        self._langSelectedRenderer = self.builder.get_object(
            "langSelectedRenderer")
        self._langSelectedColumn = self.builder.get_object(
            "langSelectedColumn")
        self._langSelection = self.builder.get_object("languageViewSelection")
        self._localeStore = self.builder.get_object("localeStore")
        self._localeView = self.builder.get_object("localeView")

        LangLocaleHandler.initialize(self)

        # mark selected locales and languages with selected locales bold
        localeNativeColumn = self.builder.get_object("localeNativeName")
        localeNativeNameRenderer = self.builder.get_object(
            "localeNativeNameRenderer")
        localeNativeColumn.set_cell_data_func(localeNativeNameRenderer,
                                              self._mark_selected_locale_bold)

        for col, rend in [("nativeName", "nativeNameRenderer"),
                          ("englishName", "englishNameRenderer")]:
            column = self.builder.get_object(col)
            renderer = self.builder.get_object(rend)
            column.set_cell_data_func(renderer,
                                      self._mark_selected_language_bold)
Esempio n. 4
0
    def initialize(self):
        self._languageStore = self.builder.get_object("languageStore")
        self._languageEntry = self.builder.get_object("languageEntry")
        self._languageStoreFilter = self.builder.get_object("languageStoreFilter")
        self._langView = self.builder.get_object("languageView")
        self._langSelectedRenderer = self.builder.get_object("langSelectedRenderer")
        self._langSelectedColumn = self.builder.get_object("langSelectedColumn")
        self._langSelection = self.builder.get_object("languageViewSelection")
        self._localeStore = self.builder.get_object("localeStore")
        self._localeView = self.builder.get_object("localeView")

        LangLocaleHandler.initialize(self)

        # mark selected locales and languages with selected locales bold
        localeNativeColumn = self.builder.get_object("localeNativeName")
        localeNativeNameRenderer = self.builder.get_object("localeNativeNameRenderer")
        override_cell_property(localeNativeColumn, localeNativeNameRenderer, "weight", self._mark_selected_locale_bold)

        languageNameColumn = self.builder.get_object("nameColumn")
        nativeNameRenderer = self.builder.get_object("nativeNameRenderer")
        englishNameRenderer = self.builder.get_object("englishNameRenderer")
        override_cell_property(languageNameColumn, nativeNameRenderer, "weight", self._mark_selected_language_bold)
        override_cell_property(languageNameColumn, englishNameRenderer, "weight", self._mark_selected_language_bold)

        # If a language has selected locales, highlight every column so that
        # the row appears highlighted
        for col in self._langView.get_columns():
            for rend in col.get_cells():
                override_cell_property(col, rend, "cell-background-rgba", self._highlight_selected_language)

        # and also set an icon so that we don't depend on a color to convey information
        highlightedColumn = self.builder.get_object("highlighted")
        highlightedRenderer = self.builder.get_object("highlightedRenderer")
        override_cell_property(highlightedColumn, highlightedRenderer, "icon-name", self._render_lang_highlighted)
    def initialize(self):
        self.initialize_start()
        self._languageStore = self.builder.get_object("languageStore")
        self._languageEntry = self.builder.get_object("languageEntry")
        self._languageStoreFilter = self.builder.get_object(
            "languageStoreFilter")
        self._langView = self.builder.get_object("languageView")
        self._langSelectedRenderer = self.builder.get_object(
            "langSelectedRenderer")
        self._langSelectedColumn = self.builder.get_object(
            "langSelectedColumn")
        self._langSelection = self.builder.get_object("languageViewSelection")
        self._localeStore = self.builder.get_object("localeStore")
        self._localeView = self.builder.get_object("localeView")

        LangLocaleHandler.initialize(self)

        # mark selected locales and languages with selected locales bold
        localeNativeColumn = self.builder.get_object("localeNativeName")
        localeNativeNameRenderer = self.builder.get_object(
            "localeNativeNameRenderer")
        override_cell_property(localeNativeColumn, localeNativeNameRenderer,
                               "weight", self._mark_selected_locale_bold)

        languageNameColumn = self.builder.get_object("nameColumn")
        nativeNameRenderer = self.builder.get_object("nativeNameRenderer")
        englishNameRenderer = self.builder.get_object("englishNameRenderer")
        override_cell_property(languageNameColumn, nativeNameRenderer,
                               "weight", self._mark_selected_language_bold)
        override_cell_property(languageNameColumn, englishNameRenderer,
                               "weight", self._mark_selected_language_bold)

        # If a language has selected locales, highlight every column so that
        # the row appears highlighted
        for col in self._langView.get_columns():
            for rend in col.get_cells():
                override_cell_property(col, rend, "cell-background-rgba",
                                       self._highlight_selected_language)

        # and also set an icon so that we don't depend on a color to convey information
        highlightedColumn = self.builder.get_object("highlighted")
        highlightedRenderer = self.builder.get_object("highlightedRenderer")
        override_cell_property(highlightedColumn, highlightedRenderer,
                               "icon-name", self._render_lang_highlighted)

        # report that we are done
        self.initialize_done()
Esempio n. 6
0
    def initialize(self):
        self._languageStore = self.builder.get_object("languageStore")
        self._languageEntry = self.builder.get_object("languageEntry")
        self._languageStoreFilter = self.builder.get_object("languageStoreFilter")
        self._langView = self.builder.get_object("languageView")
        self._langSelectedRenderer = self.builder.get_object("langSelectedRenderer")
        self._langSelectedColumn = self.builder.get_object("langSelectedColumn")
        self._langSelection = self.builder.get_object("languageViewSelection")
        self._localeStore = self.builder.get_object("localeStore")
        self._localeView = self.builder.get_object("localeView")

        LangLocaleHandler.initialize(self)

        # mark selected locales and languages with selected locales bold
        localeNativeColumn = self.builder.get_object("localeNativeName")
        localeNativeNameRenderer = self.builder.get_object("localeNativeNameRenderer")
        localeNativeColumn.set_cell_data_func(localeNativeNameRenderer,
                                              self._mark_selected_locale_bold)

        for col, rend in [("nativeName", "nativeNameRenderer"),
                          ("englishName", "englishNameRenderer")]:
            column = self.builder.get_object(col)
            renderer = self.builder.get_object(rend)
            column.set_cell_data_func(renderer, self._mark_selected_language_bold)
Esempio n. 7
0
    def initialize(self):
        self.initialize_start()
        self._languageStore = self.builder.get_object("languageStore")
        self._languageStoreFilter = self.builder.get_object(
            "languageStoreFilter")
        self._languageEntry = self.builder.get_object("languageEntry")
        self._langSelection = self.builder.get_object("languageViewSelection")
        self._langSelectedRenderer = self.builder.get_object(
            "langSelectedRenderer")
        self._langSelectedColumn = self.builder.get_object(
            "langSelectedColumn")
        self._langView = self.builder.get_object("languageView")
        self._localeView = self.builder.get_object("localeView")
        self._localeStore = self.builder.get_object("localeStore")
        self._localeSelection = self.builder.get_object("localeViewSelection")

        LangLocaleHandler.initialize(self)

        # We need to tell the view whether something is a separator or not.
        self._langView.set_row_separator_func(self._row_is_separator, None)

        # We can use the territory from geolocation here
        # to preselect the translation, when it's available.
        #
        # But as the lookup might still be in progress we need to make sure
        # to wait for it to finish. If the lookup has already finished
        # the wait function is basically a noop.
        geoloc.geoloc.wait_for_refresh_to_finish()

        # the lookup should be done now, get the teorritory
        territory = geoloc.geoloc.result.territory_code

        # bootopts and kickstart have priority over geoip
        language = self._l12_module.proxy.Language
        if language and self._l12_module.proxy.LanguageKickstarted:
            locales = [language]
        else:
            locales = localization.get_territory_locales(territory) or [
                DEFAULT_LANG
            ]

        # get the data models
        filter_store = self._languageStoreFilter
        store = filter_store.get_model()

        # get language codes for the locales
        langs = [
            localization.parse_langcode(locale)['language']
            for locale in locales
        ]

        # check which of the geolocated languages have translations
        # and store the iterators for those languages in a dictionary
        langs_with_translations = {}
        itr = store.get_iter_first()
        while itr:
            row_lang = store[itr][2]
            if row_lang in langs:
                langs_with_translations[row_lang] = itr
            itr = store.iter_next(itr)

        # if there are no translations for the given locales,
        # use default
        if not langs_with_translations:
            self._set_lang(DEFAULT_LANG)
            localization.setup_locale(DEFAULT_LANG,
                                      self._l12_module.proxy,
                                      text_mode=False)
            lang_itr, _locale_itr = self._select_locale(
                self._l12_module.proxy.Language)
            langs_with_translations[DEFAULT_LANG] = lang_itr
            locales = [DEFAULT_LANG]

        # go over all geolocated languages in reverse order
        # and move those we have translation for to the top of the
        # list, above the separator
        for lang in reversed(langs):
            itr = langs_with_translations.get(lang)
            if itr:
                store.move_after(itr, None)
            else:
                # we don't have translation for this language,
                # so dump all locales for it
                locales = [
                    l for l in locales
                    if localization.parse_langcode(l)['language'] != lang
                ]

        # And then we add a separator after the selected best language
        # and any additional languages (that have translations) from geoip
        newItr = store.insert(len(langs_with_translations))
        store.set(newItr, 0, "", 1, "", 2, "", 3, True)

        # setup the "best" locale
        locale = localization.setup_locale(locales[0], self._l12_module.proxy)
        self._set_lang(locale)
        self._select_locale(self._l12_module.proxy.Language)

        # report that we are done
        self.initialize_done()
Esempio n. 8
0
    def initialize(self):
        self._languageStore = self.builder.get_object("languageStore")
        self._languageStoreFilter = self.builder.get_object("languageStoreFilter")
        self._languageEntry = self.builder.get_object("languageEntry")
        self._langSelection = self.builder.get_object("languageViewSelection")
        self._langSelectedRenderer = self.builder.get_object("langSelectedRenderer")
        self._langSelectedColumn = self.builder.get_object("langSelectedColumn")
        self._langView = self.builder.get_object("languageView")
        self._localeView = self.builder.get_object("localeView")
        self._localeStore = self.builder.get_object("localeStore")
        self._localeSelection = self.builder.get_object("localeViewSelection")

        LangLocaleHandler.initialize(self)

        # We need to tell the view whether something is a separator or not.
        self._langView.set_row_separator_func(self._row_is_separator, None)

        # We can use the territory from geolocation here
        # to preselect the translation, when it's available.
        territory = geoloc.get_territory_code(wait=True)

        # bootopts and kickstart have priority over geoip
        if self.data.lang.lang and self.data.lang.seen:
            locales = [self.data.lang.lang]
        else:
            locales = localization.get_territory_locales(territory) or [DEFAULT_LANG]

        # get the data models
        filter_store = self._languageStoreFilter
        store = filter_store.get_model()

        # get language codes for the locales
        langs = [localization.parse_langcode(locale)['language'] for locale in locales]

        # check which of the geolocated languages have translations
        # and store the iterators for those languages in a dictionary
        langs_with_translations = {}
        itr = store.get_iter_first()
        while itr:
            row_lang = store[itr][2]
            if row_lang in langs:
                langs_with_translations[row_lang] = itr
            itr = store.iter_next(itr)

        # if there are no translations for the given locales,
        # use default
        if not langs_with_translations:
            localization.setup_locale(DEFAULT_LANG, self.data.lang)
            lang_itr, _locale_itr = self._select_locale(self.data.lang.lang)
            langs_with_translations[DEFAULT_LANG] = lang_itr
            locales = [DEFAULT_LANG]

        # go over all geolocated languages in reverse order
        # and move those we have translation for to the top of the
        # list, above the separator
        for lang in reversed(langs):
            itr = langs_with_translations.get(lang)
            if itr:
                store.move_after(itr, None)
            else:
                # we don't have translation for this language,
                # so dump all locales for it
                locales = [l for l in locales
                           if localization.parse_langcode(l)['language'] != lang]

        # And then we add a separator after the selected best language
        # and any additional languages (that have translations) from geoip
        newItr = store.insert(len(langs_with_translations))
        store.set(newItr, 0, "", 1, "", 2, "", 3, True)

        # setup the "best" locale
        localization.setup_locale(locales[0], self.data.lang)
        self._select_locale(self.data.lang.lang)
Esempio n. 9
0
    def initialize(self):
        self._languageStore = self.builder.get_object("languageStore")
        self._languageStoreFilter = self.builder.get_object("languageStoreFilter")
        self._languageEntry = self.builder.get_object("languageEntry")
        self._langSelection = self.builder.get_object("languageViewSelection")
        self._langSelectedRenderer = self.builder.get_object("langSelectedRenderer")
        self._langSelectedColumn = self.builder.get_object("langSelectedColumn")
        self._langView = self.builder.get_object("languageView")
        self._localeView = self.builder.get_object("localeView")
        self._localeStore = self.builder.get_object("localeStore")
        self._localeSelection = self.builder.get_object("localeViewSelection")

        LangLocaleHandler.initialize(self)

        # We need to tell the view whether something is a separator or not.
        self._langView.set_row_separator_func(self._row_is_separator, None)

        # We can use the territory from geolocation here
        # to preselect the translation, when it's available.
        territory = geoloc.get_territory_code(wait=True)

        # bootopts and kickstart have priority over geoip
        if self.data.lang.lang and self.data.lang.seen:
            locales = [self.data.lang.lang]
        else:
            locales = localization.get_territory_locales(territory) or [DEFAULT_LANG]

        # get the data models
        filter_store = self._languageStoreFilter
        store = filter_store.get_model()

        # get language codes for the locales
        langs = [localization.parse_langcode(locale)['language'] for locale in locales]

        # check which of the geolocated languages have translations
        # and store the iterators for those languages in a dictionary
        langs_with_translations = {}
        itr = store.get_iter_first()
        while itr:
            row_lang = store[itr][2]
            if row_lang in langs:
                langs_with_translations[row_lang] = itr
            itr = store.iter_next(itr)

        # if there are no translations for the given locales,
        # use default
        if not langs_with_translations:
            self._set_lang(DEFAULT_LANG)
            localization.setup_locale(DEFAULT_LANG, self.data.lang, text_mode=False)
            lang_itr, _locale_itr = self._select_locale(self.data.lang.lang)
            langs_with_translations[DEFAULT_LANG] = lang_itr
            locales = [DEFAULT_LANG]

        # go over all geolocated languages in reverse order
        # and move those we have translation for to the top of the
        # list, above the separator
        for lang in reversed(langs):
            itr = langs_with_translations.get(lang)
            if itr:
                store.move_after(itr, None)
            else:
                # we don't have translation for this language,
                # so dump all locales for it
                locales = [l for l in locales
                           if localization.parse_langcode(l)['language'] != lang]

        # And then we add a separator after the selected best language
        # and any additional languages (that have translations) from geoip
        newItr = store.insert(len(langs_with_translations))
        store.set(newItr, 0, "", 1, "", 2, "", 3, True)

        # setup the "best" locale
        locale = localization.setup_locale(locales[0], self.data.lang)
        self._set_lang(locale)
        self._select_locale(self.data.lang.lang)
Esempio n. 10
0
    def initialize(self):
        self.initialize_start()
        self._languageStore = self.builder.get_object("languageStore")
        self._languageStoreFilter = self.builder.get_object("languageStoreFilter")
        self._languageEntry = self.builder.get_object("languageEntry")
        self._langSelection = self.builder.get_object("languageViewSelection")
        self._langSelectedRenderer = self.builder.get_object("langSelectedRenderer")
        self._langSelectedColumn = self.builder.get_object("langSelectedColumn")
        self._langView = self.builder.get_object("languageView")
        self._localeView = self.builder.get_object("localeView")
        self._localeStore = self.builder.get_object("localeStore")
        self._localeSelection = self.builder.get_object("localeViewSelection")

        LangLocaleHandler.initialize(self)

        # We need to tell the view whether something is a separator or not.
        self._langView.set_row_separator_func(self._row_is_separator, None)

        # We can use the territory from geolocation here
        # to preselect the translation, when it's available.
        #
        # But as the lookup might still be in progress we need to make sure
        # to wait for it to finish. If the lookup has already finished
        # the wait function is basically a noop.
        geoloc.geoloc.wait_for_refresh_to_finish()

        # the lookup should be done now, get the teorritory
        territory = geoloc.geoloc.result.territory_code

        # bootopts and kickstart have priority over geoip
        language = self._l12_module.proxy.Language
        if language and self._l12_module.proxy.LanguageKickstarted:
            locales = [language]
        else:
            locales = localization.get_territory_locales(territory) or [DEFAULT_LANG]

        # get the data models
        filter_store = self._languageStoreFilter
        store = filter_store.get_model()

        # get language codes for the locales
        langs = [localization.parse_langcode(locale)['language'] for locale in locales]

        # check which of the geolocated languages have translations
        # and store the iterators for those languages in a dictionary
        langs_with_translations = {}
        itr = store.get_iter_first()
        while itr:
            row_lang = store[itr][2]
            if row_lang in langs:
                langs_with_translations[row_lang] = itr
            itr = store.iter_next(itr)

        # if there are no translations for the given locales,
        # use default
        if not langs_with_translations:
            self._set_lang(DEFAULT_LANG)
            localization.setup_locale(DEFAULT_LANG, self._l12_module.proxy, text_mode=False)
            lang_itr, _locale_itr = self._select_locale(self._l12_module.proxy.Language)
            langs_with_translations[DEFAULT_LANG] = lang_itr
            locales = [DEFAULT_LANG]

        # go over all geolocated languages in reverse order
        # and move those we have translation for to the top of the
        # list, above the separator
        for lang in reversed(langs):
            itr = langs_with_translations.get(lang)
            if itr:
                store.move_after(itr, None)
            else:
                # we don't have translation for this language,
                # so dump all locales for it
                locales = [l for l in locales
                           if localization.parse_langcode(l)['language'] != lang]

        # And then we add a separator after the selected best language
        # and any additional languages (that have translations) from geoip
        newItr = store.insert(len(langs_with_translations))
        store.set(newItr, 0, "", 1, "", 2, "", 3, True)

        # setup the "best" locale
        locale = localization.setup_locale(locales[0], self._l12_module.proxy)
        self._set_lang(locale)
        self._select_locale(self._l12_module.proxy.Language)

        # report that we are done
        self.initialize_done()
Esempio n. 11
0
    def initialize(self):
        self.initialize_start()
        self._languageStore = self.builder.get_object("languageStore")
        self._languageStoreFilter = self.builder.get_object(
            "languageStoreFilter")
        self._languageEntry = self.builder.get_object("languageEntry")
        self._langSelection = self.builder.get_object("languageViewSelection")
        self._langSelectedRenderer = self.builder.get_object(
            "langSelectedRenderer")
        self._langSelectedColumn = self.builder.get_object(
            "langSelectedColumn")
        self._langView = self.builder.get_object("languageView")
        self._localeView = self.builder.get_object("localeView")
        self._localeStore = self.builder.get_object("localeStore")
        self._localeSelection = self.builder.get_object("localeViewSelection")

        LangLocaleHandler.initialize(self)

        # We need to tell the view whether something is a separator or not.
        self._langView.set_row_separator_func(self._row_is_separator, None)

        # We can use the territory from geolocation here
        # to preselect the translation, when it's available.
        locales = self._get_starting_locales()

        # get the data models
        filter_store = self._languageStoreFilter
        store = filter_store.get_model()

        # get language codes for the locales
        langs = [localization.get_language_id(locale) for locale in locales]

        # get common languages and append them here
        common_langs = localization.get_common_languages()
        common_langs_len = len(set(common_langs).difference(set(langs)))
        langs += common_langs

        # check which of the geolocated or common languages have translations
        # and store the iterators for those languages in a dictionary
        langs_with_translations = {}
        itr = store.get_iter_first()
        while itr:
            row_lang = store[itr][2]
            if row_lang in langs:
                langs_with_translations[row_lang] = itr
            itr = store.iter_next(itr)

        # if there are no translations for the given locales,
        # use default
        if not langs_with_translations:
            self._set_lang(DEFAULT_LANG)
            localization.setup_locale(DEFAULT_LANG,
                                      self._l12_module,
                                      text_mode=False)
            lang_itr, _locale_itr = self._select_locale(
                self._l12_module.Language)
            langs_with_translations[DEFAULT_LANG] = lang_itr
            locales = [DEFAULT_LANG]

        # go over all geolocated and common languages in reverse order
        # and move those we have translation for to the top of the
        # list, above the separator
        for lang in reversed(langs):
            itr = langs_with_translations.get(lang)
            if itr:
                store.move_after(itr, None)
            else:
                # we don't have translation for this language,
                # so dump all locales for it
                locales = [
                    l for l in locales
                    if localization.get_language_id(l) != lang
                ]

        # And then we add a separator after the selected best language
        # and any additional languages (that have translations) from geoip
        langs_with_translations_len = len(langs_with_translations)
        newItr = store.insert(langs_with_translations_len)
        store.set(newItr, 0, "", 1, "", 2, "", 3, True)

        # add a separator before common languages as well
        commonLangsItr = store.insert(langs_with_translations_len -
                                      common_langs_len)
        store.set(commonLangsItr, 0, "", 1, "", 2, "", 3, True)

        # setup the "best" locale
        best_locale = locales[0] if locales else DEFAULT_LANG
        locale = localization.setup_locale(best_locale, self._l12_module)
        self._set_lang(locale)
        self._select_locale(self._l12_module.Language)

        # report that we are done
        self.initialize_done()