PluginPyInstaller.py

branch
eric7
changeset 38
fc9ef9dcd51a
parent 35
d9b3cadaf707
child 43
01ce3d6f7a07
diff -r 9ecfea29a47c -r fc9ef9dcd51a PluginPyInstaller.py
--- a/PluginPyInstaller.py	Thu May 27 19:23:58 2021 +0200
+++ b/PluginPyInstaller.py	Thu May 27 20:28:55 2021 +0200
@@ -12,14 +12,14 @@
 import platform
 import shutil
 
-from PyQt5.QtCore import (
+from PyQt6.QtCore import (
     pyqtSlot, QObject, QCoreApplication, QTranslator, QProcess
 )
-from PyQt5.QtWidgets import QDialog
+from PyQt6.QtWidgets import QDialog
 
-from E5Gui import E5MessageBox
-from E5Gui.E5Action import E5Action
-from E5Gui.E5Application import e5App
+from EricWidgets import EricMessageBox
+from EricGui.EricAction import EricAction
+from EricWidgets.EricApplication import ericApp
 
 import Utilities
 
@@ -28,9 +28,9 @@
 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
 autoactivate = True
 deactivateable = True
-version = "2.2.0"
+version = "1.0.0"
 className = "PyInstallerPlugin"
-packageName = "PyInstaller"
+packageName = "PyInstallerInterface"
 shortDescription = "Show dialogs to configure and execute PyInstaller."
 longDescription = (
     """This plug-in implements dialogs to configure and execute PyInstaller"""
@@ -89,9 +89,7 @@
     """
     # Determine Python Version
     if majorVersion == 3:
-        minorVersions = range(10)
-    elif majorVersion == 2:
-        minorVersions = [7]     # PyInstaller supports just Python 2.7
+        minorVersions = range(16)
     else:
         return []
     
@@ -214,7 +212,8 @@
     """
     Restricted function to check the availability of pyinstaller.
     
-    @return flag indicating availability (boolean)
+    @return flag indicating availability
+    @rtype bool
     """
     global error, exePy3
     
@@ -266,7 +265,8 @@
         """
         Public method to activate this plug-in.
         
-        @return tuple of None and activation status (boolean)
+        @return tuple of None and activation status
+        @rtype tuple of (None, bool)
         """
         global error
         
@@ -281,13 +281,13 @@
         # clear previous error
         error = ""
         
-        project = e5App().getObject("Project")
+        project = ericApp().getObject("Project")
         menu = project.getMenu("Packagers")
         if menu:
             self.__projectSeparator = menu.addSeparator()
             
             # Execute PyInstaller
-            act = E5Action(
+            act = EricAction(
                 self.tr('Execute PyInstaller'),
                 self.tr('Execute Py&Installer'), 0, 0,
                 self, 'packagers_pyinstaller_run')
@@ -305,7 +305,7 @@
             self.__projectActs.append(act)
             
             # Execute pyi-makespec
-            act = E5Action(
+            act = EricAction(
                 self.tr('Make PyInstaller Spec File'),
                 self.tr('Make PyInstaller &Spec File'), 0, 0,
                 self, 'packagers_pyinstaller_spec')
@@ -323,7 +323,7 @@
             self.__projectActs.append(act)
             
             # clean the pyinstaller created directories
-            act = E5Action(
+            act = EricAction(
                 self.tr('Clean PyInstaller'),
                 self.tr('&Clean PyInstaller'), 0, 0,
                 self, 'packagers_pyinstaller_clean')
@@ -339,7 +339,7 @@
             menu.addAction(act)
             self.__projectActs.append(act)
             
-            project.addE5Actions(self.__projectActs)
+            project.addEricActions(self.__projectActs)
             project.showMenu.connect(self.__projectShowMenu)
         
         return None, True
@@ -348,14 +348,14 @@
         """
         Public method to deactivate this plug-in.
         """
-        menu = e5App().getObject("Project").getMenu("Packagers")
+        menu = ericApp().getObject("Project").getMenu("Packagers")
         if menu:
             for act in self.__projectActs:
                 menu.removeAction(act)
             if self.__projectSeparator:
                 menu.removeAction(self.__projectSeparator)
             
-            e5App().getObject("Project").removeE5Actions(
+            ericApp().getObject("Project").removeEricActions(
                 self.__projectActs)
         
         self.__initialize()
@@ -372,7 +372,8 @@
         """
         if menuName == "Packagers":
             enable = (
-                e5App().getObject("Project").getProjectLanguage() == "Python3"
+                ericApp().getObject("Project").getProjectLanguage() ==
+                "Python3"
             )
             for act in self.__projectActs:
                 act.setEnabled(enable)
@@ -385,13 +386,13 @@
             loc = self.__ui.getLocale()
             if loc and loc != "C":
                 locale_dir = os.path.join(os.path.dirname(__file__),
-                                          "PyInstaller", "i18n")
+                                          "PyInstallerInterface", "i18n")
                 translation = "pyinstaller_{0}".format(loc)
                 translator = QTranslator(None)
                 loaded = translator.load(translation, locale_dir)
                 if loaded:
                     self.__translator = translator
-                    e5App().installTranslator(self.__translator)
+                    ericApp().installTranslator(self.__translator)
                 else:
                     print("Warning: translation file '{0}' could not be"
                           " loaded.".format(translation))
@@ -403,13 +404,13 @@
         Private slot to execute the pyinstaller command for the current
         project.
         """
-        project = e5App().getObject("Project")
+        project = ericApp().getObject("Project")
         majorVersionStr = project.getProjectLanguage()
         if majorVersionStr == "Python3":
             executables = [f for f in exePy3 if
                            f.endswith(("pyinstaller", "pyinstaller.exe"))]
             if not executables:
-                E5MessageBox.critical(
+                EricMessageBox.critical(
                     self.__ui,
                     self.tr("pyinstaller"),
                     self.tr("""The pyinstaller executable could not be"""
@@ -420,18 +421,18 @@
             if not project.checkAllScriptsDirty(reportSyntaxErrors=True):
                 return
             
-            from PyInstaller.PyInstallerConfigDialog import (
+            from PyInstallerInterface.PyInstallerConfigDialog import (
                 PyInstallerConfigDialog
             )
             params = project.getData('PACKAGERSPARMS', "PYINSTALLER")
             dlg = PyInstallerConfigDialog(project, executables, params,
                                           mode="installer")
-            if dlg.exec() == QDialog.Accepted:
+            if dlg.exec() == QDialog.DialogCode.Accepted:
                 args, params, script = dlg.generateParameters()
                 project.setData('PACKAGERSPARMS', "PYINSTALLER", params)
                 
                 # now do the call
-                from PyInstaller.PyInstallerExecDialog import (
+                from PyInstallerInterface.PyInstallerExecDialog import (
                     PyInstallerExecDialog
                 )
                 dia = PyInstallerExecDialog("pyinstaller")
@@ -446,13 +447,13 @@
         Private slot to execute the pyi-makespec command for the current
         project to generate a spec file to be used by pyinstaller.
         """
-        project = e5App().getObject("Project")
+        project = ericApp().getObject("Project")
         majorVersionStr = project.getProjectLanguage()
         if majorVersionStr == "Python3":
             executables = [f for f in exePy3 if
                            f.endswith(("pyi-makespec", "pyi-makespec.exe"))]
             if not executables:
-                E5MessageBox.critical(
+                EricMessageBox.critical(
                     self.__ui,
                     self.tr("pyi-makespec"),
                     self.tr("""The pyi-makespec executable could not be"""
@@ -463,18 +464,18 @@
             if not project.checkAllScriptsDirty(reportSyntaxErrors=True):
                 return
             
-            from PyInstaller.PyInstallerConfigDialog import (
+            from PyInstallerInterface.PyInstallerConfigDialog import (
                 PyInstallerConfigDialog
             )
             params = project.getData('PACKAGERSPARMS', "PYINSTALLER")
             dlg = PyInstallerConfigDialog(project, executables, params,
                                           mode="spec")
-            if dlg.exec() == QDialog.Accepted:
+            if dlg.exec() == QDialog.DialogCode.Accepted:
                 args, params, script = dlg.generateParameters()
                 project.setData('PACKAGERSPARMS', "PYINSTALLER", params)
                 
                 # now do the call
-                from PyInstaller.PyInstallerExecDialog import (
+                from PyInstallerInterface.PyInstallerExecDialog import (
                     PyInstallerExecDialog
                 )
                 dia = PyInstallerExecDialog("pyinstaller")
@@ -488,17 +489,30 @@
         """
         Private slot to remove the directories created by pyinstaller.
         """
-        project = e5App().getObject("Project")
+        project = ericApp().getObject("Project")
         
-        from PyInstaller.PyInstallerCleanupDialog import (
+        from PyInstallerInterface.PyInstallerCleanupDialog import (
             PyInstallerCleanupDialog
         )
         dlg = PyInstallerCleanupDialog()
-        if dlg.exec() == QDialog.Accepted:
+        if dlg.exec() == QDialog.DialogCode.Accepted:
             removeDirs = dlg.getDirectories()
             for directory in removeDirs:
                 rd = os.path.join(project.getProjectPath(), directory)
                 shutil.rmtree(rd, ignore_errors=True)
 
+
+def installDependencies(pipInstall):
+    """
+    Function to install dependencies of this plug-in.
+    
+    @param pipInstall function to be called with a list of package names.
+    @type function
+    """
+    try:
+        import PyInstaller         # __IGNORE_WARNING__
+    except ImportError:
+        pipInstall(["pyinstaller"])
+
 #
 # eflag: noqa = M801

eric ide

mercurial