eric6/Plugins/PluginWizardSetup.py

changeset 6942
2602857055c5
parent 6735
31e263d49c04
child 7199
c71bd6f21748
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2013 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the setup.py wizard plug-in.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import QObject
13 from PyQt5.QtWidgets import QDialog
14
15 from E5Gui.E5Application import e5App
16 from E5Gui.E5Action import E5Action
17 from E5Gui import E5MessageBox
18
19 import UI.Info
20
21 # Start-of-Header
22 name = "setup.py Wizard Plug-in"
23 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
24 autoactivate = True
25 deactivateable = True
26 version = UI.Info.VersionOnly
27 className = "SetupWizard"
28 packageName = "__core__"
29 shortDescription = "Wizard for the creation of a setup.py file."
30 longDescription = \
31 """This plug-in implements a wizard to generate code for""" \
32 """ a setup.py file. It supports the 'distutils' and 'setuptools'""" \
33 """ variants."""
34 needsRestart = False
35 pyqtApi = 2
36 python2Compatible = True
37 # End-of-Header
38
39 error = ""
40
41
42 class SetupWizard(QObject):
43 """
44 Class implementing the setup.py wizard plug-in.
45 """
46 def __init__(self, ui):
47 """
48 Constructor
49
50 @param ui reference to the user interface object (UI.UserInterface)
51 """
52 super(SetupWizard, self).__init__(ui)
53 self.__ui = ui
54 self.__action = None
55
56 def __initialize(self):
57 """
58 Private slot to (re)initialize the plug-in.
59 """
60 self.__act = None
61
62 def activate(self):
63 """
64 Public method to activate this plug-in.
65
66 @return tuple of None and activation status (boolean)
67 """
68 self.__initAction()
69 self.__initMenu()
70
71 return None, True
72
73 def deactivate(self):
74 """
75 Public method to deactivate this plug-in.
76 """
77 menu = self.__ui.getMenu("wizards")
78 if menu:
79 menu.removeAction(self.__action)
80 self.__ui.removeE5Actions([self.__action], 'wizards')
81
82 def __initAction(self):
83 """
84 Private method to initialize the action.
85 """
86 self.__action = E5Action(
87 self.tr('setup.py Wizard'),
88 self.tr('&setup.py Wizard...'),
89 0, 0, self,
90 'wizards_setup_py')
91 self.__action.setStatusTip(self.tr('setup.py Wizard'))
92 self.__action.setWhatsThis(self.tr(
93 """<b>setup.py Wizard</b>"""
94 """<p>This wizard opens a dialog for entering all the parameters"""
95 """ needed to create the basic contents of a setup.py file. The"""
96 """ generated code is inserted at the current cursor position."""
97 """</p>"""
98 ))
99 self.__action.triggered.connect(self.__handle)
100
101 self.__ui.addE5Actions([self.__action], 'wizards')
102
103 def __initMenu(self):
104 """
105 Private method to add the actions to the right menu.
106 """
107 menu = self.__ui.getMenu("wizards")
108 if menu:
109 menu.addAction(self.__action)
110
111 def __callForm(self, editor):
112 """
113 Private method to display a dialog and get the code.
114
115 @param editor reference to the current editor
116 @return the generated code (string)
117 """
118 from WizardPlugins.SetupWizard.SetupWizardDialog import \
119 SetupWizardDialog
120 dlg = SetupWizardDialog(None)
121 if dlg.exec_() == QDialog.Accepted:
122 line, index = editor.getCursorPosition()
123 indLevel = editor.indentation(line) // editor.indentationWidth()
124 if editor.indentationsUseTabs():
125 indString = '\t'
126 else:
127 indString = editor.indentationWidth() * ' '
128 return (dlg.getCode(indLevel, indString), True)
129 else:
130 return (None, False)
131
132 def __handle(self):
133 """
134 Private method to handle the wizards action.
135 """
136 editor = e5App().getObject("ViewManager").activeWindow()
137
138 if editor is None:
139 E5MessageBox.critical(
140 self.__ui,
141 self.tr('No current editor'),
142 self.tr('Please open or create a file first.'))
143 else:
144 code, ok = self.__callForm(editor)
145 if ok:
146 line, index = editor.getCursorPosition()
147 # It should be done on this way to allow undo
148 editor.beginUndoAction()
149 editor.insertAt(code, line, index)
150 editor.endUndoAction()
151
152 #
153 # eflag: noqa = M801

eric ide

mercurial