eric7/Plugins/PluginWizardEricPlugin.py

branch
eric7
changeset 8356
68ec9c3d4de5
parent 8318
962bce857696
child 8358
144a6b854f70
equal deleted inserted replaced
8355:8a7677a63c8d 8356:68ec9c3d4de5
10 import os 10 import os
11 11
12 from PyQt6.QtCore import QObject 12 from PyQt6.QtCore import QObject
13 from PyQt6.QtWidgets import QDialog 13 from PyQt6.QtWidgets import QDialog
14 14
15 from E5Gui.E5Application import e5App 15 from E5Gui.EricApplication import ericApp
16 from E5Gui.E5Action import E5Action 16 from E5Gui.EricAction import EricAction
17 from E5Gui import E5MessageBox 17 from E5Gui import EricMessageBox
18 18
19 import UI.Info 19 import UI.Info
20 20
21 # Start-of-Header 21 # Start-of-Header
22 name = "eric plug-in Wizard Plug-in" 22 name = "eric plug-in Wizard Plug-in"
74 Public method to deactivate this plug-in. 74 Public method to deactivate this plug-in.
75 """ 75 """
76 menu = self.__ui.getMenu("wizards") 76 menu = self.__ui.getMenu("wizards")
77 if menu: 77 if menu:
78 menu.removeAction(self.__action) 78 menu.removeAction(self.__action)
79 self.__ui.removeE5Actions([self.__action], 'wizards') 79 self.__ui.removeEricActions([self.__action], 'wizards')
80 80
81 def __initAction(self): 81 def __initAction(self):
82 """ 82 """
83 Private method to initialize the action. 83 Private method to initialize the action.
84 """ 84 """
85 self.__action = E5Action( 85 self.__action = EricAction(
86 self.tr('eric Plug-in Wizard'), 86 self.tr('eric Plug-in Wizard'),
87 self.tr('&eric Plug-in Wizard...'), 87 self.tr('&eric Plug-in Wizard...'),
88 0, 0, self, 88 0, 0, self,
89 'wizards_eric_plugin') 89 'wizards_eric_plugin')
90 self.__action.setStatusTip(self.tr('eric Plug-in Wizard')) 90 self.__action.setStatusTip(self.tr('eric Plug-in Wizard'))
95 """ The generated code is inserted at the current cursor""" 95 """ The generated code is inserted at the current cursor"""
96 """ position.</p>""" 96 """ position.</p>"""
97 )) 97 ))
98 self.__action.triggered.connect(self.__handle) 98 self.__action.triggered.connect(self.__handle)
99 99
100 self.__ui.addE5Actions([self.__action], 'wizards') 100 self.__ui.addEricActions([self.__action], 'wizards')
101 101
102 def __initMenu(self): 102 def __initMenu(self):
103 """ 103 """
104 Private method to add the actions to the right menu. 104 Private method to add the actions to the right menu.
105 """ 105 """
126 126
127 def __handle(self): 127 def __handle(self):
128 """ 128 """
129 Private method to handle the wizards action. 129 Private method to handle the wizards action.
130 """ 130 """
131 editor = e5App().getObject("ViewManager").activeWindow() 131 editor = ericApp().getObject("ViewManager").activeWindow()
132 132
133 if editor is None: 133 if editor is None:
134 E5MessageBox.critical( 134 EricMessageBox.critical(
135 self.__ui, 135 self.__ui,
136 self.tr('No current editor'), 136 self.tr('No current editor'),
137 self.tr('Please open or create a file first.')) 137 self.tr('Please open or create a file first.'))
138 else: 138 else:
139 code, packageName, ok = self.__callForm(editor) 139 code, packageName, ok = self.__callForm(editor)
145 editor.endUndoAction() 145 editor.endUndoAction()
146 if not editor.getFileName(): 146 if not editor.getFileName():
147 editor.setLanguage("dummy.py") 147 editor.setLanguage("dummy.py")
148 148
149 if packageName: 149 if packageName:
150 project = e5App().getObject("Project") 150 project = ericApp().getObject("Project")
151 packagePath = os.path.join(project.getProjectPath(), 151 packagePath = os.path.join(project.getProjectPath(),
152 packageName) 152 packageName)
153 if not os.path.exists(packagePath): 153 if not os.path.exists(packagePath):
154 try: 154 try:
155 os.mkdir(packagePath) 155 os.mkdir(packagePath)
156 except OSError as err: 156 except OSError as err:
157 E5MessageBox.critical( 157 EricMessageBox.critical(
158 self, 158 self,
159 self.tr("Create Package"), 159 self.tr("Create Package"),
160 self.tr( 160 self.tr(
161 """<p>The package directory <b>{0}</b>""" 161 """<p>The package directory <b>{0}</b>"""
162 """ could not be created. Aborting...""" 162 """ could not be created. Aborting..."""
167 if not os.path.exists(packageFile): 167 if not os.path.exists(packageFile):
168 try: 168 try:
169 with open(packageFile, "w", encoding="utf-8"): 169 with open(packageFile, "w", encoding="utf-8"):
170 pass 170 pass
171 except OSError as err: 171 except OSError as err:
172 E5MessageBox.critical( 172 EricMessageBox.critical(
173 self, 173 self,
174 self.tr("Create Package"), 174 self.tr("Create Package"),
175 self.tr( 175 self.tr(
176 """<p>The package file <b>{0}</b> could""" 176 """<p>The package file <b>{0}</b> could"""
177 """ not be created. Aborting...</p>""" 177 """ not be created. Aborting...</p>"""
178 """<p>Reason: {1}</p>""") 178 """<p>Reason: {1}</p>""")
179 .format(packageFile, str(err))) 179 .format(packageFile, str(err)))
180 return 180 return
181 project.appendFile(packageFile) 181 project.appendFile(packageFile)
182 project.saveProject() 182 project.saveProject()
183 e5App().getObject("ViewManager").openSourceFile( 183 ericApp().getObject("ViewManager").openSourceFile(
184 packageFile) 184 packageFile)
185 185
186 # 186 #
187 # eflag: noqa = M801 187 # eflag: noqa = M801

eric ide

mercurial