PluginPySide2PyQt.py

changeset 16
051e29b6bdd6
parent 13
ba4283ccf93c
child 18
ea533653d9b2
equal deleted inserted replaced
15:23324a7a0aa2 16:051e29b6bdd6
18 # Start-Of-Header 18 # Start-Of-Header
19 name = "PySide to PyQt4 (and vice versa) Plug-in" 19 name = "PySide to PyQt4 (and vice versa) Plug-in"
20 author = "Detlev Offenbach <detlev@die-offenbachs.de>" 20 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
21 autoactivate = True 21 autoactivate = True
22 deactivateable = True 22 deactivateable = True
23 version = "0.2.0" 23 version = "0.3.0"
24 className = "PySide2PyQtPlugin" 24 className = "PySide2PyQtPlugin"
25 packageName = "PySide2PyQt" 25 packageName = "PySide2PyQt"
26 shortDescription = "Convert PySide file to PyQt4 and vice versa" 26 shortDescription = "Convert PySide file to PyQt4 and vice versa"
27 longDescription = \ 27 longDescription = \
28 """This plug-in implements a tool to convert a PySide file""" \ 28 """This plug-in implements a tool to convert a PySide file""" \
48 QObject.__init__(self, ui) 48 QObject.__init__(self, ui)
49 self.__ui = ui 49 self.__ui = ui
50 50
51 self.__translator = None 51 self.__translator = None
52 self.__loadTranslator() 52 self.__loadTranslator()
53
54 self.__editors = {}
53 55
54 def activate(self): 56 def activate(self):
55 """ 57 """
56 Public method to activate this plugin. 58 Public method to activate this plugin.
57 59
60 global error 62 global error
61 error = "" # clear previous error 63 error = "" # clear previous error
62 64
63 self.__ui.showMenu.connect(self.__populateMenu) 65 self.__ui.showMenu.connect(self.__populateMenu)
64 66
67 e5App().getObject("ViewManager").editorOpenedEd.connect(
68 self.__editorOpened)
69 e5App().getObject("ViewManager").editorClosedEd.connect(
70 self.__editorClosed)
71
72 for editor in e5App().getObject("ViewManager").getOpenEditors():
73 self.__editorOpened(editor)
74
65 return None, True 75 return None, True
66 76
67 def deactivate(self): 77 def deactivate(self):
68 """ 78 """
69 Public method to deactivate this plugin. 79 Public method to deactivate this plugin.
70 """ 80 """
71 self.__ui.showMenu.disconnect(self.__populateMenu) 81 self.__ui.showMenu.disconnect(self.__populateMenu)
82
83 e5App().getObject("ViewManager").editorOpenedEd.disconnect(
84 self.__editorOpened)
85 e5App().getObject("ViewManager").editorClosedEd.disconnect(
86 self.__editorClosed)
87
88 for editor, acts in self.__editors.items():
89 menu = editor.getMenu("Tools")
90 if menu is not None:
91 for act in acts:
92 menu.removeAction(act)
93 self.__editors = {}
72 94
73 def __loadTranslator(self): 95 def __loadTranslator(self):
74 """ 96 """
75 Private method to load the translation file. 97 Private method to load the translation file.
76 """ 98 """
108 menu.addSeparator() 130 menu.addSeparator()
109 131
110 menu.addAction(self.tr("PySide to PyQt4"), self.__pyside2Pyqt) 132 menu.addAction(self.tr("PySide to PyQt4"), self.__pyside2Pyqt)
111 menu.addAction(self.tr("PyQt4 to PySide"), self.__pyqt2Pyside) 133 menu.addAction(self.tr("PyQt4 to PySide"), self.__pyqt2Pyside)
112 134
135 def __editorOpened(self, editor):
136 """
137 Private slot called, when a new editor was opened.
138
139 @param editor reference to the new editor (QScintilla.Editor)
140 """
141 menu = editor.getMenu("Tools")
142 if menu is not None:
143 self.__editors[editor] = []
144 if not menu.isEmpty():
145 act = menu.addSeparator()
146 self.__editors[editor].append(act)
147 act = menu.addAction(self.tr("PySide to PyQt4"),
148 self.__pyside2Pyqt)
149 self.__editors[editor].append(act)
150 act = menu.addAction(self.tr("PyQt4 to PySide"),
151 self.__pyqt2Pyside)
152 self.__editors[editor].append(act)
153
154 def __editorClosed(self, editor):
155 """
156 Private slot called, when an editor was closed.
157
158 @param editor reference to the editor (QScintilla.Editor)
159 """
160 try:
161 del self.__editors[editor]
162 except KeyError:
163 pass
164
113 def __pyside2Pyqt(self): 165 def __pyside2Pyqt(self):
114 """ 166 """
115 Private slot to convert the code of the current editor from PySide 167 Private slot to convert the code of the current editor from PySide
116 to PyQt4. 168 to PyQt4.
117 """ 169 """

eric ide

mercurial