eric7/Plugins/PluginWizardEricMessageBox.py

branch
eric7
changeset 8364
2d72d4d11771
parent 8358
144a6b854f70
child 8366
2a9f5153c438
equal deleted inserted replaced
8363:e0890180e16a 8364:2d72d4d11771
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2010 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the EricMessageBox wizard plugin.
8 """
9
10 from PyQt6.QtCore import QObject
11 from PyQt6.QtWidgets import QDialog
12
13 from EricWidgets.EricApplication import ericApp
14 from EricGui.EricAction import EricAction
15 from EricWidgets import EricMessageBox
16
17 import UI.Info
18
19 # Start-Of-Header
20 name = "EricMessageBox Wizard Plugin"
21 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
22 autoactivate = True
23 deactivateable = True
24 version = UI.Info.VersionOnly
25 className = "EricMessageBoxWizard"
26 packageName = "__core__"
27 shortDescription = "Show the EricMessageBox wizard."
28 longDescription = """This plugin shows the EricMessageBox wizard."""
29 pyqtApi = 2
30 # End-Of-Header
31
32 error = ""
33
34
35 class EricMessageBoxWizard(QObject):
36 """
37 Class implementing the EricMessageBox wizard plugin.
38 """
39 def __init__(self, ui):
40 """
41 Constructor
42
43 @param ui reference to the user interface object (UI.UserInterface)
44 """
45 super().__init__(ui)
46 self.__ui = ui
47
48 def activate(self):
49 """
50 Public method to activate this plugin.
51
52 @return tuple of None and activation status (boolean)
53 """
54 self.__initAction()
55 self.__initMenu()
56
57 return None, True
58
59 def deactivate(self):
60 """
61 Public method to deactivate this plugin.
62 """
63 menu = self.__ui.getMenu("wizards")
64 if menu:
65 menu.removeAction(self.action)
66 self.__ui.removeEricActions([self.action], 'wizards')
67
68 def __initAction(self):
69 """
70 Private method to initialize the action.
71 """
72 self.action = EricAction(
73 self.tr('EricMessageBox Wizard'),
74 self.tr('&EricMessageBox Wizard...'), 0, 0, self,
75 'wizards_e5messagebox')
76 self.action.setStatusTip(self.tr('EricMessageBox Wizard'))
77 self.action.setWhatsThis(self.tr(
78 """<b>EricMessageBox Wizard</b>"""
79 """<p>This wizard opens a dialog for entering all the parameters"""
80 """ needed to create an EricMessageBox. The generated code is"""
81 """ inserted at the current cursor position.</p>"""
82 ))
83 self.action.triggered.connect(self.__handle)
84
85 self.__ui.addEricActions([self.action], 'wizards')
86
87 def __initMenu(self):
88 """
89 Private method to add the actions to the right menu.
90 """
91 menu = self.__ui.getMenu("wizards")
92 if menu:
93 menu.addAction(self.action)
94
95 def __callForm(self, editor):
96 """
97 Private method to display a dialog and get the code.
98
99 @param editor reference to the current editor
100 @return the generated code (string)
101 """
102 from WizardPlugins.EricMessageBoxWizard.EricMessageBoxWizardDialog import (
103 EricMessageBoxWizardDialog
104 )
105 dlg = EricMessageBoxWizardDialog(None)
106 if dlg.exec() == QDialog.DialogCode.Accepted:
107 line, index = editor.getCursorPosition()
108 indLevel = editor.indentation(line) // editor.indentationWidth()
109 if editor.indentationsUseTabs():
110 indString = '\t'
111 else:
112 indString = editor.indentationWidth() * ' '
113 return (dlg.getCode(indLevel, indString), True)
114 else:
115 return (None, False)
116
117 def __handle(self):
118 """
119 Private method to handle the wizards action.
120 """
121 editor = ericApp().getObject("ViewManager").activeWindow()
122
123 if editor is None:
124 EricMessageBox.critical(
125 self.__ui,
126 self.tr('No current editor'),
127 self.tr('Please open or create a file first.'))
128 else:
129 code, ok = self.__callForm(editor)
130 if ok:
131 line, index = editor.getCursorPosition()
132 # It should be done on this way to allow undo
133 editor.beginUndoAction()
134 editor.insertAt(code, line, index)
135 editor.endUndoAction()

eric ide

mercurial