Python PyQt5.QtCore.QTranslator() Examples
The following are 20
code examples of PyQt5.QtCore.QTranslator().
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
PyQt5.QtCore
, or try the search function
.
Example #1
Source File: easygui_qt.py From easygui_qt with BSD 3-Clause "New" or "Revised" License | 7 votes |
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()
Example #2
Source File: easygui_qt.py From easygui_qt with BSD 3-Clause "New" or "Revised" License | 6 votes |
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()
Example #3
Source File: __init__.py From vorta with GNU General Public License v3.0 | 6 votes |
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))
Example #4
Source File: main.py From PyQt5-Apps with GNU General Public License v3.0 | 6 votes |
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()
Example #5
Source File: ayab_control.py From ayab-desktop with GNU General Public License v3.0 | 5 votes |
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)
Example #6
Source File: ayab.py From ayab-desktop with GNU General Public License v3.0 | 5 votes |
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_())
Example #7
Source File: qualcoder.py From QualCoder with MIT License | 5 votes |
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_())
Example #8
Source File: haeclient.py From hae with MIT License | 5 votes |
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_())
Example #9
Source File: main.py From pdfdir with GNU General Public License v3.0 | 5 votes |
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_())
Example #10
Source File: test_translations.py From Hqgis with GNU General Public License v3.0 | 5 votes |
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)
Example #11
Source File: hqgis.py From Hqgis with GNU General Public License v3.0 | 5 votes |
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
Example #12
Source File: __main__.py From Lector with GNU General Public License v3.0 | 5 votes |
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_()
Example #13
Source File: test_translations.py From raster-vision-qgis with GNU General Public License v3.0 | 5 votes |
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)
Example #14
Source File: raster_vision.py From raster-vision-qgis with GNU General Public License v3.0 | 5 votes |
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
Example #15
Source File: dzetsaka.py From dzetsaka with GNU General Public License v3.0 | 4 votes |
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 # add Processing loadAlgorithms # init dialog and dzetsaka dock QDialog.__init__(self) #sender = self.sender() self.settings = QSettings() self.loadConfig() self.provider = dzetsakaProvider(self.providerType) # initialize plugin directory self.plugin_dir = os.path.dirname(__file__) if self.firstInstallation is True: self.showWelcomeWidget() # initialize locale """ locale = self.settings.value('locale/userLocale')[0:2] locale_path = os.path.join( self.plugin_dir, 'i18n', 'dzetsaka_{}.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) """ # Declare instance attributes self.actions = [] self.menu = self.tr(u'&dzetsaka') # # TODO: We are going to let the user set this up in a future iteration # self.toolbar = self.iface.addToolBar(u'dzetsaka') # self.toolbar.setObjectName(u'dzetsaka') self.pluginIsActive = False self.dockwidget = None # # param self.lastSaveDir = '' # run dock # self.run()
Example #16
Source File: run_GUI.py From pyleecan with Apache License 2.0 | 4 votes |
def run_GUI(argv): # Default material data path # Script to be used to test in dev a = QApplication(argv) # Set CSS # a.setStyleSheet("QLineEdit { background-color: yellow }") # Setup the translation translationFile = "pyleecan_fr.qm" translator = QTranslator() translator.load(translationFile, "GUI//i18n") a.installTranslator(translator) # Setting the material library matlib = MatLib(MATLIB_DIR) # MatLib widget mat_widget = DMatLib(matlib, selected=0) # Machine Setup Widget c = DMachineSetup(dmatlib=mat_widget, machine_path=join(DATA_DIR, "Machine")) if EXT_GUI: # Setup extended GUI with sub windows icon = dirname(__file__) + "/GUI/Resources/images/icon/pyleecan_64.png" window = SidebarWindow() window.setWindowIcon(QIcon(icon)) update_step = lambda: c.set_nav(c.nav_step.currentRow()) window.addSubWindow("Design", c, update_step) window.DesignWidget = c plt_widget = MachinePlotWidget(window) window.addSubWindow("Plot", plt_widget, plt_widget.update) mat_widget.installEventFilter(window) window.addSubWindow("MatLib", mat_widget, mat_widget.update_list_mat) tree = TreeView() tree_fcn = lambda: tree.generate(getattr(c, "machine")) window.addSubWindow("TreeView", tree, tree_fcn) option = WGuiOption(machine_setup=c, matlib=matlib) window.addSubWindow("Option", option) window.show() else: # "Normal" GUI c.show() exit(a.exec_())
Example #17
Source File: after_download.py From persepolis with GNU General Public License v3.0 | 4 votes |
def __init__(self, parent, dict, persepolis_setting): super().__init__(persepolis_setting) self.persepolis_setting = persepolis_setting self.dict = dict self.parent = parent # 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) # connecting buttons self.open_pushButtun.clicked.connect(self.openFile) self.open_folder_pushButtun.clicked.connect(self.openFolder) self.ok_pushButton.clicked.connect(self.okButtonPressed) # labels # find gid gid = self.dict['gid'] # get file_path from data base self.add_link_dict = self.parent.persepolis_db.searchGidInAddLinkTable(gid) file_path = self.add_link_dict['download_path'] # save_as self.save_as_lineEdit.setText(file_path) self.save_as_lineEdit.setToolTip(file_path) # link link = str(self.dict['link']) self.link_lineEdit.setText(link) self.link_lineEdit.setToolTip(link) # file_name window_title = str(self.dict['file_name']) file_name = QCoreApplication.translate("after_download_src_ui_tr", "<b>File name</b>: ") + \ window_title self.setWindowTitle(window_title) self.file_name_label.setText(file_name) # size size = QCoreApplication.translate("after_download_src_ui_tr", "<b>Size</b>: ") + str(self.dict['size']) self.size_label.setText(size) # disable link_lineEdit and save_as_lineEdit self.link_lineEdit.setEnabled(False) self.save_as_lineEdit.setEnabled(False) # set window size and position size = self.persepolis_setting.value( 'AfterDownloadWindow/size', QSize(570, 290)) position = self.persepolis_setting.value( 'AfterDownloadWindow/position', QPoint(300, 300)) self.resize(size) self.move(position)
Example #18
Source File: progress.py From persepolis with GNU General Public License v3.0 | 4 votes |
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
Example #19
Source File: offline_map_matching.py From Offline-MapMatching with GNU General Public License v3.0 | 4 votes |
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', 'OfflineMapMatching_{}.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 = OfflineMapMatchingDialog() # Declare instance attributes self.actions = [] self.menu = self.tr(u'&Offline-MapMatching') # TODO: We are going to let the user set this up in a future iteration self.toolbar = self.iface.addToolBar(u'OfflineMapMatching') self.toolbar.setObjectName(u'OfflineMapMatching') #add help-document to the GUI dir = os.path.dirname(__file__) file = os.path.abspath(os.path.join(dir, 'help_docs', 'help.html')) if os.path.exists(file): with open(file) as helpf: help = helpf.read() self.dlg.textBrowser_help.insertHtml(help) self.dlg.textBrowser_help.moveCursor(QTextCursor.Start) #declare additional instance vars self.map_matcher = MapMatcher() self.provider = OfflineMapMatchingProvider() #connect slots and signals self.dlg.comboBox_trajectory.currentIndexChanged.connect(self.startPopulateFieldsComboBox) self.dlg.pushButton_start.clicked.connect(self.startMapMatching) #set a default crs to avoid problems in QGIS 3.4 self.dlg.mQgsProjectionSelectionWidget.setCrs(QgsCoordinateReferenceSystem('EPSG:4326')) # noinspection PyMethodMayBeStatic
Example #20
Source File: setting_ui.py From persepolis with GNU General Public License v3.0 | 4 votes |
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"))