Python wx.Locale() Examples

The following are 12 code examples of wx.Locale(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module wx , or try the search function .
Example #1
Source File: testsupport_new.py    From wxGlade with MIT License 6 votes vote down vote up
def setUpClass(cls):
        WXGladeBaseTest.setUpClass()
        xrc2wxg._write_timestamp = False

        # create an simply application
        cls.app = wx.App()
        cls.locale = wx.Locale(wx.LANGUAGE_DEFAULT)
        compat.wx_ArtProviderPush(main.wxGladeArtProvider())
        import history
        common.history = history.History()
        cls.frame = main.wxGladeFrame()

        # suppress wx error messages
        cls.nolog = wx.LogNull()

        #cls.app.SetAssertMode(0) # avoid triggering of wx assertions; sometimes needed for debugging

        # hide all windows
        #cls.frame.Hide()
        #cls.frame.hide_all() 
Example #2
Source File: guiminer.py    From poclbm with GNU General Public License v3.0 5 votes vote down vote up
def update_language(new_language):
    global locale, language
    language = new_language
    if locale:
        del locale

    locale = wx.Locale(language)
    if locale.IsOk():
        locale.AddCatalogLookupPathPrefix(os.path.join(get_module_path(), "locale"))
        locale.AddCatalog("guiminer")
    else:
        locale = None 
Example #3
Source File: tray.py    From superpaper with MIT License 5 votes vote down vote up
def OnInit(self):
        """Starts tray icon loop."""
        frame = wx.Frame(None)
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH_US)
        self.SetTopWindow(frame)
        TaskBarIcon(frame)
        return True 
Example #4
Source File: mki18n.py    From CANFestivino with GNU Lesser General Public License v2.1 5 votes vote down vote up
def getlanguageDict():
    languageDict = {}
    
    for lang in [x for x in dir(wx) if x.startswith("LANGUAGE")]:
        i = wx.Locale(wx.LANGUAGE_DEFAULT).GetLanguageInfo(getattr(wx, lang))
        if i:
            languageDict[i.CanonicalName] = i.Description

    return languageDict

# -----------------------------------------------------------------------------
# m a k e P O ( )         -- Build the Portable Object file for the application --
# ^^^^^^^^^^^^^^^
# 
Example #5
Source File: main.py    From wxGlade with MIT License 5 votes vote down vote up
def OnInit(self):
        sys.stdout = sys.__stdout__
        sys.stderr = sys.__stderr__

        # replace text based exception handler by a graphical exception dialog
        sys.excepthook = self.graphical_exception_handler

        # use graphical implementation to show caught exceptions
        self._exception_orig = logging.exception  # Reference to original implementation of logging.exception()
        logging.exception = self.exception

        # needed for wx >= 2.3.4 to disable wxPyAssertionError exceptions
        if not config.debugging:
            self.SetAssertMode(0)

        common.init_preferences()

        self.locale = wx.Locale(wx.LANGUAGE_DEFAULT)  # avoid PyAssertionErrors
        #compat.wx_ArtProviderPush(wxGladeArtProvider())

        frame = wxGladeFrame()
        self.SetTopWindow(frame)
        self.SetExitOnFrameDelete(True)

        self.Bind(wx.EVT_IDLE, self.OnIdle)

        return True 
Example #6
Source File: update-po.py    From wxGlade with MIT License 5 votes vote down vote up
def getlanguageDict():
    languageDict = {}

    for lang in [x for x in dir(wx) if x.startswith("LANGUAGE")]:
        i = wx.Locale(wx.LANGUAGE_DEFAULT).GetLanguageInfo(getattr(wx, lang))
        if i:
            languageDict[i.CanonicalName] = i.Description

    return languageDict

# -----------------------------------------------------------------------------
# m a k e P O ( )         -- Build the Portable Object file for the application --
# ^^^^^^^^^^^^^^^
# 
Example #7
Source File: App.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self):
        self.onExitFuncs = []
        wx.App.__init__(self, 0)
        lang_id = LCID_TO_WX.get(kernel32.GetUserDefaultUILanguage(), None)

        if lang_id is not None:
            self.locale = wx.Locale(lang_id)

        self.shouldVeto = False
        self.firstQuery = True
        self.endSession = False
        self.frame = wx.Frame(None)
        self.hwnd = self.frame.GetHandle() 
