PySide to PyQt4 converter project started.

Wed, 18 Dec 2013 15:48:49 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 18 Dec 2013 15:48:49 +0100
changeset 0
4e3bb54c22d7
child 1
299876e9654d

PySide to PyQt4 converter project started.

.hgignore file | annotate | diff | comparison | revisions
PluginPySide2PyQt.py file | annotate | diff | comparison | revisions
PySide2PyQt.e4p file | annotate | diff | comparison | revisions
PySide2PyQt/__init__.py file | annotate | diff | comparison | revisions
__init__.py file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Wed Dec 18 15:48:49 2013 +0100
@@ -0,0 +1,17 @@
+glob:.eric5project
+glob:_eric5project
+glob:.eric4project
+glob:_eric4project
+glob:.ropeproject
+glob:_ropeproject
+glob:.directory
+glob:**.pyc
+glob:**.pyo
+glob:**.orig
+glob:**.bak
+glob:**.rej
+glob:**~
+glob:cur
+glob:tmp
+glob:__pycache__
+glob:**.DS_Store
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PluginPySide2PyQt.py	Wed Dec 18 15:48:49 2013 +0100
@@ -0,0 +1,161 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2013 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing the PySide to PyQt4 (and vice versa) plug-in.
+"""
+
+from __future__ import unicode_literals    # __IGNORE_WARNING__
+
+import os
+
+from PyQt4.QtCore import QObject, QTranslator
+
+from E5Gui.E5Application import e5App
+
+# Start-Of-Header
+name = "PySide to PyQt4 (and vice versa) Plug-in"
+author = "Detlev Offenbach <detlev@die-offenbachs.de>"
+autoactivate = True
+deactivateable = True
+version = "0.1.0"
+className = "PySide2PyQtPlugin"
+packageName = "PySide2PyQt"
+shortDescription = "Remove print() like debug statements."
+longDescription = \
+    """This plug-in implements a tool to convert a PySide file""" \
+    """ to PyQt4 and vice versa. It works with the text of the""" \
+    """ current editor."""
+needsRestart = False
+pyqtApi = 2
+# End-Of-Header
+
+error = ""
+
+
+class PySide2PyQtPlugin(QObject):
+    """
+    Class implementing the PySide to PyQt4 (and vice versa) plugin.
+    """
+    def __init__(self, ui):
+        """
+        Constructor
+        
+        @param ui reference to the user interface object (UI.UserInterface)
+        """
+        QObject.__init__(self, ui)
+        self.__ui = ui
+        
+        self.__translator = None
+        self.__loadTranslator()
+    
+    def activate(self):
+        """
+        Public method to activate this plugin.
+        
+        @return tuple of None and activation status (boolean)
+        """
+        global error
+        error = ""     # clear previous error
+        
+        self.__ui.showMenu.connect(self.__populateMenu)
+        
+        return None, True
+    
+    def deactivate(self):
+        """
+        Public method to deactivate this plugin.
+        """
+        self.__ui.showMenu.disconnect(self.__populateMenu)
+    
+    def __loadTranslator(self):
+        """
+        Private method to load the translation file.
+        """
+        if self.__ui is not None:
+            loc = self.__ui.getLocale()
+            if loc and loc != "C":
+                locale_dir = os.path.join(
+                    os.path.dirname(__file__), "PySide2PyQt", "i18n")
+                translation = "pyside2pyqt_{0}".format(loc)
+                translator = QTranslator(None)
+                loaded = translator.load(translation, locale_dir)
+                if loaded:
+                    self.__translator = translator
+                    e5App().installTranslator(self.__translator)
+                else:
+                    print("Warning: translation file '{0}' could not be"
+                          " loaded.".format(translation))
+                    print("Using default.")
+    
+    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)
+        """
+        if name != "Tools":
+            return
+        
+        editor = e5App().getObject("ViewManager").activeWindow()
+        if editor is None:
+            return
+        
+        if not menu.isEmpty():
+            menu.addSeparator()
+        
+        menu.addAction(self.tr("PySide to PyQt4"), self.__pyside2Pyqt)
+        menu.addAction(self.tr("PyQt4 to PySide"), self.__pyqt2Pyside)
+    
+    def __pyside2Pyqt(self):
+        """
+        Private slot to convert the code of the current editor from PySide
+        to PyQt4.
+        """
+        editor = e5App().getObject("ViewManager").activeWindow()
+        if editor 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")
+                   )
+        if newText != text:
+            editor.beginUndoAction()
+            editor.selectAll()
+            editor.replaceSelectedText(newText)
+            editor.endUndoAction()
+    
+    def __pyqt2Pyside(self):
+        """
+        Private slot to convert the code of the current editor from PyQt4
+        to PySide.
+        """
+        editor = e5App().getObject("ViewManager").activeWindow()
+        if editor 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")
+                   )
+        if newText != text:
+            editor.beginUndoAction()
+            editor.selectAll()
+            editor.replaceSelectedText(newText)
+            editor.endUndoAction()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PySide2PyQt.e4p	Wed Dec 18 15:48:49 2013 +0100
@@ -0,0 +1,219 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE Project SYSTEM "Project-5.1.dtd">
+<!-- eric5 project file for project PySide2PyQt -->
+<Project version="5.1">
+  <Language>en_US</Language>
+  <Hash>d994091d1e81ad5afcdcbc00ecea86f23163c696</Hash>
+  <ProgLanguage mixed="0">Python3</ProgLanguage>
+  <ProjectType>E4Plugin</ProjectType>
+  <Description>Plug-in to convert PySide filePyQt4 and vice versa. It works with the current editor.</Description>
+  <Version>0.x</Version>
+  <Author>Detlev Offenbach</Author>
+  <Email>detlev@die-offenbachs.de</Email>
+  <TranslationPattern>PySide2PyQt/i18n/pyside2pyqt_%language%.ts</TranslationPattern>
+  <Eol index="1"/>
+  <Sources>
+    <Source>__init__.py</Source>
+    <Source>PluginPySide2PyQt.py</Source>
+    <Source>PySide2PyQt/__init__.py</Source>
+  </Sources>
+  <Forms/>
+  <Translations/>
+  <Resources/>
+  <Interfaces/>
+  <Others>
+    <Other>.hgignore</Other>
+  </Others>
+  <MainScript>PluginPySide2PyQt.py</MainScript>
+  <Vcs>
+    <VcsType>Mercurial</VcsType>
+    <VcsOptions>
+      <dict>
+        <key>
+          <string>add</string>
+        </key>
+        <value>
+          <list>
+            <string></string>
+          </list>
+        </value>
+        <key>
+          <string>checkout</string>
+        </key>
+        <value>
+          <list>
+            <string></string>
+          </list>
+        </value>
+        <key>
+          <string>commit</string>
+        </key>
+        <value>
+          <list>
+            <string></string>
+          </list>
+        </value>
+        <key>
+          <string>diff</string>
+        </key>
+        <value>
+          <list>
+            <string></string>
+          </list>
+        </value>
+        <key>
+          <string>export</string>
+        </key>
+        <value>
+          <list>
+            <string></string>
+          </list>
+        </value>
+        <key>
+          <string>global</string>
+        </key>
+        <value>
+          <list>
+            <string></string>
+          </list>
+        </value>
+        <key>
+          <string>history</string>
+        </key>
+        <value>
+          <list>
+            <string></string>
+          </list>
+        </value>
+        <key>
+          <string>log</string>
+        </key>
+        <value>
+          <list>
+            <string></string>
+          </list>
+        </value>
+        <key>
+          <string>remove</string>
+        </key>
+        <value>
+          <list>
+            <string></string>
+          </list>
+        </value>
+        <key>
+          <string>status</string>
+        </key>
+        <value>
+          <list>
+            <string></string>
+          </list>
+        </value>
+        <key>
+          <string>tag</string>
+        </key>
+        <value>
+          <list>
+            <string></string>
+          </list>
+        </value>
+        <key>
+          <string>update</string>
+        </key>
+        <value>
+          <list>
+            <string></string>
+          </list>
+        </value>
+      </dict>
+    </VcsOptions>
+    <VcsOtherData>
+      <dict/>
+    </VcsOtherData>
+  </Vcs>
+  <FiletypeAssociations>
+    <FiletypeAssociation pattern="*.idl" type="INTERFACES"/>
+    <FiletypeAssociation pattern="*.py" type="SOURCES"/>
+    <FiletypeAssociation pattern="*.py3" type="SOURCES"/>
+    <FiletypeAssociation pattern="*.pyw" type="SOURCES"/>
+    <FiletypeAssociation pattern="*.pyw3" type="SOURCES"/>
+    <FiletypeAssociation pattern="*.qm" type="TRANSLATIONS"/>
+    <FiletypeAssociation pattern="*.qrc" type="RESOURCES"/>
+    <FiletypeAssociation pattern="*.ts" type="TRANSLATIONS"/>
+    <FiletypeAssociation pattern="*.ui" type="FORMS"/>
+    <FiletypeAssociation pattern="*.ui.h" type="FORMS"/>
+  </FiletypeAssociations>
+  <Checkers>
+    <CheckersParams>
+      <dict>
+        <key>
+          <string>Pep8Checker</string>
+        </key>
+        <value>
+          <dict>
+            <key>
+              <string>DocstringType</string>
+            </key>
+            <value>
+              <string>eric</string>
+            </value>
+            <key>
+              <string>ExcludeFiles</string>
+            </key>
+            <value>
+              <string></string>
+            </value>
+            <key>
+              <string>ExcludeMessages</string>
+            </key>
+            <value>
+              <string>E24, W293, N802, N803, N807, N808, N821</string>
+            </value>
+            <key>
+              <string>FixCodes</string>
+            </key>
+            <value>
+              <string></string>
+            </value>
+            <key>
+              <string>FixIssues</string>
+            </key>
+            <value>
+              <bool>False</bool>
+            </value>
+            <key>
+              <string>HangClosing</string>
+            </key>
+            <value>
+              <bool>False</bool>
+            </value>
+            <key>
+              <string>IncludeMessages</string>
+            </key>
+            <value>
+              <string></string>
+            </value>
+            <key>
+              <string>MaxLineLength</string>
+            </key>
+            <value>
+              <int>79</int>
+            </value>
+            <key>
+              <string>NoFixCodes</string>
+            </key>
+            <value>
+              <string>E501</string>
+            </value>
+            <key>
+              <string>RepeatMessages</string>
+            </key>
+            <value>
+              <bool>True</bool>
+            </value>
+          </dict>
+        </value>
+      </dict>
+    </CheckersParams>
+  </Checkers>
+</Project>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PySide2PyQt/__init__.py	Wed Dec 18 15:48:49 2013 +0100
@@ -0,0 +1,9 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2013 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Package implementing the PySide to PyQt4 (and vice versa) plug-in
+functionality and data.
+"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/__init__.py	Wed Dec 18 15:48:49 2013 +0100
@@ -0,0 +1,9 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2013 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+
+"""
+Package implementing the PySide to PyQt4 (and vice versa) plug-in.
+"""

eric ide

mercurial