Sat, 12 Jul 2014 14:55:23 +0200
Ported to PyQt5 and eric6.
--- a/.hgignore Sat Apr 26 15:53:30 2014 +0200 +++ b/.hgignore Sat Jul 12 14:55:23 2014 +0200 @@ -1,3 +1,5 @@ +glob:.eric6project +glob:_eric6project glob:.eric5project glob:_eric5project glob:.eric4project
--- a/ChangeLog Sat Apr 26 15:53:30 2014 +0200 +++ b/ChangeLog Sat Jul 12 14:55:23 2014 +0200 @@ -1,5 +1,8 @@ ChangeLog --------- +Version 2.0.0: +- ported for eric6 using PyQt5 + Version 1.0.0: - first stable release
--- a/PluginPySide2PyQt.py Sat Apr 26 15:53:30 2014 +0200 +++ b/PluginPySide2PyQt.py Sat Jul 12 14:55:23 2014 +0200 @@ -4,29 +4,30 @@ # """ -Module implementing the PySide to PyQt4 (and vice versa) plug-in. +Module implementing the PySide to PyQt (and vice versa) plug-in. """ from __future__ import unicode_literals import os -from PyQt4.QtCore import QObject, QTranslator +from PyQt5.QtCore import QObject, QTranslator +from PyQt5.QtWidgets import QMenu from E5Gui.E5Application import e5App # Start-Of-Header -name = "PySide to PyQt4 (and vice versa) Plug-in" +name = "PySide to PyQt (and vice versa) Plug-in" author = "Detlev Offenbach <detlev@die-offenbachs.de>" autoactivate = True deactivateable = True -version = "1.0.0" +version = "2.0.0" className = "PySide2PyQtPlugin" packageName = "PySide2PyQt" -shortDescription = "Convert PySide file to PyQt4 and vice versa" +shortDescription = "Convert PySide file to PyQt and vice versa" longDescription = \ """This plug-in implements a tool to convert a PySide file""" \ - """ to PyQt4 and vice versa. It works with the text of the""" \ + """ to PyQt4 or PyQt5 and vice versa. It works with the text of the""" \ """ current editor.""" needsRestart = False pyqtApi = 2 @@ -38,7 +39,7 @@ class PySide2PyQtPlugin(QObject): """ - Class implementing the PySide to PyQt4 (and vice versa) plugin. + Class implementing the PySide to PyQt (and vice versa) plugin. """ def __init__(self, ui): """ @@ -52,6 +53,8 @@ self.__translator = None self.__loadTranslator() + self.__initMenu() + self.__editors = {} def activate(self): @@ -113,6 +116,21 @@ " loaded.".format(translation)) print("Using default.") + def __initMenu(self): + """ + Private method to initialize the menu. + """ + self.__menu = QMenu(self.tr("PySide to/from PyQt")) + self.__menu.addAction(self.tr("PySide to PyQt4"), self.__pyside2Pyqt)\ + .setData("pyqt4") + self.__menu.addAction(self.tr("PySide to PyQt5"), self.__pyside2Pyqt)\ + .setData("pyqt5") + self.__menu.addAction(self.tr("PyQt4 to PySide"), self.__pyqt2Pyside)\ + .setData("pyqt4") + self.__menu.addAction(self.tr("PyQt5 to PySide"), self.__pyqt2Pyside)\ + .setData("pyqt5") + self.__menu.setEnabled(False) + def __populateMenu(self, name, menu): """ Private slot to populate the tools menu with our entries. @@ -128,10 +146,8 @@ if not menu.isEmpty(): menu.addSeparator() - menu.addAction(self.tr("PySide to PyQt4"), self.__pyside2Pyqt)\ - .setEnabled(editor is not None) - menu.addAction(self.tr("PyQt4 to PySide"), self.__pyqt2Pyside)\ - .setEnabled(editor is not None) + act = menu.addMenu(self.__menu) + act.setEnabled(editor is not None) def __editorOpened(self, editor): """ @@ -145,12 +161,9 @@ if not menu.isEmpty(): act = menu.addSeparator() self.__editors[editor].append(act) - act = menu.addAction(self.tr("PySide to PyQt4"), - self.__pyside2Pyqt) + act = menu.addMenu(self.__menu) self.__editors[editor].append(act) - act = menu.addAction(self.tr("PyQt4 to PySide"), - self.__pyqt2Pyside) - self.__editors[editor].append(act) + self.__menu.setEnabled(True) def __editorClosed(self, editor): """ @@ -160,28 +173,50 @@ """ try: del self.__editors[editor] + if not self.__editors: + self.__menu.setEnabled(False) except KeyError: pass def __pyside2Pyqt(self): """ Private slot to convert the code of the current editor from PySide - to PyQt4. + to PyQt. """ editor = e5App().getObject("ViewManager").activeWindow() if editor is None: return + act = self.sender() + if act is None: + return + text = editor.text() - newText = (text - .replace("PySide", "PyQt4") - .replace("Signal", "pyqtSignal") - .replace("Slot", "pyqtSlot") - .replace("Property", "pyqtProperty") - .replace("pyside-uic", "pyuic4") - .replace("pyside-rcc", "pyrcc4") - .replace("pyside-lupdate", "pylupdate4") - ) + pyqt = act.data() + if pyqt == "pyqt4": + newText = (text + .replace("PySide", "PyQt4") + .replace("Signal", "pyqtSignal") + .replace("Slot", "pyqtSlot") + .replace("Property", "pyqtProperty") + .replace("pyside-uic", "pyuic4") + .replace("pyside-rcc", "pyrcc4") + .replace("pyside-lupdate", "pylupdate4") + ) + elif pyqt == "pyqt5": + # Note: this code does no Qt4 to Qt5 conversion + newText = (text + .replace("PySide", "PyQt5") + .replace("Signal", "pyqtSignal") + .replace("Slot", "pyqtSlot") + .replace("Property", "pyqtProperty") + .replace("pyside-uic", "pyuic5") + .replace("pyside-rcc", "pyrcc5") + .replace("pyside-lupdate", "pylupdate5") + ) + else: + return + if newText != text: editor.beginUndoAction() editor.selectAll() @@ -190,23 +225,43 @@ def __pyqt2Pyside(self): """ - Private slot to convert the code of the current editor from PyQt4 + Private slot to convert the code of the current editor from PyQt to PySide. """ editor = e5App().getObject("ViewManager").activeWindow() if editor is None: return + act = self.sender() + if act is None: + return + text = editor.text() - newText = (text - .replace("PyQt4", "PySide") - .replace("pyqtSignal", "Signal") - .replace("pyqtSlot", "Slot") - .replace("pyqtProperty", "Property") - .replace("pyuic4", "pyside-uic") - .replace("pyrcc4", "pyside-rcc") - .replace("pylupdate4", "pyside-lupdate") - ) + pyqt = act.data() + if pyqt == "pyqt4": + newText = (text + .replace("PyQt4", "PySide") + .replace("pyqtSignal", "Signal") + .replace("pyqtSlot", "Slot") + .replace("pyqtProperty", "Property") + .replace("pyuic4", "pyside-uic") + .replace("pyrcc4", "pyside-rcc") + .replace("pylupdate4", "pyside-lupdate") + ) + elif pyqt == "pyqt5": + # Note: this code does no Qt4 to Qt5 conversion + newText = (text + .replace("PyQt5", "PySide") + .replace("pyqtSignal", "Signal") + .replace("pyqtSlot", "Slot") + .replace("pyqtProperty", "Property") + .replace("pyuic5", "pyside-uic") + .replace("pyrcc5", "pyside-rcc") + .replace("pylupdate5", "pyside-lupdate") + ) + else: + return + if newText != text: editor.beginUndoAction() editor.selectAll()
--- a/PySide2PyQt.e4p Sat Apr 26 15:53:30 2014 +0200 +++ b/PySide2PyQt.e4p Sat Jul 12 14:55:23 2014 +0200 @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE Project SYSTEM "Project-5.1.dtd"> -<!-- eric5 project file for project PySide2PyQt --> +<!-- eric6 project file for project PySide2PyQt --> +<!-- Copyright (C) 2014 Detlev Offenbach, detlev@die-offenbachs.de --> <Project version="5.1"> <Language>en_US</Language> <Hash>d994091d1e81ad5afcdcbc00ecea86f23163c696</Hash> @@ -35,6 +36,7 @@ <Other>PKGLIST</Other> <Other>PluginPySide2PyQt.zip</Other> <Other>PySide2PyQt/Documentation/LICENSE.GPL3</Other> + <Other>PySide2PyQt.e4p</Other> </Others> <MainScript>PluginPySide2PyQt.py</MainScript> <Vcs> @@ -167,7 +169,7 @@ <string>cssFile</string> </key> <value> - <string>%PYTHON%/eric5/CSSs/default.css</string> + <string>%PYTHON%/eric6/CSSs/default.css</string> </value> <key> <string>ignoreDirectories</string> @@ -179,6 +181,8 @@ <string>.ropeproject</string> <string>_eric5project</string> <string>_ropeproject</string> + <string>.eric6project</string> + <string>_eric6project</string> </list> </value> <key>
--- a/PySide2PyQt/Documentation/source/Plugin_Tools_PySide2PyQt.PluginPySide2PyQt.html Sat Apr 26 15:53:30 2014 +0200 +++ b/PySide2PyQt/Documentation/source/Plugin_Tools_PySide2PyQt.PluginPySide2PyQt.html Sat Jul 12 14:55:23 2014 +0200 @@ -21,7 +21,7 @@ <body><a NAME="top" ID="top"></a> <h1>Plugin_Tools_PySide2PyQt.PluginPySide2PyQt</h1> <p> -Module implementing the PySide to PyQt4 (and vice versa) plug-in. +Module implementing the PySide to PyQt (and vice versa) plug-in. </p> <h3>Global Attributes</h3> <table> @@ -31,7 +31,7 @@ <table> <tr> <td><a href="#PySide2PyQtPlugin">PySide2PyQtPlugin</a></td> -<td>Class implementing the PySide to PyQt4 (and vice versa) plugin.</td> +<td>Class implementing the PySide to PyQt (and vice versa) plugin.</td> </tr> </table> <h3>Functions</h3> @@ -42,7 +42,7 @@ <a NAME="PySide2PyQtPlugin" ID="PySide2PyQtPlugin"></a> <h2>PySide2PyQtPlugin</h2> <p> - Class implementing the PySide to PyQt4 (and vice versa) plugin. + Class implementing the PySide to PyQt (and vice versa) plugin. </p> <h3>Derived from</h3> QObject @@ -66,6 +66,9 @@ <td><a href="#PySide2PyQtPlugin.__editorOpened">__editorOpened</a></td> <td>Private slot called, when a new editor was opened.</td> </tr><tr> +<td><a href="#PySide2PyQtPlugin.__initMenu">__initMenu</a></td> +<td>Private method to initialize the menu.</td> +</tr><tr> <td><a href="#PySide2PyQtPlugin.__loadTranslator">__loadTranslator</a></td> <td>Private method to load the translation file.</td> </tr><tr> @@ -73,10 +76,10 @@ <td>Private slot to populate the tools menu with our entries.</td> </tr><tr> <td><a href="#PySide2PyQtPlugin.__pyqt2Pyside">__pyqt2Pyside</a></td> -<td>Private slot to convert the code of the current editor from PyQt4 to PySide.</td> +<td>Private slot to convert the code of the current editor from PyQt to PySide.</td> </tr><tr> <td><a href="#PySide2PyQtPlugin.__pyside2Pyqt">__pyside2Pyqt</a></td> -<td>Private slot to convert the code of the current editor from PySide to PyQt4.</td> +<td>Private slot to convert the code of the current editor from PySide to PyQt.</td> </tr><tr> <td><a href="#PySide2PyQtPlugin.activate">activate</a></td> <td>Public method to activate this plugin.</td> @@ -119,7 +122,12 @@ <dd> reference to the new editor (QScintilla.Editor) </dd> -</dl><a NAME="PySide2PyQtPlugin.__loadTranslator" ID="PySide2PyQtPlugin.__loadTranslator"></a> +</dl><a NAME="PySide2PyQtPlugin.__initMenu" ID="PySide2PyQtPlugin.__initMenu"></a> +<h4>PySide2PyQtPlugin.__initMenu</h4> +<b>__initMenu</b>(<i></i>) +<p> + Private method to initialize the menu. +</p><a NAME="PySide2PyQtPlugin.__loadTranslator" ID="PySide2PyQtPlugin.__loadTranslator"></a> <h4>PySide2PyQtPlugin.__loadTranslator</h4> <b>__loadTranslator</b>(<i></i>) <p> @@ -141,14 +149,14 @@ <h4>PySide2PyQtPlugin.__pyqt2Pyside</h4> <b>__pyqt2Pyside</b>(<i></i>) <p> - Private slot to convert the code of the current editor from PyQt4 + Private slot to convert the code of the current editor from PyQt to PySide. </p><a NAME="PySide2PyQtPlugin.__pyside2Pyqt" ID="PySide2PyQtPlugin.__pyside2Pyqt"></a> <h4>PySide2PyQtPlugin.__pyside2Pyqt</h4> <b>__pyside2Pyqt</b>(<i></i>) <p> Private slot to convert the code of the current editor from PySide - to PyQt4. + to PyQt. </p><a NAME="PySide2PyQtPlugin.activate" ID="PySide2PyQtPlugin.activate"></a> <h4>PySide2PyQtPlugin.activate</h4> <b>activate</b>(<i></i>)
--- a/PySide2PyQt/Documentation/source/index-Plugin_Tools_PySide2PyQt.PySide2PyQt.html Sat Apr 26 15:53:30 2014 +0200 +++ b/PySide2PyQt/Documentation/source/index-Plugin_Tools_PySide2PyQt.PySide2PyQt.html Sat Jul 12 14:55:23 2014 +0200 @@ -21,7 +21,7 @@ <body> <h1>Plugin_Tools_PySide2PyQt.PySide2PyQt</h1> <p> -Package implementing the PySide to PyQt4 (and vice versa) plug-in data. +Package implementing the PySide to PyQt (and vice versa) plug-in data. </p>
--- a/PySide2PyQt/Documentation/source/index-Plugin_Tools_PySide2PyQt.html Sat Apr 26 15:53:30 2014 +0200 +++ b/PySide2PyQt/Documentation/source/index-Plugin_Tools_PySide2PyQt.html Sat Jul 12 14:55:23 2014 +0200 @@ -21,14 +21,14 @@ <body> <h1>Plugin_Tools_PySide2PyQt</h1> <p> -Package implementing the PySide to PyQt4 (and vice versa) plug-in. +Package implementing the PySide to PyQt (and vice versa) plug-in. </p> <h3>Packages</h3> <table> <tr> <td><a href="index-Plugin_Tools_PySide2PyQt.PySide2PyQt.html">PySide2PyQt</a></td> -<td>Package implementing the PySide to PyQt4 (and vice versa) plug-in data.</td> +<td>Package implementing the PySide to PyQt (and vice versa) plug-in data.</td> </tr> </table> @@ -36,7 +36,7 @@ <table> <tr> <td><a href="Plugin_Tools_PySide2PyQt.PluginPySide2PyQt.html">PluginPySide2PyQt</a></td> -<td>Module implementing the PySide to PyQt4 (and vice versa) plug-in.</td> +<td>Module implementing the PySide to PyQt (and vice versa) plug-in.</td> </tr> </table> </body></html> \ No newline at end of file
--- a/PySide2PyQt/Documentation/source/index.html Sat Apr 26 15:53:30 2014 +0200 +++ b/PySide2PyQt/Documentation/source/index.html Sat Jul 12 14:55:23 2014 +0200 @@ -26,7 +26,7 @@ <table> <tr> <td><a href="index-Plugin_Tools_PySide2PyQt.html">Plugin_Tools_PySide2PyQt</a></td> -<td>Package implementing the PySide to PyQt4 (and vice versa) plug-in.</td> +<td>Package implementing the PySide to PyQt (and vice versa) plug-in.</td> </tr> </table>
--- a/PySide2PyQt/__init__.py Sat Apr 26 15:53:30 2014 +0200 +++ b/PySide2PyQt/__init__.py Sat Jul 12 14:55:23 2014 +0200 @@ -4,5 +4,5 @@ # """ -Package implementing the PySide to PyQt4 (and vice versa) plug-in data. +Package implementing the PySide to PyQt (and vice versa) plug-in data. """
--- a/PySide2PyQt/i18n/pyside2pyqt_de.ts Sat Apr 26 15:53:30 2014 +0200 +++ b/PySide2PyQt/i18n/pyside2pyqt_de.ts Sat Jul 12 14:55:23 2014 +0200 @@ -1,17 +1,31 @@ <?xml version="1.0" encoding="utf-8"?> -<!DOCTYPE TS> -<TS version="2.0" language="de_DE"> +<!DOCTYPE TS><TS version="2.0" language="de_DE" sourcelanguage=""> <context> <name>PySide2PyQtPlugin</name> <message> - <location filename="../../PluginPySide2PyQt.py" line="111"/> + <location filename="../../PluginPySide2PyQt.py" line="125"/> <source>PySide to PyQt4</source> <translation>PySide nach PyQt4</translation> </message> <message> - <location filename="../../PluginPySide2PyQt.py" line="112"/> + <location filename="../../PluginPySide2PyQt.py" line="129"/> <source>PyQt4 to PySide</source> <translation>PyQt4 nach PySide</translation> </message> + <message> + <location filename="../../PluginPySide2PyQt.py" line="124"/> + <source>PySide to/from PyQt</source> + <translation>PySide von/nach PyQt</translation> + </message> + <message> + <location filename="../../PluginPySide2PyQt.py" line="127"/> + <source>PySide to PyQt5</source> + <translation>PySide nach PyQt5</translation> + </message> + <message> + <location filename="../../PluginPySide2PyQt.py" line="131"/> + <source>PyQt5 to PySide</source> + <translation>PyQt5 nach PySide</translation> + </message> </context> </TS>
--- a/PySide2PyQt/i18n/pyside2pyqt_en.ts Sat Apr 26 15:53:30 2014 +0200 +++ b/PySide2PyQt/i18n/pyside2pyqt_en.ts Sat Jul 12 14:55:23 2014 +0200 @@ -1,17 +1,31 @@ <?xml version="1.0" encoding="utf-8"?> -<!DOCTYPE TS> -<TS version="2.0" language="en_US"> +<!DOCTYPE TS><TS version="2.0" language="en_US" sourcelanguage=""> <context> <name>PySide2PyQtPlugin</name> <message> - <location filename="../../PluginPySide2PyQt.py" line="111"/> + <location filename="../../PluginPySide2PyQt.py" line="125"/> <source>PySide to PyQt4</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../../PluginPySide2PyQt.py" line="112"/> + <location filename="../../PluginPySide2PyQt.py" line="129"/> <source>PyQt4 to PySide</source> <translation type="unfinished"></translation> </message> + <message> + <location filename="../../PluginPySide2PyQt.py" line="124"/> + <source>PySide to/from PyQt</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../../PluginPySide2PyQt.py" line="127"/> + <source>PySide to PyQt5</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../../PluginPySide2PyQt.py" line="131"/> + <source>PyQt5 to PySide</source> + <translation type="unfinished"></translation> + </message> </context> </TS>
--- a/PySide2PyQt/i18n/pyside2pyqt_es.ts Sat Apr 26 15:53:30 2014 +0200 +++ b/PySide2PyQt/i18n/pyside2pyqt_es.ts Sat Jul 12 14:55:23 2014 +0200 @@ -1,17 +1,31 @@ <?xml version="1.0" encoding="utf-8"?> -<!DOCTYPE TS> -<TS version="2.0" language="es_ES"> +<!DOCTYPE TS><TS version="2.0" language="es_ES" sourcelanguage=""> <context> <name>PySide2PyQtPlugin</name> <message> - <location filename="../../PluginPySide2PyQt.py" line="111"/> + <location filename="../../PluginPySide2PyQt.py" line="125"/> <source>PySide to PyQt4</source> <translation>PySide a PyQt4</translation> </message> <message> - <location filename="../../PluginPySide2PyQt.py" line="112"/> + <location filename="../../PluginPySide2PyQt.py" line="129"/> <source>PyQt4 to PySide</source> <translation>PyQt4 a PySide</translation> </message> + <message> + <location filename="../../PluginPySide2PyQt.py" line="124"/> + <source>PySide to/from PyQt</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../../PluginPySide2PyQt.py" line="127"/> + <source>PySide to PyQt5</source> + <translation type="unfinished">PySide a PyQt5</translation> + </message> + <message> + <location filename="../../PluginPySide2PyQt.py" line="131"/> + <source>PyQt5 to PySide</source> + <translation type="unfinished">PyQt4 a PySide {5 ?}</translation> + </message> </context> </TS>