Пример #1
0
    def on_import_preferences(self, event=None):
        """
        Imports a preference file. Backs up the user's current preference file
        into a directory, with a timestamp on the filename
        """
        logger.debug("Prompting to import preferences")
        wildcard = _("Whyteboard Preference Files") + u" (*.pref)|*.pref"

        filename = file_dialog(self, _("Import Preferences From..."), wx.OPEN,
                               wildcard, get_home_dir())

        if filename:
            Config().init(filename)
            _dir = os.path.join(get_home_dir(), u"pref-bkup")

            if not os.path.isdir(_dir):
                os.makedirs(_dir)

            home = os.path.join(get_home_dir(), u"user.pref")
            if os.path.exists(home):
                stamp = time.strftime(u"%d-%m-%Y_%H-%M_%S")
                logger.debug("Renaming old preferences file to [%s]", stamp)
                os.rename(home, os.path.join(_dir, stamp + u".user.pref"))
                
            config = Config().clone()
            config.init(filename)
            self.update_config(config.config)
Пример #2
0
    def set_language(self, option_lang=None):
        """
        Sets the user's language.
        """
        set_lang = False
        lang_name = Config().get('language')
        logger.debug("Found language [%s] in config", lang_name)

        if option_lang:
            logger.debug("Attempting to set language from command line: [%s]", option_lang)
            country = wx.Locale.FindLanguageInfo(option_lang)
            if country:
                set_lang = True
                lang_name = country.Description
                self.locale = wx.Locale(country.Language)
                logger.debug("Using command-line set language [%s]", lang_name)
            else:
                logger.warning("Could not parse command-line argument [%s] into a known locale/language", option_lang)

        if not set_lang:
            for x in meta.languages:
                if lang_name.capitalize() == 'Welsh':
                    self.locale = wx.Locale()
                    self.locale.Init(u"Cymraeg", u"cy", u"cy_GB.utf8")
                    break
                elif lang_name == x[0]:
                    logger.debug("Attempting to set language to [%s] from config", lang_name)
                    nolog = wx.LogNull()
                    self.locale = wx.Locale(x[2])

        if not hasattr(self, "locale"):
            logger.debug("No locale set, reverting to system language")
            self.locale = wx.Locale(wx.LANGUAGE_DEFAULT)
            Config().language(wx.Locale.GetLanguageName(wx.LANGUAGE_DEFAULT))
            Config().write()

        if not wx.Locale.IsOk(self.locale):
            logger.warning("Could not set language to [%s]", lang_name)
            wx.MessageBox(u"Error setting language to %s - reverting to English"
                          % lang_name, u"Whyteboard")
            if not set_lang:
                Config().language('English')
                Config().write()
            self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)

        logger.info("Whyteboard is running in [%s]", wx.Locale.GetLanguageName(self.locale.GetLanguage()))
        langdir = os.path.join(get_path(), u'locale')
        logger.debug("Adding locale catalogue [%s]", langdir)
        self.locale.AddCatalogLookupPathPrefix(langdir)
        self.locale.AddCatalog(u"whyteboard")
        self.locale.AddCatalog(u'wxstd')

        # nasty fix for some translated strings not being applied
        meta.languages = meta.define_languages()
        meta.types, meta.dialog_wildcard = meta.define_filetypes()