Plugins/PluginWizardE5MessageBox.py

changeset 562
8bf0dbc1ca6a
child 791
9ec2ac20e54e
equal deleted inserted replaced
561:c4315307961b 562:8bf0dbc1ca6a
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2010 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the E5MessageBox wizard plugin.
8 """
9
10 from PyQt4.QtCore import QObject
11 from PyQt4.QtGui import QDialog
12
13 from E5Gui.E5Application import e5App
14 from E5Gui.E5Action import E5Action
15 from E5Gui import E5MessageBox
16
17 from WizardPlugins.E5MessageBoxWizard.E5MessageBoxWizardDialog import \
18 E5MessageBoxWizardDialog
19
20 # Start-Of-Header
21 name = "E5MessageBox Wizard Plugin"
22 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
23 autoactivate = True
24 deactivateable = True
25 version = "5.1.0"
26 className = "E5MessageBoxWizard"
27 packageName = "__core__"
28 shortDescription = "Show the E5MessageBox wizard."
29 longDescription = """This plugin shows the E5MessageBox wizard."""
30 pyqtApi = 2
31 # End-Of-Header
32
33 error = ""
34
35 class E5MessageBoxWizard(QObject):
36 """
37 Class implementing the E5MessageBox 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 QObject.__init__(self, 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.removeE5Actions([self.action], 'wizards')
67
68 def __initAction(self):
69 """
70 Private method to initialize the action.
71 """
72 self.action = E5Action(self.trUtf8('E5MessageBox Wizard'),
73 self.trUtf8('&E5MessageBox Wizard...'), 0, 0, self,
74 'wizards_e5messagebox')
75 self.action.setStatusTip(self.trUtf8('E5MessageBox Wizard'))
76 self.action.setWhatsThis(self.trUtf8(
77 """<b>E5MessageBox Wizard</b>"""
78 """<p>This wizard opens a dialog for entering all the parameters"""
79 """ needed to create an E5MessageBox. The generated code is inserted"""
80 """ at the current cursor position.</p>"""
81 ))
82 self.action.triggered[()].connect(self.__handle)
83
84 self.__ui.addE5Actions([self.action], 'wizards')
85
86 def __initMenu(self):
87 """
88 Private method to add the actions to the right menu.
89 """
90 menu = self.__ui.getMenu("wizards")
91 if menu:
92 menu.addAction(self.action)
93
94 def __callForm(self, editor):
95 """
96 Private method to display a dialog and get the code.
97
98 @param editor reference to the current editor
99 @return the generated code (string)
100 """
101 dlg = E5MessageBoxWizardDialog(None)
102 if dlg.exec_() == QDialog.Accepted:
103 line, index = editor.getCursorPosition()
104 indLevel = editor.indentation(line) // editor.indentationWidth()
105 if editor.indentationsUseTabs():
106 indString = '\t'
107 else:
108 indString = editor.indentationWidth() * ' '
109 return (dlg.getCode(indLevel, indString), True)
110 else:
111 return (None, False)
112
113 def __handle(self):
114 """
115 Private method to handle the wizards action
116 """
117 editor = e5App().getObject("ViewManager").activeWindow()
118
119 if editor == None:
120 E5MessageBox.critical(self.__ui,
121 self.trUtf8('No current editor'),
122 self.trUtf8('Please open or create a file first.'))
123 else:
124 code, ok = self.__callForm(editor)
125 if ok:
126 line, index = editor.getCursorPosition()
127 # It should be done on this way to allow undo
128 editor.beginUndoAction()
129 editor.insertAt(code, line, index)
130 editor.endUndoAction()

eric ide

mercurial