|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2013 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the setup.py wizard plug-in. |
|
8 """ |
|
9 |
|
10 import functools |
|
11 |
|
12 from PyQt6.QtCore import QObject |
|
13 |
|
14 from EricWidgets.EricApplication import ericApp |
|
15 from EricGui.EricAction import EricAction |
|
16 from EricWidgets import EricMessageBox |
|
17 |
|
18 import UI.Info |
|
19 |
|
20 # Start-of-Header |
|
21 name = "setup.py Wizard Plug-in" |
|
22 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
|
23 autoactivate = True |
|
24 deactivateable = True |
|
25 version = UI.Info.VersionOnly |
|
26 className = "SetupWizard" |
|
27 packageName = "__core__" |
|
28 shortDescription = "Wizard for the creation of a setup.py file." |
|
29 longDescription = ( |
|
30 """This plug-in implements a wizard to generate code for""" |
|
31 """ a setup.py file. It supports the 'setuptools' variant.""" |
|
32 ) |
|
33 needsRestart = False |
|
34 pyqtApi = 2 |
|
35 # End-of-Header |
|
36 |
|
37 error = "" |
|
38 |
|
39 |
|
40 class SetupWizard(QObject): |
|
41 """ |
|
42 Class implementing the setup.py wizard plug-in. |
|
43 """ |
|
44 def __init__(self, ui): |
|
45 """ |
|
46 Constructor |
|
47 |
|
48 @param ui reference to the user interface object |
|
49 @type UI.UserInterface |
|
50 """ |
|
51 super().__init__(ui) |
|
52 self.__ui = ui |
|
53 self.__actions = [] |
|
54 |
|
55 def activate(self): |
|
56 """ |
|
57 Public method to activate this plug-in. |
|
58 |
|
59 @return tuple of None and activation status |
|
60 @rtype tuple of (None, boolean) |
|
61 """ |
|
62 self.__initActions() |
|
63 self.__initMenu() |
|
64 |
|
65 return None, True |
|
66 |
|
67 def deactivate(self): |
|
68 """ |
|
69 Public method to deactivate this plug-in. |
|
70 """ |
|
71 menu = self.__ui.getMenu("wizards") |
|
72 if menu: |
|
73 for act in self.__actions: |
|
74 menu.removeAction(act) |
|
75 self.__ui.removeEricActions(self.__actions, 'wizards') |
|
76 |
|
77 def __initActions(self): |
|
78 """ |
|
79 Private method to initialize the actions. |
|
80 """ |
|
81 # 1. action for 'setup.py' creation |
|
82 act = EricAction( |
|
83 self.tr('setup.py Wizard'), |
|
84 self.tr('setup.py Wizard...'), |
|
85 0, 0, self, |
|
86 'wizards_setup_py') |
|
87 act.setStatusTip(self.tr('setup.py Wizard')) |
|
88 act.setWhatsThis(self.tr( |
|
89 """<b>setup.py Wizard</b>""" |
|
90 """<p>This wizard opens a dialog for entering all the parameters""" |
|
91 """ needed to create the basic contents of a setup.py file. The""" |
|
92 """ generated code is inserted at the current cursor position.""" |
|
93 """</p>""" |
|
94 )) |
|
95 act.triggered.connect(functools.partial(self.__handle, "setup.py")) |
|
96 self.__actions.append(act) |
|
97 |
|
98 # 2. action for 'setup.cfg' creation |
|
99 act = EricAction( |
|
100 self.tr('setup.cfg Wizard'), |
|
101 self.tr('setup.cfg Wizard...'), |
|
102 0, 0, self, |
|
103 'wizards_setup_cfg') |
|
104 act.setStatusTip(self.tr('setup.cfg Wizard')) |
|
105 act.setWhatsThis(self.tr( |
|
106 """<b>setup.cfg Wizard</b>""" |
|
107 """<p>This wizard opens a dialog for entering all the parameters""" |
|
108 """ needed to create the basic contents of a setup.cfg file. The""" |
|
109 """ generated code is inserted at the current cursor position.""" |
|
110 """</p>""" |
|
111 )) |
|
112 act.triggered.connect(functools.partial(self.__handle, "setup.cfg")) |
|
113 self.__actions.append(act) |
|
114 |
|
115 # 3. action for 'pyproject.toml' creation |
|
116 act = EricAction( |
|
117 self.tr('pyproject.toml Wizard'), |
|
118 self.tr('pyproject.toml Wizard...'), |
|
119 0, 0, self, |
|
120 'wizards_pyproject_toml') |
|
121 act.setStatusTip(self.tr('pyproject.toml Wizard')) |
|
122 act.setWhatsThis(self.tr( |
|
123 """<b>pyproject.toml Wizard</b>""" |
|
124 """<p>This wizard opens a dialog for entering all the parameters""" |
|
125 """ needed to create the basic contents of a pyproject.toml file. The""" |
|
126 """ generated code is inserted at the current cursor position.""" |
|
127 """</p>""" |
|
128 )) |
|
129 act.triggered.connect(functools.partial(self.__handle, "pyproject.toml")) |
|
130 self.__actions.append(act) |
|
131 |
|
132 self.__ui.addEricActions(self.__actions, 'wizards') |
|
133 |
|
134 def __initMenu(self): |
|
135 """ |
|
136 Private method to add the actions to the right menu. |
|
137 """ |
|
138 menu = self.__ui.getMenu("wizards") |
|
139 if menu: |
|
140 menu.addActions(self.__actions) |
|
141 |
|
142 def __handle(self, category): |
|
143 """ |
|
144 Private method to handle the wizards action. |
|
145 |
|
146 @param category category of setup file to create |
|
147 @type str |
|
148 """ |
|
149 from WizardPlugins.SetupWizard.SetupWizardDialog import ( |
|
150 SetupWizardDialog |
|
151 ) |
|
152 |
|
153 editor = ericApp().getObject("ViewManager").activeWindow() |
|
154 |
|
155 if editor is None: |
|
156 EricMessageBox.critical( |
|
157 self.__ui, |
|
158 self.tr('No current editor'), |
|
159 self.tr('Please open or create a file first.')) |
|
160 else: |
|
161 dlg = SetupWizardDialog(category, editor, self.__ui) |
|
162 dlg.show() |
|
163 |
|
164 # |
|
165 # eflag: noqa = M801 |