PluginPySide2PyQt.py

changeset 53
52bc3465c1bc
parent 52
c88593752c63
child 55
f9706d6a2ece
equal deleted inserted replaced
52:c88593752c63 53:52bc3465c1bc
5 5
6 """ 6 """
7 Module implementing the PySide to PyQt (and vice versa) plug-in. 7 Module implementing the PySide to PyQt (and vice versa) plug-in.
8 """ 8 """
9 9
10 import contextlib
10 import os 11 import os
11 12
12 from PyQt5.QtCore import QObject, QTranslator 13 from PyQt5.QtCore import QObject, QTranslator
13 from PyQt5.QtWidgets import QMenu 14 from PyQt5.QtWidgets import QMenu
14 15
17 # Start-Of-Header 18 # Start-Of-Header
18 name = "PySide to PyQt (and vice versa) Plug-in" 19 name = "PySide to PyQt (and vice versa) Plug-in"
19 author = "Detlev Offenbach <detlev@die-offenbachs.de>" 20 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
20 autoactivate = True 21 autoactivate = True
21 deactivateable = True 22 deactivateable = True
22 version = "3.0.0" 23 version = "3.1.0"
23 className = "PySide2PyQtPlugin" 24 className = "PySide2PyQtPlugin"
24 packageName = "PySide2PyQt" 25 packageName = "PySide2PyQt"
25 shortDescription = "Convert PySide file to PyQt and vice versa" 26 shortDescription = "Convert PySide file to PyQt and vice versa"
26 longDescription = ( 27 longDescription = (
27 """This plug-in implements a tool to convert a PySide2 file to PyQt5""" 28 """This plug-in implements a tool to convert a PySide2 file to PyQt5"""
42 """ 43 """
43 Constructor 44 Constructor
44 45
45 @param ui reference to the user interface object (UI.UserInterface) 46 @param ui reference to the user interface object (UI.UserInterface)
46 """ 47 """
47 QObject.__init__(self, ui) 48 super.__init__(ui)
48 self.__ui = ui 49 self.__ui = ui
49 50
50 self.__translator = None 51 self.__translator = None
51 self.__loadTranslator() 52 self.__loadTranslator()
52 53
182 """ 183 """
183 Private slot called, when an editor was closed. 184 Private slot called, when an editor was closed.
184 185
185 @param editor reference to the editor (QScintilla.Editor) 186 @param editor reference to the editor (QScintilla.Editor)
186 """ 187 """
187 try: 188 with contextlib.suppress(KeyError):
188 del self.__editors[editor] 189 del self.__editors[editor]
189 if not self.__editors: 190 if not self.__editors:
190 self.__menu.setEnabled(False) 191 self.__menu.setEnabled(False)
191 except KeyError:
192 pass
193 192
194 def __editorShowMenu(self, menuName, menu, editor): 193 def __editorShowMenu(self, menuName, menu, editor):
195 """ 194 """
196 Private slot called, when the the editor context menu or a submenu is 195 Private slot called, when the the editor context menu or a submenu is
197 about to be shown. 196 about to be shown.
198 197
199 @param menuName name of the menu to be shown (string) 198 @param menuName name of the menu to be shown (string)
200 @param menu reference to the menu (QMenu) 199 @param menu reference to the menu (QMenu)
201 @param editor reference to the editor 200 @param editor reference to the editor
202 """ 201 """
203 if menuName == "Tools": 202 if (
204 if self.__menu.menuAction() not in menu.actions(): 203 menuName == "Tools" and
205 # Re-add our menu 204 self.__menu.menuAction() not in menu.actions()
206 self.__editors[editor] = [] 205 ):
207 if not menu.isEmpty(): 206 # Re-add our menu
208 act = menu.addSeparator() 207 self.__editors[editor] = []
209 self.__editors[editor].append(act) 208 if not menu.isEmpty():
210 act = menu.addMenu(self.__menu) 209 act = menu.addSeparator()
211 self.__editors[editor].append(act) 210 self.__editors[editor].append(act)
211 act = menu.addMenu(self.__menu)
212 self.__editors[editor].append(act)
212 213
213 def __pyside2Pyqt(self, pyside, pyqt): 214 def __pyside2Pyqt(self, pyside, pyqt):
214 """ 215 """
215 Private slot to convert the code of the current editor from PySide 216 Private slot to convert the code of the current editor from PySide
216 to PyQt. 217 to PyQt.

eric ide

mercurial