Example #8
Source File: Beremiz_service.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
def SetupI18n():
    # Get folder containing translation files
    localedir = os.path.join(beremiz_dir, "locale")
    # Get the default language
    langid = wx.LANGUAGE_DEFAULT
    # Define translation domain (name of translation files)
    domain = "Beremiz"

    # Define locale for wx
    loc = builtins.__dict__.get('loc', None)
    if loc is None:
        wx.LogGui.EnableLogging(False)
        loc = wx.Locale(langid)
        wx.LogGui.EnableLogging(True)
        builtins.__dict__['loc'] = loc
        # Define location for searching translation files
    loc.AddCatalogLookupPathPrefix(localedir)
    # Define locale domain
    loc.AddCatalog(domain)

    import locale
    global default_locale
    default_locale = locale.getdefaultlocale()[1]

    # sys.stdout.encoding = default_locale
    # if Beremiz_service is started from Beremiz IDE
    # sys.stdout.encoding is None (that means 'ascii' encoding').
    # And unicode string returned by wx.GetTranslation() are
    # automatically converted to 'ascii' string.
    def unicode_translation(message):
        return wx.GetTranslation(message).encode(default_locale)

    builtins.__dict__['_'] = unicode_translation
    # builtins.__dict__['_'] = wx.GetTranslation


# Life is hard... have a candy.
# pylint: disable=wrong-import-position,wrong-import-order 
Example #9
Source File: TranslationCatalogs.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
def AddCatalog(locale_dir):
    if os.path.exists(locale_dir) and os.path.isdir(locale_dir):
        domain = GetDomain(locale_dir)
        if domain is not None:
            global locale
            if locale is None:
                # Define locale for wx
                wx.LogGui.EnableLogging(False)
                locale = wx.Locale(wx.LANGUAGE_DEFAULT)
                wx.LogGui.EnableLogging(True)

            locale.AddCatalogLookupPathPrefix(locale_dir)
            locale.AddCatalog(domain) 
Example #10
Source File: mki18n.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
def getlanguageDict():
    languageDict = {}
    getSupportedLanguageDict('Beremiz')
    if wx.VERSION >= (3, 0, 0):
        _app = wx.App()
    else:
        _app = wx.PySimpleApp()

    for lang in [x for x in dir(wx) if x.startswith("LANGUAGE")]:
        i = wx.Locale(wx.LANGUAGE_DEFAULT).GetLanguageInfo(getattr(wx, lang))
        if i:
            languageDict[i.CanonicalName] = i.Description

    return languageDict 
