33 class ProjectFormsBrowser(ProjectBaseBrowser): |
34 class ProjectFormsBrowser(ProjectBaseBrowser): |
34 """ |
35 """ |
35 A class used to display the forms part of the project. |
36 A class used to display the forms part of the project. |
36 |
37 |
37 @signal appendStderr(str) emitted after something was received from |
38 @signal appendStderr(str) emitted after something was received from |
38 a QProcess on stderr |
39 a QProcess on stderr |
39 @signal sourceFile(str) emitted to open a forms file in an editor |
40 @signal sourceFile(str) emitted to open a forms file in an editor |
40 @signal uipreview(str) emitted to preview a forms file |
41 @signal uipreview(str) emitted to preview a forms file |
41 @signal trpreview(list of str) emitted to preview form files in the |
42 @signal trpreview(list of str) emitted to preview form files in the |
42 translations previewer |
43 translations previewer |
43 @signal closeSourceWindow(str) emitted after a file has been removed/deleted |
44 @signal closeSourceWindow(str) emitted after a file has been |
44 from the project |
45 removed/deleted from the project |
45 @signal showMenu(str, QMenu) emitted when a menu is about to be shown. The name |
46 @signal showMenu(str, QMenu) emitted when a menu is about to be shown. The |
46 of the menu and a reference to the menu are given. |
47 name of the menu and a reference to the menu are given. |
47 @signal menusAboutToBeCreated() emitted when the context menus are about to |
48 @signal menusAboutToBeCreated() emitted when the context menus are about to |
48 be created. This is the right moment to add or remove hook methods. |
49 be created. This is the right moment to add or remove hook methods. |
49 """ |
50 """ |
50 appendStderr = pyqtSignal(str) |
51 appendStderr = pyqtSignal(str) |
51 uipreview = pyqtSignal(str) |
52 uipreview = pyqtSignal(str) |
52 showMenu = pyqtSignal(str, QMenu) |
53 showMenu = pyqtSignal(str, QMenu) |
53 menusAboutToBeCreated = pyqtSignal() |
54 menusAboutToBeCreated = pyqtSignal() |
57 Constructor |
58 Constructor |
58 |
59 |
59 @param project reference to the project object |
60 @param project reference to the project object |
60 @param parent parent widget of this browser (QWidget) |
61 @param parent parent widget of this browser (QWidget) |
61 """ |
62 """ |
62 ProjectBaseBrowser.__init__(self, project, ProjectBrowserFormType, parent) |
63 ProjectBaseBrowser.__init__(self, project, ProjectBrowserFormType, |
|
64 parent) |
63 |
65 |
64 self.selectedItemsFilter = \ |
66 self.selectedItemsFilter = \ |
65 [ProjectBrowserFileItem, ProjectBrowserSimpleDirectoryItem] |
67 [ProjectBrowserFileItem, ProjectBrowserSimpleDirectoryItem] |
66 |
68 |
67 self.setWindowTitle(self.trUtf8('Forms')) |
69 self.setWindowTitle(self.trUtf8('Forms')) |
68 |
70 |
69 self.setWhatsThis(self.trUtf8( |
71 self.setWhatsThis(self.trUtf8( |
70 """<b>Project Forms Browser</b>""" |
72 """<b>Project Forms Browser</b>""" |
71 """<p>This allows to easily see all forms contained in the current""" |
73 """<p>This allows to easily see all forms contained in the""" |
72 """ project. Several actions can be executed via the context menu.</p>""" |
74 """ current project. Several actions can be executed via the""" |
|
75 """ context menu.</p>""" |
73 )) |
76 )) |
74 |
77 |
75 # templates for Qt4 |
78 # templates for Qt4 |
76 # these two lists have to stay in sync |
79 # these two lists have to stay in sync |
77 self.templates4 = ['dialog4.tmpl', 'widget4.tmpl', 'mainwindow4.tmpl', |
80 self.templates4 = ['dialog4.tmpl', 'widget4.tmpl', 'mainwindow4.tmpl', |
115 self.dirMultiMenuActions = [] |
118 self.dirMultiMenuActions = [] |
116 |
119 |
117 self.menusAboutToBeCreated.emit() |
120 self.menusAboutToBeCreated.emit() |
118 |
121 |
119 self.menu = QMenu(self) |
122 self.menu = QMenu(self) |
120 if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]: |
123 if self.project.getProjectType() in \ |
121 self.menu.addAction(self.trUtf8('Compile form'), self.__compileForm) |
124 ["Qt4", "PyQt5", "E4Plugin", "PySide"]: |
|
125 self.menu.addAction( |
|
126 self.trUtf8('Compile form'), self.__compileForm) |
122 self.menu.addAction(self.trUtf8('Compile all forms'), |
127 self.menu.addAction(self.trUtf8('Compile all forms'), |
123 self.__compileAllForms) |
128 self.__compileAllForms) |
124 self.menu.addAction(self.trUtf8('Generate Dialog Code...'), |
129 self.menu.addAction(self.trUtf8('Generate Dialog Code...'), |
125 self.__generateDialogCode) |
130 self.__generateDialogCode) |
126 self.menu.addSeparator() |
131 self.menu.addSeparator() |
127 self.menu.addAction(self.trUtf8('Open in Qt-Designer'), self.__openFile) |
132 self.menu.addAction( |
128 self.menu.addAction(self.trUtf8('Open in Editor'), self.__openFileInEditor) |
133 self.trUtf8('Open in Qt-Designer'), self.__openFile) |
|
134 self.menu.addAction( |
|
135 self.trUtf8('Open in Editor'), self.__openFileInEditor) |
129 self.menu.addSeparator() |
136 self.menu.addSeparator() |
130 self.menu.addAction(self.trUtf8('Preview form'), self.__UIPreview) |
137 self.menu.addAction(self.trUtf8('Preview form'), self.__UIPreview) |
131 self.menu.addAction(self.trUtf8('Preview translations'), self.__TRPreview) |
138 self.menu.addAction( |
|
139 self.trUtf8('Preview translations'), self.__TRPreview) |
132 else: |
140 else: |
133 if self.hooks["compileForm"] is not None: |
141 if self.hooks["compileForm"] is not None: |
134 self.menu.addAction( |
142 self.menu.addAction( |
135 self.hooksMenuEntries.get("compileForm", |
143 self.hooksMenuEntries.get("compileForm", |
136 self.trUtf8('Compile form')), self.__compileForm) |
144 self.trUtf8('Compile form')), self.__compileForm) |
154 self.__openFile) |
162 self.__openFile) |
155 self.menu.addAction(self.trUtf8('Open'), self.__openFileInEditor) |
163 self.menu.addAction(self.trUtf8('Open'), self.__openFileInEditor) |
156 self.menu.addSeparator() |
164 self.menu.addSeparator() |
157 act = self.menu.addAction(self.trUtf8('Rename file'), self._renameFile) |
165 act = self.menu.addAction(self.trUtf8('Rename file'), self._renameFile) |
158 self.menuActions.append(act) |
166 self.menuActions.append(act) |
159 act = self.menu.addAction(self.trUtf8('Remove from project'), self._removeFile) |
167 act = self.menu.addAction( |
|
168 self.trUtf8('Remove from project'), self._removeFile) |
160 self.menuActions.append(act) |
169 self.menuActions.append(act) |
161 act = self.menu.addAction(self.trUtf8('Delete'), self.__deleteFile) |
170 act = self.menu.addAction(self.trUtf8('Delete'), self.__deleteFile) |
162 self.menuActions.append(act) |
171 self.menuActions.append(act) |
163 self.menu.addSeparator() |
172 self.menu.addSeparator() |
164 if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]: |
173 if self.project.getProjectType() in \ |
|
174 ["Qt4", "PyQt5", "E4Plugin", "PySide"]: |
165 self.menu.addAction(self.trUtf8('New form...'), self.__newForm) |
175 self.menu.addAction(self.trUtf8('New form...'), self.__newForm) |
166 else: |
176 else: |
167 if self.hooks["newForm"] is not None: |
177 if self.hooks["newForm"] is not None: |
168 self.menu.addAction( |
178 self.menu.addAction( |
169 self.hooksMenuEntries.get("newForm", |
179 self.hooksMenuEntries.get("newForm", |
181 self._collapseAllDirs) |
191 self._collapseAllDirs) |
182 self.menu.addSeparator() |
192 self.menu.addSeparator() |
183 self.menu.addAction(self.trUtf8('Configure...'), self._configure) |
193 self.menu.addAction(self.trUtf8('Configure...'), self._configure) |
184 |
194 |
185 self.backMenu = QMenu(self) |
195 self.backMenu = QMenu(self) |
186 if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"] or \ |
196 if self.project.getProjectType() in \ |
187 self.hooks["compileAllForms"] is not None: |
197 ["Qt4", "PyQt5", "E4Plugin", "PySide"] or \ |
|
198 self.hooks["compileAllForms"] is not None: |
188 self.backMenu.addAction(self.trUtf8('Compile all forms'), |
199 self.backMenu.addAction(self.trUtf8('Compile all forms'), |
189 self.__compileAllForms) |
200 self.__compileAllForms) |
190 self.backMenu.addSeparator() |
201 self.backMenu.addSeparator() |
191 self.backMenu.addAction(self.trUtf8('New form...'), self.__newForm) |
202 self.backMenu.addAction(self.trUtf8('New form...'), self.__newForm) |
192 else: |
203 else: |
193 if self.hooks["newForm"] is not None: |
204 if self.hooks["newForm"] is not None: |
194 self.backMenu.addAction( |
205 self.backMenu.addAction( |
195 self.hooksMenuEntries.get("newForm", |
206 self.hooksMenuEntries.get("newForm", |
196 self.trUtf8('New form...')), self.__newForm) |
207 self.trUtf8('New form...')), self.__newForm) |
197 self.backMenu.addAction(self.trUtf8('Add forms...'), self.project.addUiFiles) |
208 self.backMenu.addAction( |
|
209 self.trUtf8('Add forms...'), self.project.addUiFiles) |
198 self.backMenu.addAction(self.trUtf8('Add forms directory...'), |
210 self.backMenu.addAction(self.trUtf8('Add forms directory...'), |
199 self.project.addUiDir) |
211 self.project.addUiDir) |
200 self.backMenu.addSeparator() |
212 self.backMenu.addSeparator() |
201 self.backMenu.addAction(self.trUtf8('Expand all directories'), |
213 self.backMenu.addAction(self.trUtf8('Expand all directories'), |
202 self._expandAllDirs) |
214 self._expandAllDirs) |
206 self.backMenu.addAction(self.trUtf8('Configure...'), self._configure) |
218 self.backMenu.addAction(self.trUtf8('Configure...'), self._configure) |
207 self.backMenu.setEnabled(False) |
219 self.backMenu.setEnabled(False) |
208 |
220 |
209 # create the menu for multiple selected files |
221 # create the menu for multiple selected files |
210 self.multiMenu = QMenu(self) |
222 self.multiMenu = QMenu(self) |
211 if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]: |
223 if self.project.getProjectType() in \ |
|
224 ["Qt4", "PyQt5", "E4Plugin", "PySide"]: |
212 act = self.multiMenu.addAction(self.trUtf8('Compile forms'), |
225 act = self.multiMenu.addAction(self.trUtf8('Compile forms'), |
213 self.__compileSelectedForms) |
226 self.__compileSelectedForms) |
214 self.multiMenu.addSeparator() |
227 self.multiMenu.addSeparator() |
215 self.multiMenu.addAction(self.trUtf8('Open in Qt-Designer'), |
228 self.multiMenu.addAction(self.trUtf8('Open in Qt-Designer'), |
216 self.__openFile) |
229 self.__openFile) |
228 self.multiMenu.addSeparator() |
241 self.multiMenu.addSeparator() |
229 if self.hooks["open"] is not None: |
242 if self.hooks["open"] is not None: |
230 self.multiMenu.addAction( |
243 self.multiMenu.addAction( |
231 self.hooksMenuEntries.get("open", self.trUtf8('Open')), |
244 self.hooksMenuEntries.get("open", self.trUtf8('Open')), |
232 self.__openFile) |
245 self.__openFile) |
233 self.multiMenu.addAction(self.trUtf8('Open'), self.__openFileInEditor) |
246 self.multiMenu.addAction( |
|
247 self.trUtf8('Open'), self.__openFileInEditor) |
234 self.multiMenu.addSeparator() |
248 self.multiMenu.addSeparator() |
235 act = self.multiMenu.addAction(self.trUtf8('Remove from project'), |
249 act = self.multiMenu.addAction(self.trUtf8('Remove from project'), |
236 self._removeFile) |
250 self._removeFile) |
237 self.multiMenuActions.append(act) |
251 self.multiMenuActions.append(act) |
238 act = self.multiMenu.addAction(self.trUtf8('Delete'), self.__deleteFile) |
252 act = self.multiMenu.addAction( |
|
253 self.trUtf8('Delete'), self.__deleteFile) |
239 self.multiMenuActions.append(act) |
254 self.multiMenuActions.append(act) |
240 self.multiMenu.addSeparator() |
255 self.multiMenu.addSeparator() |
241 self.multiMenu.addAction(self.trUtf8('Expand all directories'), |
256 self.multiMenu.addAction(self.trUtf8('Expand all directories'), |
242 self._expandAllDirs) |
257 self._expandAllDirs) |
243 self.multiMenu.addAction(self.trUtf8('Collapse all directories'), |
258 self.multiMenu.addAction(self.trUtf8('Collapse all directories'), |
244 self._collapseAllDirs) |
259 self._collapseAllDirs) |
245 self.multiMenu.addSeparator() |
260 self.multiMenu.addSeparator() |
246 self.multiMenu.addAction(self.trUtf8('Configure...'), self._configure) |
261 self.multiMenu.addAction(self.trUtf8('Configure...'), self._configure) |
247 |
262 |
248 self.dirMenu = QMenu(self) |
263 self.dirMenu = QMenu(self) |
249 if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]: |
264 if self.project.getProjectType() in \ |
|
265 ["Qt4", "PyQt5", "E4Plugin", "PySide"]: |
250 self.dirMenu.addAction(self.trUtf8('Compile all forms'), |
266 self.dirMenu.addAction(self.trUtf8('Compile all forms'), |
251 self.__compileAllForms) |
267 self.__compileAllForms) |
252 self.dirMenu.addSeparator() |
268 self.dirMenu.addSeparator() |
253 else: |
269 else: |
254 if self.hooks["compileAllForms"] is not None: |
270 if self.hooks["compileAllForms"] is not None: |
255 self.dirMenu.addAction( |
271 self.dirMenu.addAction( |
256 self.hooksMenuEntries.get("compileAllForms", |
272 self.hooksMenuEntries.get("compileAllForms", |
257 self.trUtf8('Compile all forms')), |
273 self.trUtf8('Compile all forms')), |
258 self.__compileAllForms) |
274 self.__compileAllForms) |
259 self.dirMenu.addSeparator() |
275 self.dirMenu.addSeparator() |
260 act = self.dirMenu.addAction(self.trUtf8('Remove from project'), self._removeDir) |
276 act = self.dirMenu.addAction( |
|
277 self.trUtf8('Remove from project'), self._removeDir) |
261 self.dirMenuActions.append(act) |
278 self.dirMenuActions.append(act) |
262 act = self.dirMenu.addAction(self.trUtf8('Delete'), self._deleteDirectory) |
279 act = self.dirMenu.addAction( |
|
280 self.trUtf8('Delete'), self._deleteDirectory) |
263 self.dirMenuActions.append(act) |
281 self.dirMenuActions.append(act) |
264 self.dirMenu.addSeparator() |
282 self.dirMenu.addSeparator() |
265 if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]: |
283 if self.project.getProjectType() in \ |
|
284 ["Qt4", "PyQt5", "E4Plugin", "PySide"]: |
266 self.dirMenu.addAction(self.trUtf8('New form...'), self.__newForm) |
285 self.dirMenu.addAction(self.trUtf8('New form...'), self.__newForm) |
267 else: |
286 else: |
268 if self.hooks["newForm"] is not None: |
287 if self.hooks["newForm"] is not None: |
269 self.dirMenu.addAction( |
288 self.dirMenu.addAction( |
270 self.hooksMenuEntries.get("newForm", |
289 self.hooksMenuEntries.get("newForm", |
271 self.trUtf8('New form...')), self.__newForm) |
290 self.trUtf8('New form...')), self.__newForm) |
272 self.dirMenu.addAction(self.trUtf8('Add forms...'), self.__addFormFiles) |
291 self.dirMenu.addAction( |
|
292 self.trUtf8('Add forms...'), self.__addFormFiles) |
273 self.dirMenu.addAction(self.trUtf8('Add forms directory...'), |
293 self.dirMenu.addAction(self.trUtf8('Add forms directory...'), |
274 self.__addFormsDirectory) |
294 self.__addFormsDirectory) |
275 self.dirMenu.addSeparator() |
295 self.dirMenu.addSeparator() |
276 self.dirMenu.addAction(self.trUtf8('Copy Path to Clipboard'), |
296 self.dirMenu.addAction(self.trUtf8('Copy Path to Clipboard'), |
277 self._copyToClipboard) |
297 self._copyToClipboard) |
496 path = os.path.join(self.project.ppath, itm.data(0)) |
519 path = os.path.join(self.project.ppath, itm.data(0)) |
497 |
520 |
498 if self.hooks["newForm"] is not None: |
521 if self.hooks["newForm"] is not None: |
499 self.hooks["newForm"](path) |
522 self.hooks["newForm"](path) |
500 else: |
523 else: |
501 if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]: |
524 if self.project.getProjectType() in \ |
|
525 ["Qt4", "PyQt5", "E4Plugin", "PySide"]: |
502 self.__newUiForm(path) |
526 self.__newUiForm(path) |
503 |
527 |
504 def __newUiForm(self, path): |
528 def __newUiForm(self, path): |
505 """ |
529 """ |
506 Private slot to handle the New Form menu action for Qt-related projects. |
530 Private slot to handle the New Form menu action for Qt-related |
|
531 projects. |
507 |
532 |
508 @param path full directory path for the new form file (string) |
533 @param path full directory path for the new form file (string) |
509 """ |
534 """ |
510 selectedForm, ok = QInputDialog.getItem( |
535 selectedForm, ok = QInputDialog.getItem( |
511 None, |
536 None, |
572 fn2 = itm.fileName() |
598 fn2 = itm.fileName() |
573 fullNames.append(fn2) |
599 fullNames.append(fn2) |
574 fn = self.project.getRelativePath(fn2) |
600 fn = self.project.getRelativePath(fn2) |
575 files.append(fn) |
601 files.append(fn) |
576 |
602 |
577 from UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog |
603 from UI.DeleteFilesConfirmationDialog import \ |
|
604 DeleteFilesConfirmationDialog |
578 dlg = DeleteFilesConfirmationDialog(self.parent(), |
605 dlg = DeleteFilesConfirmationDialog(self.parent(), |
579 self.trUtf8("Delete forms"), |
606 self.trUtf8("Delete forms"), |
580 self.trUtf8("Do you really want to delete these forms from the project?"), |
607 self.trUtf8( |
|
608 "Do you really want to delete these forms from the project?"), |
581 files) |
609 files) |
582 |
610 |
583 if dlg.exec_() == QDialog.Accepted: |
611 if dlg.exec_() == QDialog.Accepted: |
584 for fn2, fn in zip(fullNames, files): |
612 for fn2, fn in zip(fullNames, files): |
585 self.closeSourceWindow.emit(fn2) |
613 self.closeSourceWindow.emit(fn2) |
586 self.project.deleteFile(fn) |
614 self.project.deleteFile(fn) |
587 |
615 |
588 ############################################################################ |
616 ########################################################################### |
589 ## Methods to handle the various compile commands |
617 ## Methods to handle the various compile commands |
590 ############################################################################ |
618 ########################################################################### |
591 |
619 |
592 def __readStdout(self): |
620 def __readStdout(self): |
593 """ |
621 """ |
594 Private slot to handle the readyReadStandardOutput signal of the |
622 Private slot to handle the readyReadStandardOutput signal of the |
595 pyuic/rbuic process. |
623 pyuic/rbuic process. |
647 E5MessageBox.information(self, |
675 E5MessageBox.information(self, |
648 self.trUtf8("Form Compilation"), |
676 self.trUtf8("Form Compilation"), |
649 self.trUtf8("The compilation of the form file" |
677 self.trUtf8("The compilation of the form file" |
650 " was successful.")) |
678 " was successful.")) |
651 else: |
679 else: |
652 ui.showNotification(UI.PixmapCache.getPixmap("designer48.png"), |
680 ui.showNotification( |
|
681 UI.PixmapCache.getPixmap("designer48.png"), |
653 self.trUtf8("Form Compilation"), |
682 self.trUtf8("Form Compilation"), |
654 self.trUtf8("The compilation of the form file" |
683 self.trUtf8("The compilation of the form file" |
655 " was successful.")) |
684 " was successful.")) |
656 self.project.projectFormCompiled.emit(self.compiledFile) |
685 self.project.projectFormCompiled.emit(self.compiledFile) |
657 except IOError as msg: |
686 except IOError as msg: |
658 if not self.noDialog: |
687 if not self.noDialog: |
659 E5MessageBox.information(self, |
688 E5MessageBox.information(self, |
660 self.trUtf8("Form Compilation"), |
689 self.trUtf8("Form Compilation"), |
661 self.trUtf8("<p>The compilation of the form file failed.</p>" |
690 self.trUtf8( |
|
691 "<p>The compilation of the form file failed.</p>" |
662 "<p>Reason: {0}</p>").format(str(msg))) |
692 "<p>Reason: {0}</p>").format(str(msg))) |
663 else: |
693 else: |
664 ui.showNotification(UI.PixmapCache.getPixmap("designer48.png"), |
694 ui.showNotification( |
|
695 UI.PixmapCache.getPixmap("designer48.png"), |
665 self.trUtf8("Form Compilation"), |
696 self.trUtf8("Form Compilation"), |
666 self.trUtf8("<p>The compilation of the form file failed.</p>" |
697 self.trUtf8( |
|
698 "<p>The compilation of the form file failed.</p>" |
667 "<p>Reason: {0}</p>").format(str(msg))) |
699 "<p>Reason: {0}</p>").format(str(msg))) |
668 else: |
700 else: |
669 if not self.noDialog: |
701 if not self.noDialog: |
670 E5MessageBox.information(self, |
702 E5MessageBox.information(self, |
671 self.trUtf8("Form Compilation"), |
703 self.trUtf8("Form Compilation"), |