PluginProjectWeb.py

branch
eric7
changeset 38
6a12561fc0b5
parent 35
a3f1dcf94fe4
child 40
a9b17341d181
--- a/PluginProjectWeb.py	Tue May 25 19:44:14 2021 +0200
+++ b/PluginProjectWeb.py	Tue May 25 20:12:47 2021 +0200
@@ -10,10 +10,10 @@
 import contextlib
 import os
 
-from PyQt5.QtCore import QObject, QTranslator
-from PyQt5.QtWidgets import QMenu
+from PyQt6.QtCore import QObject, QTranslator
+from PyQt6.QtWidgets import QMenu
 
-from E5Gui.E5Application import e5App
+from EricWidgets.EricApplication import ericApp
 
 import Preferences
 
@@ -29,13 +29,13 @@
 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
 autoactivate = True
 deactivateable = True
-version = "2.2.0"
+version = "1.0.0"
 className = "ProjectWebPlugin"
 packageName = "ProjectWeb"
 shortDescription = "Support for Web projects and web related tools."
 longDescription = (
     """This plug-in provides support for ordinary web projects and some web"""
-    """ related tools.\n\nIt requires BeautifulSoup4 for some of its"""
+    """ related tools.\n\nIt uses BeautifulSoup4 for some of its"""
     """ functionality."""
 )
 needsRestart = False
@@ -53,7 +53,8 @@
         """
         Constructor
         
-        @param ui reference to the user interface object (UI.UserInterface)
+        @param ui reference to the user interface object
+        @type UserInterface
         """
         super().__init__(ui)
         self.__ui = ui
@@ -68,7 +69,7 @@
         """
         Private slot to (re)initialize the plugin.
         """
-        self.__e5project = e5App().getObject("Project")
+        self.__ericProject = ericApp().getObject("Project")
         
         self.__editors = {}
         self.__mainActions = []
@@ -77,13 +78,14 @@
         """
         Public method to activate this plugin.
         
-        @return tuple of None and activation status (boolean)
+        @return tuple of None and activation status
+        @rtype tuple of (None, bool)
         """
         global error
         error = ""     # clear previous error
         
         # it is not registered for a specific programming language
-        self.__e5project.registerProjectType(
+        self.__ericProject.registerProjectType(
             "Web", self.tr("Web"),
             self.fileTypesCallback)
         
@@ -105,12 +107,12 @@
             act = menu.addMenu(self.__menu)
             self.__mainActions.append(act)
         
-        e5App().getObject("ViewManager").editorOpenedEd.connect(
+        ericApp().getObject("ViewManager").editorOpenedEd.connect(
             self.__editorOpened)
-        e5App().getObject("ViewManager").editorClosedEd.connect(
+        ericApp().getObject("ViewManager").editorClosedEd.connect(
             self.__editorClosed)
         
-        for editor in e5App().getObject("ViewManager").getOpenEditors():
+        for editor in ericApp().getObject("ViewManager").getOpenEditors():
             self.__editorOpened(editor)
         
         return None, True
@@ -119,7 +121,7 @@
         """
         Public method to deactivate this plugin.
         """
-        self.__e5project.unregisterProjectType("Web")
+        self.__ericProject.unregisterProjectType("Web")
         
         self.__ui.showMenu.disconnect(self.__populateMenu)
         
@@ -129,9 +131,9 @@
                 menu.removeAction(act)
         self.__mainActions = []
 
-        e5App().getObject("ViewManager").editorOpenedEd.disconnect(
+        ericApp().getObject("ViewManager").editorOpenedEd.disconnect(
             self.__editorOpened)
-        e5App().getObject("ViewManager").editorClosedEd.disconnect(
+        ericApp().getObject("ViewManager").editorClosedEd.disconnect(
             self.__editorClosed)
         
         for editor, acts in self.__editors.items():
@@ -157,7 +159,7 @@
                 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))
@@ -168,8 +170,9 @@
         Public method to get the filetype associations of the Web project type.
         
         @return dictionary with file type associations
+        @rtype dict
         """
-        if self.__e5project.getProjectType() == "Web":
+        if self.__ericProject.getProjectType() == "Web":
             return {
                 "*.html": "FORMS",
                 "*.htm": "FORMS",
@@ -198,7 +201,7 @@
         """
         Private slot to prepare the menu before it is shown.
         """
-        editor = e5App().getObject("ViewManager").activeWindow()
+        editor = ericApp().getObject("ViewManager").activeWindow()
         selectionAvailable = bool(editor and editor.selectedText() != "")
         isHtml = bool(editor and
                       editor.getLanguage().lower().startswith("html"))
@@ -214,8 +217,10 @@
         """
         Private slot to populate the tools menu with our entries.
         
-        @param name name of the menu (string)
-        @param menu reference to the menu to be populated (QMenu)
+        @param name name of the menu
+        @type str
+        @param menu reference to the menu to be populated
+        @type QMenu
         """
         if name not in ["Tools", "PluginTools"]:
             return
@@ -229,7 +234,8 @@
         """
         Private slot called, when a new editor was opened.
         
-        @param editor reference to the new editor (QScintilla.Editor)
+        @param editor reference to the new editor
+        @type Editor
         """
         menu = editor.getMenu("Tools")
         if menu is not None:
@@ -245,7 +251,8 @@
         """
         Private slot called, when an editor was closed.
         
-        @param editor reference to the editor (QScintilla.Editor)
+        @param editor reference to the editor
+        @type Editor
         """
         with contextlib.suppress(KeyError):
             del self.__editors[editor]
@@ -255,9 +262,12 @@
         Private slot called, when the the editor context menu or a submenu is
         about to be shown.
         
-        @param menuName name of the menu to be shown (string)
-        @param menu reference to the menu (QMenu)
+        @param menuName name of the menu to be shown
+        @type str
+        @param menu reference to the menu
+        @type QMenu
         @param editor reference to the editor
+        @type Editor
         """
         if (
             menuName == "Tools" and
@@ -276,7 +286,7 @@
         Private slot handling the HTML5 to CSS3 conversion.
         """
         from ProjectWeb.Html5ToCss3Converter import Html5ToCss3Converter
-        vm = e5App().getObject("ViewManager")
+        vm = ericApp().getObject("ViewManager")
         editor = vm.activeWindow()
         html = editor.selectedText()
         
@@ -294,7 +304,7 @@
         Private slot handling the HTML5 to JavaScript conversion.
         """
         from ProjectWeb.Html5ToJsConverter import Html5ToJsConverter
-        vm = e5App().getObject("ViewManager")
+        vm = ericApp().getObject("ViewManager")
         editor = vm.activeWindow()
         html = editor.selectedText()
         
@@ -312,7 +322,7 @@
         Private slot handling the Prettify HTML action.
         """
         from ProjectWeb.Html5Prettifier import Html5Prettifier
-        editor = e5App().getObject("ViewManager").activeWindow()
+        editor = ericApp().getObject("ViewManager").activeWindow()
         html = editor.text()
         
         prettifier = Html5Prettifier(html)
@@ -328,5 +338,18 @@
             
             editor.setCursorPosition(cursorLine, cursorIndex)
 
+
+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 bs4         # __IGNORE_WARNING__
+    except ImportError:
+        pipInstall(["beautifulsoup4"])
+
 #
 # eflag: noqa = M801

eric ide

mercurial