Example #11
Source File: wx_bass_control.py    From pybass with Apache License 2.0 4 votes vote down vote up
def start(self):
			result = True
			self.help_file = self.app_name + '.htb'
			#SETUP LANGUAGE
			lang_catalog = getdefaultlocale()[0]
			list_trans = []
			current_trans = -1
			i = 0
			self.wx_coding = 'ansi'
			if wx.USE_UNICODE:
				self.wx_coding = 'unicode'
			if os.path.exists('lang/%s'%lang_catalog):
				for dir_name in os.listdir('lang'):
					if os.path.exists('lang/%s/%s_%s.mo'%(dir_name, self.app_name, self.wx_coding)):
						if dir_name == lang_catalog:
							current_trans = i
							self.help_file = 'lang/' + dir_name + '/'+ self.help_file
						list_trans.append(gettext.GNUTranslations(open('lang/%s/%s_%s.mo'%(dir_name, self.app_name, self.wx_coding), 'rb')))
						i += 1
				if len(list_trans) > 0:
					try:
						list_trans[current_trans].install(unicode = wx.USE_UNICODE)
					except:
						print print_error()
			if current_trans == -1:
				trans = gettext.NullTranslations()
				trans.install(unicode = wx.USE_UNICODE)
			# SETUP WX LANGUAGE TRANSLATION TO OS DEFAULT LANGUAGE
			# WX DIRECTORY MUST BE TO CONTAIN LANG DIRECTORY
			self.locale = wx.Locale(wx.LANGUAGE_DEFAULT)
			# CHECK EXISTS INSTANCE
			name_user = wx.GetUserId()
			name_instance = self.app_name + '::'
			self.instance_checker = wx.SingleInstanceChecker(name_instance + name_user)
			if self.instance_checker.IsAnotherRunning():
				wx.MessageBox(_('Software is already running.'), _('Warning'))
				return False
			# CREATE HTML HELP CONTROLLER
			wx.FileSystem.AddHandler(wx.ZipFSHandler())
			self.help_controller = HtmlHelpController()
			if os.path.exists(self.help_file):
				self.help_controller.AddBook(self.help_file)
			#ABOUT APPLICATION
			self.developers = [_('Max Kolosov')]
			self.copyright = _('(C) 2009 Max Kolosov')
			self.web_site = ('http://vosolok2008.narod.ru', _('Home page'))
			self.email = ('mailto:maxkolosov@inbox.ru', _('email for feedback'))
			self.license = _('BSD license')
			self.about_description = _('wxPython bass music player.')
			#CREATE MAIN FRAME
			self.main_frame = main_frame(None, wx.ID_ANY, self.app_name, app = self)
			self.SetTopWindow(self.main_frame)
			self.main_frame.Show()
			return result 
Example #12
Source File: wx_ctrl_phoenix.py    From pybass with Apache License 2.0 4 votes vote down vote up
def start(self):
			result = True
			self.help_file = self.app_name + '.htb'
			#SETUP LANGUAGE
			lang_catalog = getdefaultlocale()[0]
			list_trans = []
			current_trans = -1
			i = 0
			if os.path.exists('lang/%s'%lang_catalog):
				for dir_name in os.listdir('lang'):
					if os.path.exists('lang/%s/%s.mo'%(dir_name, self.app_name)):
						if dir_name == lang_catalog:
							current_trans = i
							self.help_file = 'lang/' + dir_name + '/'+ self.help_file
						list_trans.append(gettext.GNUTranslations(open('lang/%s/%s.mo'%(dir_name, self.app_name), 'rb')))
						i += 1
				if len(list_trans) > 0:
					try:
						list_trans[current_trans].install(unicode = True)#wx.USE_UNICODE
					except:
						print_error()
			if current_trans == -1:
				trans = gettext.NullTranslations()
				trans.install(unicode = True)#wx.USE_UNICODE
			# SETUP WX LANGUAGE TRANSLATION TO OS DEFAULT LANGUAGE
			# WX DIRECTORY MUST BE TO CONTAIN LANG DIRECTORY
			self.locale = wx.Locale(wx.LANGUAGE_DEFAULT)
			# CHECK EXISTS INSTANCE
			name_user = wx.GetUserId()
			name_instance = self.app_name + '::'
			self.instance_checker = wx.SingleInstanceChecker(name_instance + name_user)
			if self.instance_checker.IsAnotherRunning():
				wx.MessageBox(_('Software is already running.'), _('Warning'))
				return False
			# CREATE HTML HELP CONTROLLER
			#~ wx.FileSystem.AddHandler(wx.ZipFSHandler())
			self.help_controller = HtmlHelpController()
			if os.path.exists(self.help_file):
				self.help_controller.AddBook(self.help_file)
			#ABOUT APPLICATION
			self.developers = [_('Maxim Kolosov')]
			self.copyright = _('(C) 2013 Max Kolosov')
			self.web_site = ('http://pybass.sf.net', _('Home page'))
			self.email = ('mailto:pyirrlicht@gmail.com', _('email for feedback'))
			self.license = _('BSD license')
			self.about_description = _('wxPython bass music player.')
			#CREATE MAIN FRAME
			self.main_frame = main_frame(None, wx.ID_ANY, self.app_name, app = self)
			self.SetTopWindow(self.main_frame)
			self.main_frame.Show()
			return result