eric6/Project/ProjectFormsBrowser.py

changeset 7635
0cdead130a81
parent 7628
f904d0eef264
child 7759
51aa6c6b66f7
equal deleted inserted replaced
7634:8c3d033e5044 7635:0cdead130a81
72 """<p>This allows to easily see all forms contained in the""" 72 """<p>This allows to easily see all forms contained in the"""
73 """ current project. Several actions can be executed via the""" 73 """ current project. Several actions can be executed via the"""
74 """ context menu.</p>""" 74 """ context menu.</p>"""
75 )) 75 ))
76 76
77 # templates for Qt4 77 # templates for Qt
78 # these two lists have to stay in sync 78 # these two lists have to stay in sync
79 self.templates4 = [ 79 self.templates4 = [
80 'dialog4.tmpl', 'widget4.tmpl', 'mainwindow4.tmpl', 80 'dialog4.tmpl', 'widget4.tmpl', 'mainwindow4.tmpl',
81 'dialogbuttonboxbottom4.tmpl', 'dialogbuttonboxright4.tmpl', 81 'dialogbuttonboxbottom4.tmpl', 'dialogbuttonboxright4.tmpl',
82 'dialogbuttonsbottom4.tmpl', 'dialogbuttonsbottomcenter4.tmpl', 82 'dialogbuttonsbottom4.tmpl', 'dialogbuttonsbottomcenter4.tmpl',
123 self.dirMultiMenuActions = [] 123 self.dirMultiMenuActions = []
124 124
125 self.menusAboutToBeCreated.emit() 125 self.menusAboutToBeCreated.emit()
126 126
127 self.menu = QMenu(self) 127 self.menu = QMenu(self)
128 if self.project.getProjectType() in [ 128 if self.project.getProjectType() in ["PyQt5", "E6Plugin", "PySide2"]:
129 "Qt4", "PyQt5", "E6Plugin", "PySide", "PySide2"
130 ]:
131 self.menu.addAction( 129 self.menu.addAction(
132 self.tr('Compile form'), self.__compileForm) 130 self.tr('Compile form'), self.__compileForm)
133 self.menu.addAction( 131 self.menu.addAction(
134 self.tr('Compile all forms'), 132 self.tr('Compile all forms'),
135 self.__compileAllForms) 133 self.__compileAllForms)
185 self.tr('Remove from project'), self._removeFile) 183 self.tr('Remove from project'), self._removeFile)
186 self.menuActions.append(act) 184 self.menuActions.append(act)
187 act = self.menu.addAction(self.tr('Delete'), self.__deleteFile) 185 act = self.menu.addAction(self.tr('Delete'), self.__deleteFile)
188 self.menuActions.append(act) 186 self.menuActions.append(act)
189 self.menu.addSeparator() 187 self.menu.addSeparator()
190 if self.project.getProjectType() in [ 188 if self.project.getProjectType() in ["PyQt5", "E6Plugin", "PySide2"]:
191 "Qt4", "PyQt5", "E6Plugin", "PySide", "PySide2"
192 ]:
193 self.menu.addAction(self.tr('New form...'), self.__newForm) 189 self.menu.addAction(self.tr('New form...'), self.__newForm)
194 else: 190 else:
195 if self.hooks["newForm"] is not None: 191 if self.hooks["newForm"] is not None:
196 self.menu.addAction( 192 self.menu.addAction(
197 self.hooksMenuEntries.get( 193 self.hooksMenuEntries.get(
211 self.menu.addAction(self.tr('Configure...'), self._configure) 207 self.menu.addAction(self.tr('Configure...'), self._configure)
212 208
213 self.backMenu = QMenu(self) 209 self.backMenu = QMenu(self)
214 if ( 210 if (
215 self.project.getProjectType() in [ 211 self.project.getProjectType() in [
216 "Qt4", "PyQt5", "E6Plugin", "PySide", "PySide2" 212 "PyQt5", "E6Plugin", "PySide2"
217 ] or 213 ] or
218 self.hooks["compileAllForms"] is not None 214 self.hooks["compileAllForms"] is not None
219 ): 215 ):
220 self.backMenu.addAction( 216 self.backMenu.addAction(
221 self.tr('Compile all forms'), self.__compileAllForms) 217 self.tr('Compile all forms'), self.__compileAllForms)
243 self.backMenu.addAction(self.tr('Configure...'), self._configure) 239 self.backMenu.addAction(self.tr('Configure...'), self._configure)
244 self.backMenu.setEnabled(False) 240 self.backMenu.setEnabled(False)
245 241
246 # create the menu for multiple selected files 242 # create the menu for multiple selected files
247 self.multiMenu = QMenu(self) 243 self.multiMenu = QMenu(self)
248 if self.project.getProjectType() in [ 244 if self.project.getProjectType() in ["PyQt5", "E6Plugin", "PySide2"]:
249 "Qt4", "PyQt5", "E6Plugin", "PySide", "PySide2"
250 ]:
251 self.multiMenu.addAction( 245 self.multiMenu.addAction(
252 self.tr('Compile forms'), self.__compileSelectedForms) 246 self.tr('Compile forms'), self.__compileSelectedForms)
253 self.multiMenu.addSeparator() 247 self.multiMenu.addSeparator()
254 self.__pyuicMultiConfigAct = self.multiMenu.addAction( 248 self.__pyuicMultiConfigAct = self.multiMenu.addAction(
255 self.tr('Configure uic Compiler'), 249 self.tr('Configure uic Compiler'),
290 self.tr('Collapse all directories'), self._collapseAllDirs) 284 self.tr('Collapse all directories'), self._collapseAllDirs)
291 self.multiMenu.addSeparator() 285 self.multiMenu.addSeparator()
292 self.multiMenu.addAction(self.tr('Configure...'), self._configure) 286 self.multiMenu.addAction(self.tr('Configure...'), self._configure)
293 287
294 self.dirMenu = QMenu(self) 288 self.dirMenu = QMenu(self)
295 if self.project.getProjectType() in [ 289 if self.project.getProjectType() in ["PyQt5", "E6Plugin", "PySide2"]:
296 "Qt4", "PyQt5", "E6Plugin", "PySide", "PySide2"
297 ]:
298 self.dirMenu.addAction( 290 self.dirMenu.addAction(
299 self.tr('Compile all forms'), self.__compileAllForms) 291 self.tr('Compile all forms'), self.__compileAllForms)
300 self.dirMenu.addSeparator() 292 self.dirMenu.addSeparator()
301 self.__pyuicDirConfigAct = self.dirMenu.addAction( 293 self.__pyuicDirConfigAct = self.dirMenu.addAction(
302 self.tr('Configure uic Compiler'), 294 self.tr('Configure uic Compiler'),
315 self.dirMenuActions.append(act) 307 self.dirMenuActions.append(act)
316 act = self.dirMenu.addAction( 308 act = self.dirMenu.addAction(
317 self.tr('Delete'), self._deleteDirectory) 309 self.tr('Delete'), self._deleteDirectory)
318 self.dirMenuActions.append(act) 310 self.dirMenuActions.append(act)
319 self.dirMenu.addSeparator() 311 self.dirMenu.addSeparator()
320 if self.project.getProjectType() in [ 312 if self.project.getProjectType() in ["PyQt5", "E6Plugin", "PySide2"]:
321 "Qt4", "PyQt5", "E6Plugin", "PySide", "PySide2"
322 ]:
323 self.dirMenu.addAction(self.tr('New form...'), self.__newForm) 313 self.dirMenu.addAction(self.tr('New form...'), self.__newForm)
324 else: 314 else:
325 if self.hooks["newForm"] is not None: 315 if self.hooks["newForm"] is not None:
326 self.dirMenu.addAction( 316 self.dirMenu.addAction(
327 self.hooksMenuEntries.get( 317 self.hooksMenuEntries.get(
341 self.tr('Collapse all directories'), self._collapseAllDirs) 331 self.tr('Collapse all directories'), self._collapseAllDirs)
342 self.dirMenu.addSeparator() 332 self.dirMenu.addSeparator()
343 self.dirMenu.addAction(self.tr('Configure...'), self._configure) 333 self.dirMenu.addAction(self.tr('Configure...'), self._configure)
344 334
345 self.dirMultiMenu = QMenu(self) 335 self.dirMultiMenu = QMenu(self)
346 if self.project.getProjectType() in [ 336 if self.project.getProjectType() in ["PyQt5", "E6Plugin", "PySide2"]:
347 "Qt4", "PyQt5", "E6Plugin", "PySide", "PySide2"
348 ]:
349 self.dirMultiMenu.addAction( 337 self.dirMultiMenu.addAction(
350 self.tr('Compile all forms'), self.__compileAllForms) 338 self.tr('Compile all forms'), self.__compileAllForms)
351 self.dirMultiMenu.addSeparator() 339 self.dirMultiMenu.addSeparator()
352 self.__pyuicDirMultiConfigAct = self.dirMultiMenu.addAction( 340 self.__pyuicDirMultiConfigAct = self.dirMultiMenu.addAction(
353 self.tr('Configure uic Compiler'), 341 self.tr('Configure uic Compiler'),
388 @param coord the position of the mouse pointer (QPoint) 376 @param coord the position of the mouse pointer (QPoint)
389 """ 377 """
390 if not self.project.isOpen(): 378 if not self.project.isOpen():
391 return 379 return
392 380
393 enable = self.project.getProjectType() in ("Qt4", "PyQt5", "E6Plugin") 381 enable = self.project.getProjectType() in ("PyQt5", "E6Plugin")
394 self.__pyuicConfigAct.setEnabled(enable) 382 self.__pyuicConfigAct.setEnabled(enable)
395 self.__pyuicMultiConfigAct.setEnabled(enable) 383 self.__pyuicMultiConfigAct.setEnabled(enable)
396 self.__pyuicDirConfigAct.setEnabled(enable) 384 self.__pyuicDirConfigAct.setEnabled(enable)
397 self.__pyuicDirMultiConfigAct.setEnabled(enable) 385 self.__pyuicDirMultiConfigAct.setEnabled(enable)
398 self.__pyuicBackConfigAct.setEnabled(enable) 386 self.__pyuicBackConfigAct.setEnabled(enable)
576 564
577 if self.hooks["newForm"] is not None: 565 if self.hooks["newForm"] is not None:
578 self.hooks["newForm"](path) 566 self.hooks["newForm"](path)
579 else: 567 else:
580 if self.project.getProjectType() in [ 568 if self.project.getProjectType() in [
581 "Qt4", "PyQt5", "E6Plugin", "PySide", "PySide2" 569 "PyQt5", "E6Plugin", "PySide2"
582 ]: 570 ]:
583 self.__newUiForm(path) 571 self.__newUiForm(path)
584 572
585 def __newUiForm(self, path): 573 def __newUiForm(self, path):
586 """ 574 """
688 """ 676 """
689 Private method to determine the UI compiler for the project. 677 Private method to determine the UI compiler for the project.
690 """ 678 """
691 self.__resetUiCompiler() 679 self.__resetUiCompiler()
692 680
693 if self.project.getProjectLanguage() in [ 681 if self.project.getProjectLanguage() == "Python3":
694 "Python", "Python2", "Python3" 682 if self.project.getProjectType() in ["PyQt5"]:
695 ]:
696 if self.project.getProjectType() in ["Qt4", ]:
697 self.__uicompiler = Utilities.generatePyQtToolPath(
698 'pyuic4', ["py3uic4"])
699 elif self.project.getProjectType() in ["PyQt5"]:
700 self.__uicompiler = Utilities.generatePyQtToolPath( 683 self.__uicompiler = Utilities.generatePyQtToolPath(
701 'pyuic5', ["py3uic5"]) 684 'pyuic5', ["py3uic5"])
702 elif self.project.getProjectType() in ["E6Plugin"]: 685 elif self.project.getProjectType() in ["E6Plugin"]:
703 self.__uicompiler = Utilities.generatePyQtToolPath( 686 self.__uicompiler = Utilities.generatePyQtToolPath(
704 'pyuic5', ["py3uic5"]) 687 'pyuic5', ["py3uic5"])
705 elif self.project.getProjectType() == "PySide":
706 self.__uicompiler = Utilities.generatePySideToolPath(
707 'pyside-uic', "1")
708 elif self.project.getProjectType() == "PySide2": 688 elif self.project.getProjectType() == "PySide2":
709 self.__uicompiler = Utilities.generatePySideToolPath( 689 self.__uicompiler = Utilities.generatePySideToolPath(
710 'pyside2-uic', "2") 690 'pyside2-uic')
711 elif self.project.getProjectLanguage() == "Ruby":
712 if self.project.getProjectType() == "Qt4":
713 self.__uicompiler = 'rbuic4'
714 if Utilities.isWindowsPlatform():
715 self.__uicompiler = Utilities.getWindowsExecutablePath(
716 self.__uicompiler)
717 691
718 def getUiCompiler(self): 692 def getUiCompiler(self):
719 """ 693 """
720 Public method to get the UI compiler executable of the project. 694 Public method to get the UI compiler executable of the project.
721 695
728 return self.__uicompiler 702 return self.__uicompiler
729 703
730 def __readStdout(self): 704 def __readStdout(self):
731 """ 705 """
732 Private slot to handle the readyReadStandardOutput signal of the 706 Private slot to handle the readyReadStandardOutput signal of the
733 pyuic4/pyuic5/pyside-uic/pyside2-uic/rbuic4 process. 707 pyuic5/pyside2-uic process.
734 """ 708 """
735 if self.compileProc is None: 709 if self.compileProc is None:
736 return 710 return
737 self.compileProc.setReadChannel(QProcess.StandardOutput) 711 self.compileProc.setReadChannel(QProcess.StandardOutput)
738 712
741 "utf-8", 'replace') 715 "utf-8", 'replace')
742 716
743 def __readStderr(self): 717 def __readStderr(self):
744 """ 718 """
745 Private slot to handle the readyReadStandardError signal of the 719 Private slot to handle the readyReadStandardError signal of the
746 pyuic4/pyuic5/pyside-uic/pyside2-uic/rbuic4 process. 720 pyuic5/pyside2-uic process.
747 """ 721 """
748 if self.compileProc is None: 722 if self.compileProc is None:
749 return 723 return
750 724
751 ioEncoding = Preferences.getSystem("IOEncoding") 725 ioEncoding = Preferences.getSystem("IOEncoding")
840 return None 814 return None
841 815
842 ofn, ext = os.path.splitext(fn) 816 ofn, ext = os.path.splitext(fn)
843 fn = os.path.join(self.project.ppath, fn) 817 fn = os.path.join(self.project.ppath, fn)
844 818
845 if self.project.getProjectLanguage() in [ 819 if self.project.getProjectLanguage() == "Python3":
846 "Python", "Python2", "Python3"
847 ]:
848 dirname, filename = os.path.split(ofn) 820 dirname, filename = os.path.split(ofn)
849 self.compiledFile = os.path.join(dirname, "Ui_" + filename + ".py") 821 self.compiledFile = os.path.join(dirname, "Ui_" + filename + ".py")
850 822
851 if self.project.getProjectType() in ["PySide", "PySide2"]: 823 if self.project.getProjectType() == "PySide2":
852 # PySide and PySide2 824 # PySide2
853 if Preferences.getQt("PySide2FromImports"): 825 if Preferences.getQt("PySide2FromImports"):
854 args.append("--from-imports") 826 args.append("--from-imports")
855 else: 827 else:
856 # PyQt4 and PyQt5 828 # PyQt5
857 if Preferences.getQt("PyuicExecute"): 829 if Preferences.getQt("PyuicExecute"):
858 args.append("-x") 830 args.append("-x")
859 indentWidth = Preferences.getQt("PyuicIndent") 831 indentWidth = Preferences.getQt("PyuicIndent")
860 if indentWidth != self.PyuicIndentDefault: 832 if indentWidth != self.PyuicIndentDefault:
861 args.append("--indent={0}".format(indentWidth)) 833 args.append("--indent={0}".format(indentWidth))
900 ).format(uicompiler)) 872 ).format(uicompiler))
901 return None 873 return None
902 874
903 def __generateDialogCode(self): 875 def __generateDialogCode(self):
904 """ 876 """
905 Private method to generate dialog code for the form (Qt4 only). 877 Private method to generate dialog code for the form (Qt only).
906 """ 878 """
907 itm = self.model().item(self.currentIndex()) 879 itm = self.model().item(self.currentIndex())
908 fn = itm.fileName() 880 fn = itm.fileName()
909 881
910 if self.hooks["generateDialogCode"] is not None: 882 if self.hooks["generateDialogCode"] is not None:
1015 """ 987 """
1016 if self.hooks["compileChangedForms"] is not None: 988 if self.hooks["compileChangedForms"] is not None:
1017 self.hooks["compileChangedForms"](self.project.pdata["FORMS"]) 989 self.hooks["compileChangedForms"](self.project.pdata["FORMS"])
1018 else: 990 else:
1019 if self.project.getProjectType() not in [ 991 if self.project.getProjectType() not in [
1020 "Qt4", "PyQt5", "E6Plugin", "PySide", "PySide2" 992 "PyQt5", "E6Plugin", "PySide2"
1021 ]: 993 ]:
1022 # ignore the request for non Qt GUI projects 994 # ignore the request for non Qt GUI projects
1023 return 995 return
1024 996
1025 progress = E5ProgressDialog( 997 progress = E5ProgressDialog(
1035 for fn in self.project.pdata["FORMS"]: 1007 for fn in self.project.pdata["FORMS"]:
1036 progress.setValue(i) 1008 progress.setValue(i)
1037 QApplication.processEvents() 1009 QApplication.processEvents()
1038 1010
1039 ifn = os.path.join(self.project.ppath, fn) 1011 ifn = os.path.join(self.project.ppath, fn)
1040 if self.project.getProjectLanguage() in [ 1012 if self.project.getProjectLanguage() == "Python3":
1041 "Python", "Python2", "Python3"
1042 ]:
1043 dirname, filename = os.path.split(os.path.splitext(ifn)[0]) 1013 dirname, filename = os.path.split(os.path.splitext(ifn)[0])
1044 ofn = os.path.join(dirname, "Ui_" + filename + ".py") 1014 ofn = os.path.join(dirname, "Ui_" + filename + ".py")
1045 elif self.project.getProjectLanguage() == "Ruby": 1015 elif self.project.getProjectLanguage() == "Ruby":
1046 ofn = os.path.splitext(ifn)[0] + '.rb' 1016 ofn = os.path.splitext(ifn)[0] + '.rb'
1047 if ( 1017 if (
1091 """ 1061 """
1092 from .UicCompilerOptionsDialog import UicCompilerOptionsDialog 1062 from .UicCompilerOptionsDialog import UicCompilerOptionsDialog
1093 1063
1094 params = self.project.pdata["UICPARAMS"] 1064 params = self.project.pdata["UICPARAMS"]
1095 1065
1096 if self.project.getProjectType() in ["Qt4", "PyQt5", "E6Plugin"]: 1066 if self.project.getProjectType() in ["PyQt5", "E6Plugin"]:
1097 dlg = UicCompilerOptionsDialog(params, self.getUiCompiler()) 1067 dlg = UicCompilerOptionsDialog(params, self.getUiCompiler())
1098 if dlg.exec_() == QDialog.Accepted: 1068 if dlg.exec_() == QDialog.Accepted:
1099 package, suffix, root = dlg.getData() 1069 package, suffix, root = dlg.getData()
1100 if package != params["Package"]: 1070 if package != params["Package"]:
1101 params["Package"] = package 1071 params["Package"] = package

eric ide

mercurial