--- a/ProjectFlask/FlaskBabelExtension/PyBabelProjectExtension.py Sat May 29 15:04:41 2021 +0200 +++ b/ProjectFlask/FlaskBabelExtension/PyBabelProjectExtension.py Sun May 30 17:33:37 2021 +0200 @@ -11,12 +11,12 @@ import re import contextlib -from PyQt5.QtCore import pyqtSlot, QObject, QProcess -from PyQt5.QtWidgets import QDialog, QMenu +from PyQt6.QtCore import pyqtSlot, QObject, QProcess +from PyQt6.QtWidgets import QDialog, QMenu -from E5Gui import E5MessageBox -from E5Gui.E5Application import e5App -from E5Gui.E5Action import E5Action +from EricWidgets import EricMessageBox +from EricWidgets.EricApplication import ericApp +from EricGui.EricAction import EricAction from .PyBabelCommandDialog import PyBabelCommandDialog @@ -43,7 +43,7 @@ self.__plugin = plugin self.__project = project - self.__e5project = e5App().getObject("Project") + self.__ericProject = ericApp().getObject("Project") self.__hooksInstalled = False @@ -53,7 +53,7 @@ """ self.actions = [] - self.pybabelConfigAct = E5Action( + self.pybabelConfigAct = EricAction( self.tr('Configure flask-babel'), self.tr('&Configure flask-babel'), 0, 0, @@ -69,7 +69,7 @@ self.__configurePyBabel) self.actions.append(self.pybabelConfigAct) - self.pybabelInstallAct = E5Action( + self.pybabelInstallAct = EricAction( self.tr('Install flask-babel'), self.tr('&Install flask-babel'), 0, 0, @@ -86,7 +86,7 @@ self.__installFlaskBabel) self.actions.append(self.pybabelInstallAct) - self.pybabelAvailabilityAct = E5Action( + self.pybabelAvailabilityAct = EricAction( self.tr('Check flask-babel Availability'), self.tr('Check flask-babel &Availability'), 0, 0, @@ -138,10 +138,10 @@ Public method to add our hook methods. """ if self.__project.hasCapability("flask-babel"): - self.__e5project.projectLanguageAddedByCode.connect( + self.__ericProject.projectLanguageAddedByCode.connect( self.__projectLanguageAdded) self.__translationsBrowser = ( - e5App().getObject("ProjectBrowser") + ericApp().getObject("ProjectBrowser") .getProjectBrowser("translations")) self.__translationsBrowser.addHookMethodAndMenuEntry( "extractMessages", self.extractMessages, @@ -175,7 +175,7 @@ Public method to remove our hook methods. """ if self.__hooksInstalled: - self.__e5project.projectLanguageAddedByCode.disconnect( + self.__ericProject.projectLanguageAddedByCode.disconnect( self.__projectLanguageAdded) self.__translationsBrowser.removeHookMethod( "extractMessages") @@ -240,7 +240,8 @@ detector = os.path.join( os.path.dirname(__file__), "FlaskBabelDetector.py") proc = QProcess() - proc.setProcessChannelMode(QProcess.MergedChannels) + proc.setProcessChannelMode( + QProcess.ProcessChannelMode.MergedChannels) proc.start(interpreter, [detector]) finished = proc.waitForFinished(30000) if finished and proc.exitCode() == 0: @@ -257,17 +258,17 @@ config = self.__project.getData("flask-babel", "") dlg = PyBabelConfigDialog(config) - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: config = dlg.getConfiguration() self.__project.setData("flask-babel", "", config) - self.__e5project.setTranslationPattern(os.path.join( + self.__ericProject.setTranslationPattern(os.path.join( config["translationsDirectory"], "%language%", "LC_MESSAGES", "{0}.po".format(config["domain"]) )) - self.__e5project.setDirty(True) + self.__ericProject.setDirty(True) - cfgFileName = self.__e5project.getAbsoluteUniversalPath( + cfgFileName = self.__ericProject.getAbsoluteUniversalPath( config["configFile"]) if not os.path.exists(cfgFileName): self.__createBabelCfg(cfgFileName) @@ -286,7 +287,7 @@ configFileName = self.__project.getData("flask-babel", "configFile") if configFileName: - cfgFileName = self.__e5project.getAbsoluteUniversalPath( + cfgFileName = self.__ericProject.getAbsoluteUniversalPath( configFileName) if os.path.exists(cfgFileName): return True @@ -317,8 +318,8 @@ try: with open(configFile, "w") as f: f.write(template.format(app)) - self.__e5project.appendFile(configFile) - E5MessageBox.information( + self.__ericProject.appendFile(configFile) + EricMessageBox.information( None, self.tr("Generate PyBabel Configuration File"), self.tr("""The PyBabel configuration file was created.""" @@ -327,7 +328,7 @@ ) return True except OSError as err: - E5MessageBox.warning( + EricMessageBox.warning( None, self.tr("Generate PyBabel Configuration File"), self.tr("""<p>The PyBabel Configuration File could not be""" @@ -345,11 +346,11 @@ venvName = self.__project.getVirtualEnvironment() if venvName: interpreter = self.__project.getFullCommand("python") - pip = e5App().getObject("Pip") + pip = ericApp().getObject("Pip") pip.installPackages(["flask-babel"], interpreter=interpreter) self.determineCapability() else: - E5MessageBox.critical( + EricMessageBox.critical( None, self.tr("Install flask-babel"), self.tr("The 'flask-babel' extension could not be installed" @@ -367,7 +368,7 @@ if self.__project.hasCapability("flask-babel") else self.tr("The 'flask-babel' extension is not installed.") ) - E5MessageBox.information( + EricMessageBox.information( None, self.tr("flask-babel Availability"), msg) @@ -381,13 +382,13 @@ @return extracted locale @rtype str or None """ - if self.__e5project.getTranslationPattern(): + if self.__ericProject.getTranslationPattern(): filename = os.path.splitext(filename)[0] + ".po" # On Windows, path typically contains backslashes. This leads # to an invalid search pattern '...\(' because the opening bracket # will be escaped. - pattern = self.__e5project.getTranslationPattern() + pattern = self.__ericProject.getTranslationPattern() pattern = os.path.normpath(pattern) pattern = pattern.replace("%language%", "(.*?)") pattern = pattern.replace('\\', '\\\\') @@ -409,7 +410,7 @@ workdir = self.__project.getApplication()[0] started, pid = QProcess.startDetached(editor, [poFile], workdir) if not started: - E5MessageBox.critical( + EricMessageBox.critical( None, self.tr('Process Generation Error'), self.tr('The translations editor process ({0}) could' @@ -423,7 +424,7 @@ title = self.tr("Extract messages") if self.__ensurePybabelConfigured(): workdir = self.__project.getApplication()[0] - potFile = self.__e5project.getAbsoluteUniversalPath( + potFile = self.__ericProject.getAbsoluteUniversalPath( self.__project.getData("flask-babel", "catalogFile")) with contextlib.suppress(OSError): @@ -433,7 +434,7 @@ args = [ "-F", os.path.relpath( - self.__e5project.getAbsoluteUniversalPath( + self.__ericProject.getAbsoluteUniversalPath( self.__project.getData("flask-babel", "configFile")), workdir ) @@ -455,7 +456,7 @@ res = dlg.startCommand("extract", args, workdir) if res: dlg.exec() - self.__e5project.appendFile(potFile) + self.__ericProject.appendFile(potFile) def __projectLanguageAdded(self, code): """ @@ -469,10 +470,10 @@ if self.__ensurePybabelConfigured(): workdir = self.__project.getApplication()[0] - langFile = self.__e5project.getAbsoluteUniversalPath( - self.__e5project.getTranslationPattern().replace( + langFile = self.__ericProject.getAbsoluteUniversalPath( + self.__ericProject.getTranslationPattern().replace( "%language%", code)) - potFile = self.__e5project.getAbsoluteUniversalPath( + potFile = self.__ericProject.getAbsoluteUniversalPath( self.__project.getData("flask-babel", "catalogFile")) args = [ @@ -492,7 +493,7 @@ if res: dlg.exec() - self.__e5project.appendFile(langFile) + self.__ericProject.appendFile(langFile) def compileCatalogs(self, filenames): """ @@ -505,8 +506,12 @@ if self.__ensurePybabelConfigured(): workdir = self.__project.getApplication()[0] - translationsDirectory = self.__e5project.getAbsoluteUniversalPath( - self.__project.getData("flask-babel", "translationsDirectory")) + translationsDirectory = ( + self.__ericProject.getAbsoluteUniversalPath( + self.__project.getData( + "flask-babel", "translationsDirectory") + ) + ) args = [ "--domain={0}".format( @@ -529,7 +534,7 @@ for fileName in entry[2]: fullName = os.path.join(entry[0], fileName) if fullName.endswith('.mo'): - self.__e5project.appendFile(fullName) + self.__ericProject.appendFile(fullName) def compileSelectedCatalogs(self, filenames): """ @@ -543,7 +548,7 @@ locales = {self.__getLocale(f) for f in filenames} if len(locales) == 0: - E5MessageBox.warning( + EricMessageBox.warning( self.__ui, title, self.tr('No locales detected. Aborting...')) @@ -551,8 +556,12 @@ if self.__ensurePybabelConfigured(): workdir = self.__project.getApplication()[0] - translationsDirectory = self.__e5project.getAbsoluteUniversalPath( - self.__project.getData("flask-babel", "translationsDirectory")) + translationsDirectory = ( + self.__ericProject.getAbsoluteUniversalPath( + self.__project.getData( + "flask-babel", "translationsDirectory") + ) + ) argsList = [] for loc in locales: @@ -579,7 +588,7 @@ for fileName in entry[2]: fullName = os.path.join(entry[0], fileName) if fullName.endswith('.mo'): - self.__e5project.appendFile(fullName) + self.__ericProject.appendFile(fullName) def updateCatalogs(self, filenames, withObsolete=False): """ @@ -594,9 +603,13 @@ if self.__ensurePybabelConfigured(): workdir = self.__project.getApplication()[0] - translationsDirectory = self.__e5project.getAbsoluteUniversalPath( - self.__project.getData("flask-babel", "translationsDirectory")) - potFile = self.__e5project.getAbsoluteUniversalPath( + translationsDirectory = ( + self.__ericProject.getAbsoluteUniversalPath( + self.__project.getData( + "flask-babel", "translationsDirectory") + ) + ) + potFile = self.__ericProject.getAbsoluteUniversalPath( self.__project.getData("flask-babel", "catalogFile")) args = [ @@ -641,7 +654,7 @@ locales = {self.__getLocale(f) for f in filenames} if len(locales) == 0: - E5MessageBox.warning( + EricMessageBox.warning( self.__ui, title, self.tr('No locales detected. Aborting...')) @@ -649,9 +662,13 @@ if self.__ensurePybabelConfigured(): workdir = self.__project.getApplication()[0] - translationsDirectory = self.__e5project.getAbsoluteUniversalPath( - self.__project.getData("flask-babel", "translationsDirectory")) - potFile = self.__e5project.getAbsoluteUniversalPath( + translationsDirectory = ( + self.__ericProject.getAbsoluteUniversalPath( + self.__project.getData( + "flask-babel", "translationsDirectory") + ) + ) + potFile = self.__ericProject.getAbsoluteUniversalPath( self.__project.getData("flask-babel", "catalogFile")) argsList = [] for loc in locales: