34 |
34 |
35 class EricMessageBoxWizard(QObject): |
35 class EricMessageBoxWizard(QObject): |
36 """ |
36 """ |
37 Class implementing the EricMessageBox wizard plugin. |
37 Class implementing the EricMessageBox wizard plugin. |
38 """ |
38 """ |
|
39 |
39 def __init__(self, ui): |
40 def __init__(self, ui): |
40 """ |
41 """ |
41 Constructor |
42 Constructor |
42 |
43 |
43 @param ui reference to the user interface object (UI.UserInterface) |
44 @param ui reference to the user interface object (UI.UserInterface) |
44 """ |
45 """ |
45 super().__init__(ui) |
46 super().__init__(ui) |
46 self.__ui = ui |
47 self.__ui = ui |
47 |
48 |
48 def activate(self): |
49 def activate(self): |
49 """ |
50 """ |
50 Public method to activate this plugin. |
51 Public method to activate this plugin. |
51 |
52 |
52 @return tuple of None and activation status (boolean) |
53 @return tuple of None and activation status (boolean) |
53 """ |
54 """ |
54 self.__initAction() |
55 self.__initAction() |
55 self.__initMenu() |
56 self.__initMenu() |
56 |
57 |
57 return None, True |
58 return None, True |
58 |
59 |
59 def deactivate(self): |
60 def deactivate(self): |
60 """ |
61 """ |
61 Public method to deactivate this plugin. |
62 Public method to deactivate this plugin. |
62 """ |
63 """ |
63 menu = self.__ui.getMenu("wizards") |
64 menu = self.__ui.getMenu("wizards") |
64 if menu: |
65 if menu: |
65 menu.removeAction(self.action) |
66 menu.removeAction(self.action) |
66 self.__ui.removeEricActions([self.action], 'wizards') |
67 self.__ui.removeEricActions([self.action], "wizards") |
67 |
68 |
68 def __initAction(self): |
69 def __initAction(self): |
69 """ |
70 """ |
70 Private method to initialize the action. |
71 Private method to initialize the action. |
71 """ |
72 """ |
72 self.action = EricAction( |
73 self.action = EricAction( |
73 self.tr('EricMessageBox Wizard'), |
74 self.tr("EricMessageBox Wizard"), |
74 self.tr('EricMessageBox Wizard...'), 0, 0, self, |
75 self.tr("EricMessageBox Wizard..."), |
75 'wizards_e5messagebox') |
76 0, |
76 self.action.setStatusTip(self.tr('EricMessageBox Wizard')) |
77 0, |
77 self.action.setWhatsThis(self.tr( |
78 self, |
78 """<b>EricMessageBox Wizard</b>""" |
79 "wizards_e5messagebox", |
79 """<p>This wizard opens a dialog for entering all the parameters""" |
80 ) |
80 """ needed to create an EricMessageBox. The generated code is""" |
81 self.action.setStatusTip(self.tr("EricMessageBox Wizard")) |
81 """ inserted at the current cursor position.</p>""" |
82 self.action.setWhatsThis( |
82 )) |
83 self.tr( |
|
84 """<b>EricMessageBox Wizard</b>""" |
|
85 """<p>This wizard opens a dialog for entering all the parameters""" |
|
86 """ needed to create an EricMessageBox. The generated code is""" |
|
87 """ inserted at the current cursor position.</p>""" |
|
88 ) |
|
89 ) |
83 self.action.triggered.connect(self.__handle) |
90 self.action.triggered.connect(self.__handle) |
84 |
91 |
85 self.__ui.addEricActions([self.action], 'wizards') |
92 self.__ui.addEricActions([self.action], "wizards") |
86 |
93 |
87 def __initMenu(self): |
94 def __initMenu(self): |
88 """ |
95 """ |
89 Private method to add the actions to the right menu. |
96 Private method to add the actions to the right menu. |
90 """ |
97 """ |
91 menu = self.__ui.getMenu("wizards") |
98 menu = self.__ui.getMenu("wizards") |
92 if menu: |
99 if menu: |
93 menu.addAction(self.action) |
100 menu.addAction(self.action) |
94 |
101 |
95 def __callForm(self, editor): |
102 def __callForm(self, editor): |
96 """ |
103 """ |
97 Private method to display a dialog and get the code. |
104 Private method to display a dialog and get the code. |
98 |
105 |
99 @param editor reference to the current editor |
106 @param editor reference to the current editor |
100 @return the generated code (string) |
107 @return the generated code (string) |
101 """ |
108 """ |
102 from WizardPlugins.EricMessageBoxWizard.EricMessageBoxWizardDialog \ |
109 from WizardPlugins.EricMessageBoxWizard.EricMessageBoxWizardDialog import ( |
103 import EricMessageBoxWizardDialog |
110 EricMessageBoxWizardDialog, |
|
111 ) |
|
112 |
104 dlg = EricMessageBoxWizardDialog(None) |
113 dlg = EricMessageBoxWizardDialog(None) |
105 if dlg.exec() == QDialog.DialogCode.Accepted: |
114 if dlg.exec() == QDialog.DialogCode.Accepted: |
106 line, index = editor.getCursorPosition() |
115 line, index = editor.getCursorPosition() |
107 indLevel = editor.indentation(line) // editor.indentationWidth() |
116 indLevel = editor.indentation(line) // editor.indentationWidth() |
108 if editor.indentationsUseTabs(): |
117 if editor.indentationsUseTabs(): |
109 indString = '\t' |
118 indString = "\t" |
110 else: |
119 else: |
111 indString = editor.indentationWidth() * ' ' |
120 indString = editor.indentationWidth() * " " |
112 return (dlg.getCode(indLevel, indString), True) |
121 return (dlg.getCode(indLevel, indString), True) |
113 else: |
122 else: |
114 return (None, False) |
123 return (None, False) |
115 |
124 |
116 def __handle(self): |
125 def __handle(self): |
117 """ |
126 """ |
118 Private method to handle the wizards action. |
127 Private method to handle the wizards action. |
119 """ |
128 """ |
120 editor = ericApp().getObject("ViewManager").activeWindow() |
129 editor = ericApp().getObject("ViewManager").activeWindow() |
121 |
130 |
122 if editor is None: |
131 if editor is None: |
123 EricMessageBox.critical( |
132 EricMessageBox.critical( |
124 self.__ui, |
133 self.__ui, |
125 self.tr('No current editor'), |
134 self.tr("No current editor"), |
126 self.tr('Please open or create a file first.')) |
135 self.tr("Please open or create a file first."), |
|
136 ) |
127 else: |
137 else: |
128 code, ok = self.__callForm(editor) |
138 code, ok = self.__callForm(editor) |
129 if ok: |
139 if ok: |
130 line, index = editor.getCursorPosition() |
140 line, index = editor.getCursorPosition() |
131 # It should be done on this way to allow undo |
141 # It should be done on this way to allow undo |
132 editor.beginUndoAction() |
142 editor.beginUndoAction() |
133 editor.insertAt(code, line, index) |
143 editor.insertAt(code, line, index) |
134 editor.endUndoAction() |
144 editor.endUndoAction() |
135 |
145 |
|
146 |
136 # |
147 # |
137 # eflag: noqa = M841 |
148 # eflag: noqa = M841 |