|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2014 - 2017 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the eric plug-in wizard dialog. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot, QDate |
|
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
|
14 |
|
15 from E5Gui.E5Application import e5App |
|
16 |
|
17 from .Ui_PluginWizardDialog import Ui_PluginWizardDialog |
|
18 |
|
19 from .Templates import mainTemplate, configTemplate0, configTemplate1, \ |
|
20 configTemplate2, configTemplate3, onDemandTemplate, \ |
|
21 previewPixmapTemplate, moduleSetupTemplate, exeDisplayDataTemplate, \ |
|
22 exeDisplayDataListTemplate, apiFilesTemplate |
|
23 |
|
24 |
|
25 class PluginWizardDialog(QDialog, Ui_PluginWizardDialog): |
|
26 """ |
|
27 Class implementing the eric plug-in wizard dialog. |
|
28 """ |
|
29 def __init__(self, parent=None): |
|
30 """ |
|
31 Constructor |
|
32 |
|
33 @param parent reference to the parent widget (QWidget) |
|
34 """ |
|
35 super(PluginWizardDialog, self).__init__(parent) |
|
36 self.setupUi(self) |
|
37 |
|
38 self.dataTabWidget.setCurrentIndex(0) |
|
39 |
|
40 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
|
41 self.__okButton.setEnabled(False) |
|
42 |
|
43 projectOpen = e5App().getObject("Project").isOpen() |
|
44 self.projectButton.setEnabled(projectOpen) |
|
45 |
|
46 self.nameEdit.textChanged.connect(self.__enableOkButton) |
|
47 self.versionEdit.textChanged.connect(self.__enableOkButton) |
|
48 self.authorEdit.textChanged.connect(self.__enableOkButton) |
|
49 self.authorEmailEdit.textChanged.connect(self.__enableOkButton) |
|
50 self.classNameEdit.textChanged.connect(self.__enableOkButton) |
|
51 self.packageNameEdit.textChanged.connect(self.__enableOkButton) |
|
52 self.shortDescriptionEdit.textChanged.connect(self.__enableOkButton) |
|
53 self.longDescriptionEdit.textChanged.connect(self.__enableOkButton) |
|
54 self.preferencesKeyEdit.textChanged.connect(self.__enableOkButton) |
|
55 self.configurationGroup.toggled.connect(self.__enableOkButton) |
|
56 self.autoActivateCheckBox.toggled.connect(self.__enableOkButton) |
|
57 self.pluginTypeCombo.currentIndexChanged.connect(self.__enableOkButton) |
|
58 self.pluginTypeNameEdit.textChanged.connect(self.__enableOkButton) |
|
59 |
|
60 self.pluginTypeCombo.addItems(["", "viewmanager", "version_control"]) |
|
61 |
|
62 def __enableOkButton(self): |
|
63 """ |
|
64 Private slot to set the state of the OK button. |
|
65 """ |
|
66 enable = ( |
|
67 bool(self.nameEdit.text()) and |
|
68 bool(self.versionEdit.text()) and |
|
69 bool(self.authorEdit.text()) and |
|
70 bool(self.authorEmailEdit.text()) and |
|
71 bool(self.classNameEdit.text()) and |
|
72 bool(self.packageNameEdit.text()) and |
|
73 bool(self.shortDescriptionEdit.text()) and |
|
74 bool(self.longDescriptionEdit.toPlainText()) |
|
75 ) |
|
76 if self.configurationGroup.isChecked(): |
|
77 enable = enable and bool(self.preferencesKeyEdit.text()) |
|
78 if not self.autoActivateCheckBox.isChecked(): |
|
79 enable = (enable and |
|
80 bool(self.pluginTypeCombo.currentText()) and |
|
81 bool(self.pluginTypeNameEdit.text()) |
|
82 ) |
|
83 |
|
84 self.__okButton.setEnabled(enable) |
|
85 |
|
86 @pyqtSlot() |
|
87 def on_projectButton_clicked(self): |
|
88 """ |
|
89 Private slot to populate some fields with data retrieved from the |
|
90 current project. |
|
91 """ |
|
92 project = e5App().getObject("Project") |
|
93 |
|
94 try: |
|
95 self.versionEdit.setText(project.getProjectVersion()) |
|
96 self.authorEdit.setText(project.getProjectAuthor()) |
|
97 self.authorEmailEdit.setText(project.getProjectAuthorEmail()) |
|
98 description = project.getProjectDescription() |
|
99 except AttributeError: |
|
100 self.versionEdit.setText(project.pdata["VERSION"][0]) |
|
101 self.authorEdit.setText(project.pdata["AUTHOR"][0]) |
|
102 self.authorEmailEdit.setText(project.pdata["EMAIL"][0]) |
|
103 description = project.pdata["DESCRIPTION"][0] |
|
104 |
|
105 # summary is max. 55 characters long |
|
106 summary = (description.split(".", 1)[0] |
|
107 .replace("\r", "").replace("\n", "") + ".")[:55] |
|
108 self.shortDescriptionEdit.setText(summary) |
|
109 self.longDescriptionEdit.setPlainText(description) |
|
110 |
|
111 # prevent overwriting of entries by disabling the button |
|
112 self.projectButton.setEnabled(False) |
|
113 |
|
114 def getCode(self): |
|
115 """ |
|
116 Public method to get the source code. |
|
117 |
|
118 @return generated code (string) |
|
119 """ |
|
120 templateData = { |
|
121 "year": QDate.currentDate().year(), |
|
122 "author": self.authorEdit.text(), |
|
123 "email": self.authorEmailEdit.text(), |
|
124 "name": self.nameEdit.text(), |
|
125 "autoactivate": self.autoActivateCheckBox.isChecked(), |
|
126 "deactivateable": self.deactivateableCheckBox.isChecked(), |
|
127 "version": self.versionEdit.text(), |
|
128 "className": self.classNameEdit.text(), |
|
129 "packageName": self.packageNameEdit.text(), |
|
130 "shortDescription": self.shortDescriptionEdit.text(), |
|
131 "longDescription": self.longDescriptionEdit.toPlainText(), |
|
132 "needsRestart": self.restartCheckBox.isChecked(), |
|
133 "python2Compatible": self.python2CheckBox.isChecked() |
|
134 } |
|
135 |
|
136 if self.configurationGroup.isChecked(): |
|
137 templateData["config0"] = configTemplate0 |
|
138 templateData["config1"] = configTemplate1.format( |
|
139 className=self.classNameEdit.text()) |
|
140 templateData["config2"] = configTemplate2.format( |
|
141 preferencesKey=self.preferencesKeyEdit.text()) |
|
142 templateData["config3"] = configTemplate3 |
|
143 else: |
|
144 templateData["config0"] = "" |
|
145 templateData["config1"] = "" |
|
146 templateData["config2"] = "" |
|
147 templateData["config3"] = "" |
|
148 |
|
149 if self.autoActivateCheckBox.isChecked(): |
|
150 templateData["onDemand"] = "" |
|
151 else: |
|
152 templateData["onDemand"] = onDemandTemplate.format( |
|
153 pluginType=self.pluginTypeCombo.currentText(), |
|
154 pluginTypename=self.pluginTypeNameEdit.text() |
|
155 ) |
|
156 |
|
157 if self.pixmapCheckBox.isChecked(): |
|
158 templateData["preview"] = previewPixmapTemplate |
|
159 else: |
|
160 templateData["preview"] = "" |
|
161 |
|
162 if self.moduleSetupCheckBox.isChecked(): |
|
163 templateData["modulesetup"] = moduleSetupTemplate |
|
164 else: |
|
165 templateData["modulesetup"] = "" |
|
166 |
|
167 templateData["exeData"] = "" |
|
168 templateData["exeDataList"] = "" |
|
169 if self.exeGroup.isChecked(): |
|
170 if self.exeRadioButton.isChecked(): |
|
171 templateData["exeData"] = exeDisplayDataTemplate |
|
172 elif self.exeListRadioButton.isChecked(): |
|
173 templateData["exeDataList"] = exeDisplayDataListTemplate |
|
174 |
|
175 if self.apiFilesCheckBox.isChecked(): |
|
176 templateData["apiFiles"] = apiFilesTemplate |
|
177 else: |
|
178 templateData["apiFiles"] = "" |
|
179 |
|
180 return mainTemplate.format(**templateData) |
|
181 |
|
182 def packageName(self): |
|
183 """ |
|
184 Public method to retrieve the plug-in package name. |
|
185 |
|
186 @return plug-in package name (string) |
|
187 """ |
|
188 if self.createPackageCheckBox.isChecked(): |
|
189 return self.packageNameEdit.text() |
|
190 else: |
|
191 return "" |
|
192 |
|
193 @pyqtSlot(str) |
|
194 def on_pluginTypeCombo_currentTextChanged(self, txt): |
|
195 """ |
|
196 Private slot to react upon the selection of a plug-in type. |
|
197 |
|
198 @param txt selected plug-in type (string) |
|
199 """ |
|
200 self.pixmapCheckBox.setChecked(txt == "viewmanager") |