Source code for qtypy.app
#!/usr/bin/env python3
#-*- coding: ISO-8859-1 -*-
import locale
import logging
import gettext
import os
import sys
from PyQt5 import QtCore, QtWidgets
if os.environ.get('READTHEDOCS', 'False') != 'True':
from qtypy import resources # pylint: disable=W0611
[docs]class Application(QtWidgets.QApplication):
"""
Application class
"""
logger = logging.getLogger('qtypy.Application')
[docs] def setup_i18n(self, locale_name=None, msg_path=None):
"""
Sets up i18n stuff and injects '_' in the builtin namespace.
"""
if locale_name is None:
locale_name = str(QtCore.QLocale.system().name())
try:
locale.setlocale(locale.LC_ALL, locale_name)
except locale.Error as exc:
self.logger.error('Cannot set locale to "%s": %s', locale_name, exc)
if msg_path is None:
msg_path = os.path.normpath(os.path.join(os.path.dirname(sys.argv[0]), 'i18n'))
gettext.install(self.applicationName(), msg_path)