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