Added support for the editor Tools context menu (as of eric5 5.4.0). release-0.3.0

Mon, 23 Dec 2013 20:01:09 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 23 Dec 2013 20:01:09 +0100
changeset 16
051e29b6bdd6
parent 15
23324a7a0aa2
child 17
8a22f4199481

Added support for the editor Tools context menu (as of eric5 5.4.0).

ChangeLog file | annotate | diff | comparison | revisions
PluginPySide2PyQt.py file | annotate | diff | comparison | revisions
PluginPySide2PyQt.zip file | annotate | diff | comparison | revisions
PySide2PyQt/Documentation/source/Plugin_Tools_PySide2PyQt.PluginPySide2PyQt.html file | annotate | diff | comparison | revisions
--- a/ChangeLog	Sat Dec 21 15:08:17 2013 +0100
+++ b/ChangeLog	Mon Dec 23 20:01:09 2013 +0100
@@ -1,5 +1,8 @@
 ChangeLog
 ---------
+Version 0.3.0:
+- added support for the editor Tools context menu (as of eric5 5.4.0)
+
 Version 0.2.0:
 - added Spanish translations provided by Jaime Seuma
 
--- a/PluginPySide2PyQt.py	Sat Dec 21 15:08:17 2013 +0100
+++ b/PluginPySide2PyQt.py	Mon Dec 23 20:01:09 2013 +0100
@@ -20,7 +20,7 @@
 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
 autoactivate = True
 deactivateable = True
-version = "0.2.0"
+version = "0.3.0"
 className = "PySide2PyQtPlugin"
 packageName = "PySide2PyQt"
 shortDescription = "Convert PySide file to PyQt4 and vice versa"
@@ -50,6 +50,8 @@
         
         self.__translator = None
         self.__loadTranslator()
+        
+        self.__editors = {}
     
     def activate(self):
         """
@@ -62,6 +64,14 @@
         
         self.__ui.showMenu.connect(self.__populateMenu)
         
+        e5App().getObject("ViewManager").editorOpenedEd.connect(
+            self.__editorOpened)
+        e5App().getObject("ViewManager").editorClosedEd.connect(
+            self.__editorClosed)
+        
+        for editor in e5App().getObject("ViewManager").getOpenEditors():
+            self.__editorOpened(editor)
+        
         return None, True
     
     def deactivate(self):
@@ -69,6 +79,18 @@
         Public method to deactivate this plugin.
         """
         self.__ui.showMenu.disconnect(self.__populateMenu)
+        
+        e5App().getObject("ViewManager").editorOpenedEd.disconnect(
+            self.__editorOpened)
+        e5App().getObject("ViewManager").editorClosedEd.disconnect(
+            self.__editorClosed)
+        
+        for editor, acts in self.__editors.items():
+            menu = editor.getMenu("Tools")
+            if menu is not None:
+                for act in acts:
+                    menu.removeAction(act)
+        self.__editors = {}
     
     def __loadTranslator(self):
         """
@@ -110,6 +132,36 @@
         menu.addAction(self.tr("PySide to PyQt4"), self.__pyside2Pyqt)
         menu.addAction(self.tr("PyQt4 to PySide"), self.__pyqt2Pyside)
     
+    def __editorOpened(self, editor):
+        """
+        Private slot called, when a new editor was opened.
+        
+        @param editor reference to the new editor (QScintilla.Editor)
+        """
+        menu = editor.getMenu("Tools")
+        if menu is not None:
+            self.__editors[editor] = []
+            if not menu.isEmpty():
+                act = menu.addSeparator()
+                self.__editors[editor].append(act)
+            act = menu.addAction(self.tr("PySide to PyQt4"),
+                                 self.__pyside2Pyqt)
+            self.__editors[editor].append(act)
+            act = menu.addAction(self.tr("PyQt4 to PySide"),
+                                 self.__pyqt2Pyside)
+            self.__editors[editor].append(act)
+    
+    def __editorClosed(self, editor):
+        """
+        Private slot called, when an editor was closed.
+        
+        @param editor reference to the editor (QScintilla.Editor)
+        """
+        try:
+            del self.__editors[editor]
+        except KeyError:
+            pass
+    
     def __pyside2Pyqt(self):
         """
         Private slot to convert the code of the current editor from PySide
Binary file PluginPySide2PyQt.zip has changed
--- a/PySide2PyQt/Documentation/source/Plugin_Tools_PySide2PyQt.PluginPySide2PyQt.html	Sat Dec 21 15:08:17 2013 +0100
+++ b/PySide2PyQt/Documentation/source/Plugin_Tools_PySide2PyQt.PluginPySide2PyQt.html	Mon Dec 23 20:01:09 2013 +0100
@@ -60,6 +60,12 @@
 <td><a href="#PySide2PyQtPlugin.__init__">PySide2PyQtPlugin</a></td>
 <td>Constructor</td>
 </tr><tr>
+<td><a href="#PySide2PyQtPlugin.__editorClosed">__editorClosed</a></td>
+<td>Private slot called, when an editor was closed.</td>
+</tr><tr>
+<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.__loadTranslator">__loadTranslator</a></td>
 <td>Private method to load the translation file.</td>
 </tr><tr>
@@ -93,6 +99,26 @@
 <dd>
 reference to the user interface object (UI.UserInterface)
 </dd>
+</dl><a NAME="PySide2PyQtPlugin.__editorClosed" ID="PySide2PyQtPlugin.__editorClosed"></a>
+<h4>PySide2PyQtPlugin.__editorClosed</h4>
+<b>__editorClosed</b>(<i>editor</i>)
+<p>
+        Private slot called, when an editor was closed.
+</p><dl>
+<dt><i>editor</i></dt>
+<dd>
+reference to the editor (QScintilla.Editor)
+</dd>
+</dl><a NAME="PySide2PyQtPlugin.__editorOpened" ID="PySide2PyQtPlugin.__editorOpened"></a>
+<h4>PySide2PyQtPlugin.__editorOpened</h4>
+<b>__editorOpened</b>(<i>editor</i>)
+<p>
+        Private slot called, when a new editor was opened.
+</p><dl>
+<dt><i>editor</i></dt>
+<dd>
+reference to the new editor (QScintilla.Editor)
+</dd>
 </dl><a NAME="PySide2PyQtPlugin.__loadTranslator" ID="PySide2PyQtPlugin.__loadTranslator"></a>
 <h4>PySide2PyQtPlugin.__loadTranslator</h4>
 <b>__loadTranslator</b>(<i></i>)

eric ide

mercurial