class App(QApplication): def __init__(self, args): super(App, self).__init__(args) self.setOrganizationName("DocumentStyle") self.setOrganizationDomain("lloyd konneker") self.setApplicationName("testStyling") print( "To test i18n localization in Spanish, set OS locale or temporarily >export LANGUAGE=es" ) self._establishTranslator() # i18n global mainWindow # for access by ToolStyler mainWindow = MainWindow() mainWindow.setGeometry(100, 100, 500, 400) mainWindow.show() self.mainWindow = mainWindow if config.useQML: windowMgr.findRootWindow() # needed as parent of QQuickViews """ qtEmbeddedQmlFramework knows how to locate qml resources, even if embedded. Alternative old code: resourceRoot = QFileInfo(__file__).absolutePath() + '/documentStyle' self.cascadion = StyleSheetCascadion(resourceRoot=resourceRoot) """ resourceMgr.setResourceRoot(fileMainWasLoadedFrom=__file__, appPackageName='documentStyle') # cacadion might use global resourceMgr, but it is not passed. self.cascadion = StyleSheetCascadion() self.cascadion.preGui(parentWindow=mainWindow) mainWindow.newToolStyler() # depends on cascadion self.documentView = mainWindow.newDocument() # depends on cascadion # Arrange that changes to styleSheets will polish doc self.cascadion.connectSignals(mainWindow.scene.polish) # Initial polishing (using Styleable) mainWindow.scene.polish() self.exec_() def _establishTranslator(self): locale = QLocale.system() # :/ is resource directory, often same as app's working directory? translationsName = "documentStyle_" + locale.name() # translationsName = "documentStyle_es" # Spanish self.myTranslator = self._installTranslator(name=translationsName) # !!! Keep reference, since installing does not copy instance def _installTranslator(self, name): ''' Create a translator for given name. ''' translator = QTranslator() result = translator.load(name) if not result: print("Failed to load translation for:", name) # Not an exception: program continues in default (usually English) if not self.installTranslator(translator): print("Failed to install translator.") result = None else: print("Localized using", name) result = translator return result # !!! Caller should keep a reference
class App(QApplication): def __init__(self, args): super(App, self).__init__(args) self.setOrganizationName("DocumentStyle") self.setOrganizationDomain("lloyd konneker") self.setApplicationName("testStyling") print("To test i18n localization in Spanish, set OS locale or temporarily >export LANGUAGE=es") self._establishTranslator() # i18n global mainWindow # for access by ToolStyler mainWindow = MainWindow() mainWindow.setGeometry(100, 100, 500, 400) mainWindow.show() self.mainWindow = mainWindow if config.useQML: windowMgr.findRootWindow() # needed as parent of QQuickViews """ qtEmbeddedQmlFramework knows how to locate qml resources, even if embedded. Alternative old code: resourceRoot = QFileInfo(__file__).absolutePath() + '/documentStyle' self.cascadion = StyleSheetCascadion(resourceRoot=resourceRoot) """ resourceMgr.setResourceRoot(fileMainWasLoadedFrom=__file__, appPackageName='documentStyle') # cacadion might use global resourceMgr, but it is not passed. self.cascadion = StyleSheetCascadion() self.cascadion.preGui(parentWindow=mainWindow) mainWindow.newToolStyler() # depends on cascadion self.documentView = mainWindow.newDocument() # depends on cascadion # Arrange that changes to styleSheets will polish doc self.cascadion.connectSignals(mainWindow.scene.polish) # Initial polishing (using Styleable) mainWindow.scene.polish() self.exec_() def _establishTranslator(self): locale = QLocale.system() # :/ is resource directory, often same as app's working directory? translationsName = "documentStyle_" + locale.name() # translationsName = "documentStyle_es" # Spanish self.myTranslator = self._installTranslator(name=translationsName) # !!! Keep reference, since installing does not copy instance def _installTranslator(self, name): ''' Create a translator for given name. ''' translator = QTranslator() result = translator.load(name) if not result: print("Failed to load translation for:", name) # Not an exception: program continues in default (usually English) if not self.installTranslator(translator): print("Failed to install translator.") result = None else: print("Localized using", name) result = translator return result # !!! Caller should keep a reference