本文整理汇总了Python中PyQt5.QtCore.QTranslator方法的典型用法代码示例。如果您正苦于以下问题:Python QtCore.QTranslator方法的具体用法?Python QtCore.QTranslator怎么用?Python QtCore.QTranslator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore
的用法示例。
在下文中一共展示了QtCore.QTranslator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QTranslator [as 别名]
def __init__(self):
super(SimpleApp, self).__init__([])
self.translator = QtCore.QTranslator()
self.default_font = QtGui.QFont()
if sys.version_info < (3,) :
settings_path = ".easygui-qt2"
else:
settings_path = ".easygui-qt3"
self.config_path = os.path.join(os.path.expanduser("~"),
settings_path)
try:
self.load_config()
self.setFont(self.default_font)
except:
pass
self.save_config()
示例2: set_locale
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QTranslator [as 别名]
def set_locale(self, locale, save=True):
"""Sets the language of the basic controls for PyQt
from a locale - provided that the corresponding qm files
are present in the PyQt distribution.
"""
global QM_FILES
if QM_FILES is None:
QM_FILES = utils.find_qm_files()
if locale in QM_FILES:
if self.translator.load("qt_" + locale, QM_FILES[locale]):
self.installTranslator(self.translator)
self.config['locale'] = locale
else:
print("language not available")
elif locale == "default" and self.config['locale'] != 'default':
self.removeTranslator(self.translator)
self.translator = QtCore.QTranslator()
self.config['locale'] = 'default'
elif self.config['locale'] in QM_FILES:
if self.translator.load("qt_" + self.config['locale'],
QM_FILES[self.config['locale']]):
self.installTranslator(self.translator)
if save:
self.save_config()
示例3: __init__
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QTranslator [as 别名]
def __init__(self, parent=None):
super(MyWindow, self).__init__(parent)
self.setupUi(self)
try:
with open("style.qss") as f:
style = f.read() # 读取样式表
self.setStyleSheet(style)
except:
print("open stylesheet error")
self.originText.setFocus(True)
# Translator
self.trans = QTranslator()
# destination language
self.dest = "zh-CN"
# ui language : 0->zh-CN, 1->en
self.lan = 0
# real-time translate
self.isRealTimeTrans = False
self.isCopyFromTrans = False
self.connectSlots()
示例4: init_translations
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QTranslator [as 别名]
def init_translations(app):
"""
Loads translations for a given input app. If a scaling factor is defined for testing, we use
our own subclass of QTranslator.
"""
global application, translator, locale # if we don't keep a reference on these, it stops working. pyqt bug?
application = app
translator = QTranslator() if trans_scale == 100 else VortaTranslator()
locale = QLocale(os.environ.get('LANG', None))
qm_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'qm'))
ui_langs = locale.uiLanguages()
succeeded = translator.load(locale, 'vorta', prefix='.', directory=qm_path) # e.g. vorta/i18n/qm/vorta.de_DE.qm
if succeeded:
app.installTranslator(translator)
logger.debug('Loading translation %s for %r.' % ('succeeded' if succeeded else 'failed', ui_langs))
示例5: __init__
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QTranslator [as 别名]
def __init__(self, iface):
"""Constructor.
:param iface: An interface instance that will be passed to this class
which provides the hook by which you can manipulate the QGIS
application at run time.
:type iface: QgsInterface
"""
# Save reference to the QGIS interface
self.iface = iface
# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale = QSettings().value('locale/userLocale')[0:2]
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'RasterVisionPlugin_{}.qm'.format(locale))
if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
# Create the dialog (after translation) and keep reference
self.experiment_controller = ExperimentDialogController(self.iface)
self.predict_controller = PredictDialogController(self.iface)
self.profiles_controller = ProfilesDialogController()
self.config_controller = ConfigDialogController()
# Declare instance attributes
self.actions = []
self.menu = self.tr(u'&Raster Vision')
# TODO: We are going to let the user set this up in a future iteration
self.toolbar = self.iface.addToolBar(u'RasterVisionPlugin')
self.toolbar.setObjectName(u'RasterVisionPlugin')
# noinspection PyMethodMayBeStatic
示例6: test_qgis_translations
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QTranslator [as 别名]
def test_qgis_translations(self):
"""Test that translations work."""
parent_path = os.path.join(__file__, os.path.pardir, os.path.pardir)
dir_path = os.path.abspath(parent_path)
file_path = os.path.join(
dir_path, 'i18n', 'af.qm')
translator = QTranslator()
translator.load(file_path)
QCoreApplication.installTranslator(translator)
expected_message = 'Goeie more'
real_message = QCoreApplication.translate("@default", 'Good morning')
self.assertEqual(real_message, expected_message)
示例7: main
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QTranslator [as 别名]
def main():
# before we create the app, we hijack QT_AUTO_SCREEN_SCALE_FACTOR to force device scaling to be accurate
os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1"
# Make icons sharp in HiDPI screen
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
app = QtWidgets.QApplication(sys.argv)
app.setApplicationName('Lector') # This is needed for QStandardPaths
# and my own hubris
# Internationalization support
translator = QtCore.QTranslator()
translations_found = translator.load(
QtCore.QLocale.system(), ':/translations/translations_bin/Lector_')
app.installTranslator(translator)
translations_out_string = ' (Translations found)'
if not translations_found:
translations_out_string = ' (No translations found)'
print(f'Locale: {QtCore.QLocale.system().name()}' + translations_out_string)
form = MainUI()
form.show()
form.resizeEvent()
app.exec_()
示例8: __init__
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QTranslator [as 别名]
def __init__(self, iface):
self.provider = HqgisProvider()
# Save reference to the QGIS interface
self.iface = iface
# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale = QSettings().value('locale/userLocale')[0:2]
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'Hqgis_{}.qm'.format(locale))
if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
# Create the dialog (after translation) and keep reference
self.dlg = HqgisDialog()
# Declare instance attributes
self.actions = []
self.menu = self.tr(u'&Hqgis')
# TODO: We are going to let the user set this up in a future iteration
self.toolbar = self.iface.addToolBar(u'Hqgis')
self.toolbar.setObjectName(u'Hqgis')
self.getMapCoordinates = GetMapCoordinates(self.iface)
self.getMapCoordTool = None
# noinspection PyMethodMayBeStatic
示例9: run
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QTranslator [as 别名]
def run():
app = QtWidgets.QApplication(sys.argv)
# app.setStyle('fusion')
# app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
trans = QtCore.QTranslator()
# trans.load("./gui/en")
# app.installTranslator(trans)
window = Main(app, trans)
window.show()
sys.exit(app.exec_())
示例10: __init__
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QTranslator [as 别名]
def __init__(self):
from codec import Codec
from window import Window
from system import System
from datajar import DataJar
from filesystem import FileSystem
try:
manifest = json.load(codecs.open('manifest.json', 'r', 'utf-8'))
except:
manifest = {}
for key in assets.manifest:
if key in manifest:
assets.manifest[key] = manifest[key]
self.app = QApplication(sys.argv)
self.app.setApplicationName(assets.manifest['name'])
self.app.setApplicationVersion(assets.manifest['version'])
assets.sys = System()
assets.codec = Codec()
assets.fs = FileSystem()
assets.dataJar = DataJar()
translator = QTranslator()
if translator.load("zh_CN.qm"):
self.app.installTranslator(translator)
self.window = Window(None, assets.manifest['path'] + 'index.html')
sys.exit(self.app.exec_())
示例11: gui
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QTranslator [as 别名]
def gui():
qual_app = App()
settings = qual_app.load_settings()
project_path = qual_app.get_most_recent_projectpath()
app = QtWidgets.QApplication(sys.argv)
QtGui.QFontDatabase.addApplicationFont("GUI/NotoSans-hinted/NotoSans-Regular.ttf")
QtGui.QFontDatabase.addApplicationFont("GUI/NotoSans-hinted/NotoSans-Bold.ttf")
stylesheet = qual_app.merge_settings_with_default_stylesheet(settings)
app.setStyleSheet(stylesheet)
# Try and load language settings from file stored in home/.qualcoder/
# translator applies to ui designed GUI widgets only
lang = settings.get('language','en')
getlang = gettext.translation('en', localedir=path +'/locale', languages=['en'])
if lang != "en":
translator = QtCore.QTranslator()
if lang == "fr":
translator.load(path + "/locale/fr/app_fr.qm")
getlang = gettext.translation('fr', localedir=path + '/locale', languages=['fr'])
if lang == "de":
translator.load(path + "/locale/de/app_de.qm")
getlang = gettext.translation('de', localedir=path + '/locale', languages=['de'])
if lang == "es":
translator.load(path + "/locale/es/app_es.qm")
getlang = gettext.translation('es', localedir=path + '/locale', languages=['es'])
app.installTranslator(translator)
getlang.install()
ex = MainWindow(qual_app)
if project_path:
ex.open_project(path=project_path)
sys.exit(app.exec_())
示例12: run
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QTranslator [as 别名]
def run(app_context):
translator = QtCore.QTranslator()
## Loading ayab_gui main translator.
translator.load(QtCore.QLocale.system(), "ayab_gui", ".", app_context.get_resource("ayab/translations"), ".qm")
app = QtWidgets.QApplication(sys.argv)
app.installTranslator(translator)
window = GuiMain(app_context)
window.show()
sys.exit(app.exec_())
示例13: set_translator
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QTranslator [as 别名]
def set_translator(self):
dirname = os.path.dirname(__file__)
self.translator = QtCore.QTranslator()
self.translator.load(QtCore.QLocale.system(), "ayab_options", ".", dirname, ".qm")
app = QtCore.QCoreApplication.instance()
app.installTranslator(self.translator)
示例14: __init__
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QTranslator [as 别名]
def __init__(self, persepolis_setting):
super().__init__()
icon = QIcon()
self.persepolis_setting = persepolis_setting
# add support for other languages
locale = str(self.persepolis_setting.value('settings/locale'))
QLocale.setDefault(QLocale(locale))
self.translator = QTranslator()
if self.translator.load(':/translations/locales/ui_' + locale, 'ts'):
QCoreApplication.installTranslator(self.translator)
self.setWindowIcon(QIcon.fromTheme('persepolis', QIcon(':/persepolis.svg')))
self.setWindowTitle(QCoreApplication.translate("setting_ui_tr", 'Preferences'))
# set ui direction
ui_direction = self.persepolis_setting.value('ui_direction')
if ui_direction == 'rtl':
self.setLayoutDirection(Qt.RightToLeft)
elif ui_direction in 'ltr':
self.setLayoutDirection(Qt.LeftToRight)
global icons
icons = ':/' + str(self.persepolis_setting.value('settings/icons')) + '/'
window_verticalLayout = QVBoxLayout(self)
self.pressKeyLabel = QLabel(self)
window_verticalLayout.addWidget(self.pressKeyLabel)
self.capturedKeyLabel = QLabel(self)
window_verticalLayout.addWidget(self.capturedKeyLabel)
# window buttons
buttons_horizontalLayout = QHBoxLayout()
buttons_horizontalLayout.addStretch(1)
self.cancel_pushButton = QPushButton(self)
self.cancel_pushButton.setIcon(QIcon(icons + 'remove'))
buttons_horizontalLayout.addWidget(self.cancel_pushButton)
self.ok_pushButton = QPushButton(self)
self.ok_pushButton.setIcon(QIcon(icons + 'ok'))
buttons_horizontalLayout.addWidget(self.ok_pushButton)
window_verticalLayout.addLayout(buttons_horizontalLayout)
# labels
self.pressKeyLabel.setText(QCoreApplication.translate("setting_ui_tr", "Press new keys"))
self.cancel_pushButton.setText(QCoreApplication.translate("setting_ui_tr", "Cancel"))
self.ok_pushButton.setText(QCoreApplication.translate("setting_ui_tr", "OK"))
示例15: __init__
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QTranslator [as 别名]
def __init__(self, parent, gid, persepolis_setting):
super().__init__(persepolis_setting)
self.persepolis_setting = persepolis_setting
self.parent = parent
self.gid = gid
self.status = None
self.resume_pushButton.clicked.connect(self.resumePushButtonPressed)
self.stop_pushButton.clicked.connect(self.stopPushButtonPressed)
self.pause_pushButton.clicked.connect(self.pausePushButtonPressed)
self.download_progressBar.setValue(0)
self.limit_pushButton.clicked.connect(self.limitPushButtonPressed)
self.limit_frame.setEnabled(False)
self.limit_checkBox.toggled.connect(self.limitCheckBoxToggled)
self.after_frame.setEnabled(False)
self.after_checkBox.toggled.connect(self.afterCheckBoxToggled)
self.after_pushButton.clicked.connect(self.afterPushButtonPressed)
# add support for other languages
locale = str(self.persepolis_setting.value('settings/locale'))
QLocale.setDefault(QLocale(locale))
self.translator = QTranslator()
if self.translator.load(':/translations/locales/ui_' + locale, 'ts'):
QCoreApplication.installTranslator(self.translator)
# check if limit speed activated by user or not
add_link_dictionary = self.parent.persepolis_db.searchGidInAddLinkTable(gid)
limit = str(add_link_dictionary['limit_value'])
if limit != '0':
limit_number = limit[:-1]
limit_unit = limit[-1]
self.limit_spinBox.setValue(float(limit_number))
if limit_unit == 'K':
self.after_comboBox.setCurrentIndex(0)
else:
self.after_comboBox.setCurrentIndex(1)
self.limit_checkBox.setChecked(True)
self.after_comboBox.currentIndexChanged.connect(self.afterComboBoxChanged)
self.limit_comboBox.currentIndexChanged.connect(self.limitComboBoxChanged)
self.limit_spinBox.valueChanged.connect(self.limitComboBoxChanged)
# set window size and position
size = self.persepolis_setting.value(
'ProgressWindow/size', QSize(595, 274))
position = self.persepolis_setting.value(
'ProgressWindow/position', QPoint(300, 300))
self.resize(size)
self.move(position)
# close window with ESC key