--- a/PluginPySide2PyQt.py Tue Jun 01 17:49:53 2021 +0200 +++ b/PluginPySide2PyQt.py Tue Jun 01 17:58:20 2021 +0200 @@ -10,23 +10,24 @@ 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 # Start-Of-Header name = "PySide to PyQt (and vice versa) Plug-in" author = "Detlev Offenbach <detlev@die-offenbachs.de>" autoactivate = True deactivateable = True -version = "3.1.1" +version = "1.0.0" className = "PySide2PyQtPlugin" packageName = "PySide2PyQt" shortDescription = "Convert PySide file to PyQt and vice versa" longDescription = ( """This plug-in implements a tool to convert a PySide2 file to PyQt5""" - """ and vice versa. It works with the text of the current editor.""" + """ and vice versa or a PySide6 file to PyQt6 and vice versa. It works""" + """ with the text of the current editor.""" ) needsRestart = False pyqtApi = 2 @@ -43,7 +44,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 @@ -60,7 +62,8 @@ """ Public method to activate this plugin. - @return tuple of None and activation status (boolean) + @return tuple of None and activation status + @rtype (None, bool) """ global error error = "" # clear previous error @@ -75,12 +78,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 @@ -97,9 +100,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(): @@ -124,7 +127,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)) @@ -137,22 +140,28 @@ self.__menu = QMenu(self.tr("PySide to/from PyQt")) self.__menu.addAction(self.tr("PySide2 to PyQt5"), lambda: self.__pyside2Pyqt("pyside2", "pyqt5")) - self.__menu.addSeparator() self.__menu.addAction(self.tr("PyQt5 to PySide2"), lambda: self.__pyqt2Pyside("pyqt5", "pyside2")) + self.__menu.addSeparator() + self.__menu.addAction(self.tr("PySide6 to PyQt6"), + lambda: self.__pyside2Pyqt("pyside6", "pyqt6")) + self.__menu.addAction(self.tr("PyQt6 to PySide6"), + lambda: self.__pyqt2Pyside("pyqt6", "pyside6")) self.__menu.setEnabled(False) def __populateMenu(self, name, menu): """ 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 - editor = e5App().getObject("ViewManager").activeWindow() + editor = ericApp().getObject("ViewManager").activeWindow() if name == "Tools": if not menu.isEmpty(): @@ -166,7 +175,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: @@ -183,7 +193,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] @@ -195,9 +206,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 @@ -216,12 +230,12 @@ Private slot to convert the code of the current editor from PySide to PyQt. - @param pyside PySide variant (pyside2) + @param pyside PySide variant (pyside2 or pyside6) @type str - @param pyqt PyQt variant (pyqt5) + @param pyqt PyQt variant (pyqt5 or pyqt6) @type str """ - editor = e5App().getObject("ViewManager").activeWindow() + editor = ericApp().getObject("ViewManager").activeWindow() if editor is None: return @@ -229,14 +243,24 @@ if pyqt == "pyqt5" and pyside == "pyside2": newText = ( text + .replace("PySide2", "PyQt5") .replace("Signal", "pyqtSignal") .replace("Slot", "pyqtSlot") .replace("Property", "pyqtProperty") - .replace("PySide2", "PyQt5") .replace("pyside2-uic", "pyuic5") .replace("pyside2-rcc", "pyrcc5") .replace("pyside2-lupdate", "pylupdate5") ) + elif pyqt == "pyqt6" and pyside == "pyside6": + newText = ( + text + .replace("PySide6", "PyQt6") + .replace("Signal", "pyqtSignal") + .replace("Slot", "pyqtSlot") + .replace("Property", "pyqtProperty") + .replace("pyside6-uic", "pyuic6") + .replace("pyside6-lupdate", "pylupdate6") + ) else: return @@ -251,12 +275,12 @@ Private slot to convert the code of the current editor from PyQt to PySide. - @param pyqt PyQt variant (pyqt5) + @param pyqt PyQt variant (pyqt5 or pyqt6) @type str - @param pyside PySide variant (pyside2) + @param pyside PySide variant (pyside2 or pyside6) @type str """ - editor = e5App().getObject("ViewManager").activeWindow() + editor = ericApp().getObject("ViewManager").activeWindow() if editor is None: return @@ -272,6 +296,16 @@ .replace("pyrcc5", "pyside2-rcc") .replace("pylupdate5", "pyside2-lupdate") ) + elif pyqt == "pyqt6" and pyside == "pyside6": + newText = ( + text + .replace("PyQt6", "PySide6") + .replace("pyqtSignal", "Signal") + .replace("pyqtSlot", "Slot") + .replace("pyqtProperty", "Property") + .replace("pyuic6", "pyside6-uic") + .replace("pylupdate6", "pyside6-lupdate") + ) else: return