Project/ProjectFormsBrowser.py

changeset 6597
dc668f774d3d
parent 6371
bc834bbc0251
child 6645
ad476851d7e0
equal deleted inserted replaced
6596:2d82cd481adc 6597:dc668f774d3d
110 self.tr("QToolBox"), 110 self.tr("QToolBox"),
111 self.tr("QStackedWidget"), 111 self.tr("QStackedWidget"),
112 ] 112 ]
113 113
114 self.compileProc = None 114 self.compileProc = None
115 self.__uicompiler = ""
116
117 self.project.projectClosed.connect(self.__resetUiCompiler)
118 self.project.projectPropertiesChanged.connect(self.__resetUiCompiler)
115 119
116 def _createPopupMenus(self): 120 def _createPopupMenus(self):
117 """ 121 """
118 Protected overloaded method to generate the popup menu. 122 Protected overloaded method to generate the popup menu.
119 """ 123 """
133 self.tr('Compile all forms'), 137 self.tr('Compile all forms'),
134 self.__compileAllForms) 138 self.__compileAllForms)
135 self.menu.addAction( 139 self.menu.addAction(
136 self.tr('Generate Dialog Code...'), 140 self.tr('Generate Dialog Code...'),
137 self.__generateDialogCode) 141 self.__generateDialogCode)
142 self.menu.addSeparator()
143 self.menu.addAction(
144 self.tr('Configure uic Compiler'),
145 self.__configureUicCompiler)
138 self.menu.addSeparator() 146 self.menu.addSeparator()
139 self.menu.addAction( 147 self.menu.addAction(
140 self.tr('Open in Qt-Designer'), self.__openFile) 148 self.tr('Open in Qt-Designer'), self.__openFile)
141 self.menu.addAction( 149 self.menu.addAction(
142 self.tr('Open in Editor'), self.__openFileInEditor) 150 self.tr('Open in Editor'), self.__openFileInEditor)
207 ["Qt4", "PyQt5", "E6Plugin", "PySide", "PySide2"] or \ 215 ["Qt4", "PyQt5", "E6Plugin", "PySide", "PySide2"] or \
208 self.hooks["compileAllForms"] is not None: 216 self.hooks["compileAllForms"] is not None:
209 self.backMenu.addAction( 217 self.backMenu.addAction(
210 self.tr('Compile all forms'), self.__compileAllForms) 218 self.tr('Compile all forms'), self.__compileAllForms)
211 self.backMenu.addSeparator() 219 self.backMenu.addSeparator()
220 self.backMenu.addAction(
221 self.tr('Configure uic Compiler'),
222 self.__configureUicCompiler)
223 self.backMenu.addSeparator()
212 self.backMenu.addAction(self.tr('New form...'), self.__newForm) 224 self.backMenu.addAction(self.tr('New form...'), self.__newForm)
213 else: 225 else:
214 if self.hooks["newForm"] is not None: 226 if self.hooks["newForm"] is not None:
215 self.backMenu.addAction( 227 self.backMenu.addAction(
216 self.hooksMenuEntries.get( 228 self.hooksMenuEntries.get(
230 242
231 # create the menu for multiple selected files 243 # create the menu for multiple selected files
232 self.multiMenu = QMenu(self) 244 self.multiMenu = QMenu(self)
233 if self.project.getProjectType() in \ 245 if self.project.getProjectType() in \
234 ["Qt4", "PyQt5", "E6Plugin", "PySide", "PySide2"]: 246 ["Qt4", "PyQt5", "E6Plugin", "PySide", "PySide2"]:
235 act = self.multiMenu.addAction( 247 self.multiMenu.addAction(
236 self.tr('Compile forms'), self.__compileSelectedForms) 248 self.tr('Compile forms'), self.__compileSelectedForms)
249 self.multiMenu.addSeparator()
250 self.multiMenu.addAction(
251 self.tr('Configure uic Compiler'),
252 self.__configureUicCompiler)
237 self.multiMenu.addSeparator() 253 self.multiMenu.addSeparator()
238 self.multiMenu.addAction( 254 self.multiMenu.addAction(
239 self.tr('Open in Qt-Designer'), self.__openFile) 255 self.tr('Open in Qt-Designer'), self.__openFile)
240 self.multiMenu.addAction( 256 self.multiMenu.addAction(
241 self.tr('Open in Editor'), self.__openFileInEditor) 257 self.tr('Open in Editor'), self.__openFileInEditor)
275 if self.project.getProjectType() in \ 291 if self.project.getProjectType() in \
276 ["Qt4", "PyQt5", "E6Plugin", "PySide", "PySide2"]: 292 ["Qt4", "PyQt5", "E6Plugin", "PySide", "PySide2"]:
277 self.dirMenu.addAction( 293 self.dirMenu.addAction(
278 self.tr('Compile all forms'), self.__compileAllForms) 294 self.tr('Compile all forms'), self.__compileAllForms)
279 self.dirMenu.addSeparator() 295 self.dirMenu.addSeparator()
296 self.dirMenu.addAction(
297 self.tr('Configure uic Compiler'),
298 self.__configureUicCompiler)
299 self.dirMenu.addSeparator()
280 else: 300 else:
281 if self.hooks["compileAllForms"] is not None: 301 if self.hooks["compileAllForms"] is not None:
282 self.dirMenu.addAction( 302 self.dirMenu.addAction(
283 self.hooksMenuEntries.get( 303 self.hooksMenuEntries.get(
284 "compileAllForms", 304 "compileAllForms",
319 self.dirMultiMenu = QMenu(self) 339 self.dirMultiMenu = QMenu(self)
320 if self.project.getProjectType() in \ 340 if self.project.getProjectType() in \
321 ["Qt4", "PyQt5", "E6Plugin", "PySide", "PySide2"]: 341 ["Qt4", "PyQt5", "E6Plugin", "PySide", "PySide2"]:
322 self.dirMultiMenu.addAction( 342 self.dirMultiMenu.addAction(
323 self.tr('Compile all forms'), self.__compileAllForms) 343 self.tr('Compile all forms'), self.__compileAllForms)
344 self.dirMultiMenu.addSeparator()
345 self.dirMultiMenu.addAction(
346 self.tr('Configure uic Compiler'),
347 self.__configureUicCompiler)
324 self.dirMultiMenu.addSeparator() 348 self.dirMultiMenu.addSeparator()
325 else: 349 else:
326 if self.hooks["compileAllForms"] is not None: 350 if self.hooks["compileAllForms"] is not None:
327 self.dirMultiMenu.addAction( 351 self.dirMultiMenu.addAction(
328 self.hooksMenuEntries.get( 352 self.hooksMenuEntries.get(
632 656
633 ########################################################################### 657 ###########################################################################
634 ## Methods to handle the various compile commands 658 ## Methods to handle the various compile commands
635 ########################################################################### 659 ###########################################################################
636 660
661 def __resetUiCompiler(self):
662 """
663 Private slot to reset the determined UI compiler executable.
664 """
665 self.__uicompiler = ""
666
667 def __determineUiCompiler(self):
668 """
669 Private method to determine the UI compiler for the project.
670 """
671 self.__resetUiCompiler()
672
673 if self.project.getProjectLanguage() in \
674 ["Python", "Python2", "Python3"]:
675 if self.project.getProjectType() in ["Qt4", ]:
676 self.__uicompiler = Utilities.generatePyQtToolPath(
677 'pyuic4', ["py3uic4", "py2uic4"])
678 elif self.project.getProjectType() in ["PyQt5"]:
679 self.__uicompiler = Utilities.generatePyQtToolPath(
680 'pyuic5', ["py3uic5", "py2uic5"])
681 elif self.project.getProjectType() in ["E6Plugin"]:
682 if PYQT_VERSION < 0x050000:
683 self.__uicompiler = Utilities.generatePyQtToolPath(
684 'pyuic4', ["py3uic4", "py2uic4"])
685 else:
686 self.__uicompiler = Utilities.generatePyQtToolPath(
687 'pyuic5', ["py3uic5", "py2uic5"])
688 elif self.project.getProjectType() == "PySide":
689 self.__uicompiler = \
690 Utilities.generatePySideToolPath('pyside-uic', "1")
691 elif self.project.getProjectType() == "PySide2":
692 self.__uicompiler = \
693 Utilities.generatePySideToolPath('pyside2-uic', "2")
694 elif self.project.getProjectLanguage() == "Ruby":
695 if self.project.getProjectType() == "Qt4":
696 self.__uicompiler = 'rbuic4'
697 if Utilities.isWindowsPlatform():
698 self.__uicompiler = \
699 Utilities.getWindowsExecutablePath(self.__uicompiler)
700
701 def getUiCompiler(self):
702 """
703 Public method to get the UI compiler executable of the project.
704
705 @return UI compiler executable
706 @rtype str
707 """
708 if not self.__uicompiler:
709 self.__determineUiCompiler()
710
711 return self.__uicompiler
712
637 def __readStdout(self): 713 def __readStdout(self):
638 """ 714 """
639 Private slot to handle the readyReadStandardOutput signal of the 715 Private slot to handle the readyReadStandardOutput signal of the
640 pyuic4/pyuic5/pyside-uic/pyside2-uic/rbuic4 process. 716 pyuic4/pyuic5/pyside-uic/pyside2-uic/rbuic4 process.
641 """ 717 """
657 733
658 ioEncoding = Preferences.getSystem("IOEncoding") 734 ioEncoding = Preferences.getSystem("IOEncoding")
659 735
660 self.compileProc.setReadChannel(QProcess.StandardError) 736 self.compileProc.setReadChannel(QProcess.StandardError)
661 while self.compileProc and self.compileProc.canReadLine(): 737 while self.compileProc and self.compileProc.canReadLine():
662 s = self.uicompiler + ': ' 738 s = self.__uicompiler + ': '
663 error = str(self.compileProc.readLine(), 739 error = str(self.compileProc.readLine(),
664 ioEncoding, 'replace') 740 ioEncoding, 'replace')
665 s += error 741 s += error
666 self.appendStderr.emit(s) 742 self.appendStderr.emit(s)
667 743
740 """ 816 """
741 self.compileProc = QProcess() 817 self.compileProc = QProcess()
742 args = [] 818 args = []
743 self.buf = "" 819 self.buf = ""
744 820
745 if self.project.getProjectLanguage() in \ 821 uicompiler = self.getUiCompiler()
746 ["Python", "Python2", "Python3"]: 822 if not uicompiler:
747 if self.project.getProjectType() in ["Qt4", ]:
748 self.uicompiler = Utilities.generatePyQtToolPath(
749 'pyuic4', ["py3uic4", "py2uic4"])
750 elif self.project.getProjectType() in ["PyQt5"]:
751 self.uicompiler = Utilities.generatePyQtToolPath(
752 'pyuic5', ["py3uic5", "py2uic5"])
753 elif self.project.getProjectType() in ["E6Plugin"]:
754 if PYQT_VERSION < 0x050000:
755 self.uicompiler = Utilities.generatePyQtToolPath(
756 'pyuic4', ["py3uic4", "py2uic4"])
757 else:
758 self.uicompiler = Utilities.generatePyQtToolPath(
759 'pyuic5', ["py3uic5", "py2uic5"])
760 elif self.project.getProjectType() == "PySide":
761 self.uicompiler = \
762 Utilities.generatePySideToolPath('pyside-uic', "1")
763 elif self.project.getProjectType() == "PySide2":
764 self.uicompiler = \
765 Utilities.generatePySideToolPath('pyside2-uic', "2")
766 else:
767 return None
768 elif self.project.getProjectLanguage() == "Ruby":
769 if self.project.getProjectType() == "Qt4":
770 self.uicompiler = 'rbuic4'
771 if Utilities.isWindowsPlatform():
772 self.uicompiler = \
773 Utilities.getWindowsExecutablePath(self.uicompiler)
774 else:
775 return None
776 else:
777 return None 823 return None
778 824
779 ofn, ext = os.path.splitext(fn) 825 ofn, ext = os.path.splitext(fn)
780 fn = os.path.join(self.project.ppath, fn) 826 fn = os.path.join(self.project.ppath, fn)
781 827
785 self.compiledFile = os.path.join(dirname, "Ui_" + filename + ".py") 831 self.compiledFile = os.path.join(dirname, "Ui_" + filename + ".py")
786 args.append("-x") 832 args.append("-x")
787 indentWidth = Preferences.getQt("PyuicIndent") 833 indentWidth = Preferences.getQt("PyuicIndent")
788 if indentWidth != self.PyuicIndentDefault: 834 if indentWidth != self.PyuicIndentDefault:
789 args.append("--indent={0}".format(indentWidth)) 835 args.append("--indent={0}".format(indentWidth))
790 if Preferences.getQt("PyuicFromImports"): 836
791 args.append("--from-imports") 837 if self.project.getProjectType() in ["PySide", "PySide2"]:
838 # PySide and PySide2
839 if Preferences.getQt("PyuicFromImports"):
840 args.append("--from-imports")
841 else:
842 # PyQt4 and PyQt5
843 if 'uic5' in uicompiler and \
844 PYQT_VERSION >= 0x050600 and \
845 self.project.pdata["UICPARAMS"]["Package"]:
846 # only supported for PyQt5 >= 5.6 (April 2016)
847 args.append("--import-from={0}".format(
848 self.project.pdata["UICPARAMS"]["Package"]))
849 elif Preferences.getQt("PyuicFromImports"):
850 args.append("--from-imports")
851 if self.project.pdata["UICPARAMS"]["RcSuffix"]:
852 args.append("--resource-suffix={0}".format(
853 self.project.pdata["UICPARAMS"]["RcSuffix"]))
792 elif self.project.getProjectLanguage() == "Ruby": 854 elif self.project.getProjectLanguage() == "Ruby":
793 self.compiledFile = ofn + '.rb' 855 self.compiledFile = ofn + '.rb'
794 args.append('-x') 856 args.append('-x')
795 857
796 args.append(fn) 858 args.append(fn)
797 self.compileProc.finished.connect(self.__compileUIDone) 859 self.compileProc.finished.connect(self.__compileUIDone)
798 self.compileProc.readyReadStandardOutput.connect(self.__readStdout) 860 self.compileProc.readyReadStandardOutput.connect(self.__readStdout)
799 self.compileProc.readyReadStandardError.connect(self.__readStderr) 861 self.compileProc.readyReadStandardError.connect(self.__readStderr)
800 862
801 self.noDialog = noDialog 863 self.noDialog = noDialog
802 self.compileProc.start(self.uicompiler, args) 864 self.compileProc.start(uicompiler, args)
803 procStarted = self.compileProc.waitForStarted(5000) 865 procStarted = self.compileProc.waitForStarted(5000)
804 if procStarted: 866 if procStarted:
805 self.compileRunning = True 867 self.compileRunning = True
806 e5App().getObject("ViewManager").enableEditorsCheckFocusIn(False) 868 e5App().getObject("ViewManager").enableEditorsCheckFocusIn(False)
807 return self.compileProc 869 return self.compileProc
813 self, 875 self,
814 self.tr('Process Generation Error'), 876 self.tr('Process Generation Error'),
815 self.tr( 877 self.tr(
816 'Could not start {0}.<br>' 878 'Could not start {0}.<br>'
817 'Ensure that it is in the search path.' 879 'Ensure that it is in the search path.'
818 ).format(self.uicompiler)) 880 ).format(uicompiler))
819 return None 881 return None
820 882
821 def __generateDialogCode(self): 883 def __generateDialogCode(self):
822 """ 884 """
823 Private method to generate dialog code for the form (Qt4 only). 885 Private method to generate dialog code for the form (Qt4 only).
994 def handlePreferencesChanged(self): 1056 def handlePreferencesChanged(self):
995 """ 1057 """
996 Public slot used to handle the preferencesChanged signal. 1058 Public slot used to handle the preferencesChanged signal.
997 """ 1059 """
998 ProjectBaseBrowser.handlePreferencesChanged(self) 1060 ProjectBaseBrowser.handlePreferencesChanged(self)
1061
1062 self.__resetUiCompiler()
1063
1064 def __configureUicCompiler(self):
1065 """
1066 Private slot to configure some non-common uic compiler options.
1067 """
1068 from .UicCompilerOptionsDialog import UicCompilerOptionsDialog
1069
1070 params = self.project.pdata["UICPARAMS"]
1071
1072 if self.project.getProjectType() in ["Qt4", "PyQt5", "E6Plugin"]:
1073 dlg = UicCompilerOptionsDialog(params, self.getUiCompiler())
1074 if dlg.exec_() == QDialog.Accepted:
1075 package, suffix = dlg.getData()
1076 if package != params["Package"]:
1077 params["Package"] = package
1078 self.project.setDirty(True)
1079 if suffix != params["RcSuffix"]:
1080 params["RcSuffix"] = suffix
1081 self.project.setDirty(True)
1082 elif self.project.getProjectType() in ["PySide", "PySide2"]:
1083 E5MessageBox.information(
1084 self,
1085 self.tr("Configure uic Compiler"),
1086 self.tr("""No project specific uic compiler flags are"""
1087 """ supported for PySide or PySide2."""))
999 1088
1000 ########################################################################### 1089 ###########################################################################
1001 ## Support for hooks below 1090 ## Support for hooks below
1002 ########################################################################### 1091 ###########################################################################
1003 1092

eric ide

mercurial