eric7/Plugins/PluginWizardSetup.py

branch
eric7
changeset 9202
81388c6065e8
parent 9201
2f1ccadee231
equal deleted inserted replaced
9201:2f1ccadee231 9202:81388c6065e8
8 """ 8 """
9 9
10 import functools 10 import functools
11 11
12 from PyQt6.QtCore import QObject 12 from PyQt6.QtCore import QObject
13 from PyQt6.QtWidgets import QDialog
14 13
15 from EricWidgets.EricApplication import ericApp 14 from EricWidgets.EricApplication import ericApp
16 from EricGui.EricAction import EricAction 15 from EricGui.EricAction import EricAction
17 from EricWidgets import EricMessageBox 16 from EricWidgets import EricMessageBox
18 17
138 """ 137 """
139 menu = self.__ui.getMenu("wizards") 138 menu = self.__ui.getMenu("wizards")
140 if menu: 139 if menu:
141 menu.addActions(self.__actions) 140 menu.addActions(self.__actions)
142 141
143 def __callForm(self, editor, category):
144 """
145 Private method to display a dialog and get the code.
146
147 @param editor reference to the current editor
148 @type Editor
149 @param category category of setup file to create
150 @type str
151 @return tuple containing the generated code and a flag indicating an error
152 @rtype tuple of (str, bool)
153 """
154 from WizardPlugins.SetupWizard.SetupWizardDialog import (
155 SetupWizardDialog
156 )
157 dlg = SetupWizardDialog(category, self.__ui)
158 if dlg.exec() == QDialog.DialogCode.Accepted:
159 line, index = editor.getCursorPosition()
160 indLevel = editor.indentation(line) // editor.indentationWidth()
161 if editor.indentationsUseTabs():
162 indString = '\t'
163 else:
164 indString = editor.indentationWidth() * ' '
165 return (dlg.getCode(indLevel, indString), True)
166 else:
167 return ("", False)
168
169 def __handle(self, category): 142 def __handle(self, category):
170 """ 143 """
171 Private method to handle the wizards action. 144 Private method to handle the wizards action.
172 145
173 @param category category of setup file to create 146 @param category category of setup file to create
174 @type str 147 @type str
175 """ 148 """
149 from WizardPlugins.SetupWizard.SetupWizardDialog import (
150 SetupWizardDialog
151 )
152
176 editor = ericApp().getObject("ViewManager").activeWindow() 153 editor = ericApp().getObject("ViewManager").activeWindow()
177 154
178 if editor is None: 155 if editor is None:
179 EricMessageBox.critical( 156 EricMessageBox.critical(
180 self.__ui, 157 self.__ui,
181 self.tr('No current editor'), 158 self.tr('No current editor'),
182 self.tr('Please open or create a file first.')) 159 self.tr('Please open or create a file first.'))
183 else: 160 else:
184 sourceCode, ok = self.__callForm(editor, category) 161 dlg = SetupWizardDialog(category, editor, self.__ui)
185 if ok: 162 dlg.show()
186 line, index = editor.getCursorPosition()
187 # It should be done this way to allow undo
188 editor.beginUndoAction()
189 editor.insertAt(sourceCode, line, index)
190 editor.endUndoAction()
191 163
192 # 164 #
193 # eflag: noqa = M801 165 # eflag: noqa = M801

eric ide

mercurial