diff -r 9986ec0e559a -r 10516539f238 Project/ProjectResourcesBrowser.py --- a/Project/ProjectResourcesBrowser.py Tue Oct 15 22:03:54 2013 +0200 +++ b/Project/ProjectResourcesBrowser.py Fri Oct 18 23:00:41 2013 +0200 @@ -37,12 +37,12 @@ A class used to display the resources part of the project. @signal appendStderr(str) emitted after something was received from - a QProcess on stderr + a QProcess on stderr @signal sourceFile(str) emitted to open a resources file in an editor - @signal closeSourceWindow(str) emitted after a file has been removed/deleted - from the project - @signal showMenu(str, QMenu) emitted when a menu is about to be shown. The name - of the menu and a reference to the menu are given. + @signal closeSourceWindow(str) emitted after a file has been + removed/deleted from the project + @signal showMenu(str, QMenu) emitted when a menu is about to be shown. + The name of the menu and a reference to the menu are given. """ appendStderr = pyqtSignal(str) showMenu = pyqtSignal(str, QMenu) @@ -57,7 +57,8 @@ @param project reference to the project object @param parent parent widget of this browser (QWidget) """ - ProjectBaseBrowser.__init__(self, project, ProjectBrowserResourceType, parent) + ProjectBaseBrowser.__init__(self, project, ProjectBrowserResourceType, + parent) self.selectedItemsFilter = \ [ProjectBrowserFileItem, ProjectBrowserSimpleDirectoryItem] @@ -66,8 +67,9 @@ self.setWhatsThis(self.trUtf8( """<b>Project Resources Browser</b>""" - """<p>This allows to easily see all resources contained in the current""" - """ project. Several actions can be executed via the context menu.</p>""" + """<p>This allows to easily see all resources contained in the""" + """ current project. Several actions can be executed via the""" + """ context menu.</p>""" )) self.compileProc = None @@ -82,7 +84,8 @@ self.dirMultiMenuActions = [] self.menu = QMenu(self) - if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]: + if self.project.getProjectType() in \ + ["Qt4", "PyQt5", "E4Plugin", "PySide"]: self.menu.addAction(self.trUtf8('Compile resource'), self.__compileResource) self.menu.addAction(self.trUtf8('Compile all resources'), @@ -106,19 +109,23 @@ self.menu.addSeparator() act = self.menu.addAction(self.trUtf8('Rename file'), self._renameFile) self.menuActions.append(act) - act = self.menu.addAction(self.trUtf8('Remove from project'), self._removeFile) + act = self.menu.addAction( + self.trUtf8('Remove from project'), self._removeFile) self.menuActions.append(act) act = self.menu.addAction(self.trUtf8('Delete'), self.__deleteFile) self.menuActions.append(act) self.menu.addSeparator() - if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]: - self.menu.addAction(self.trUtf8('New resource...'), self.__newResource) + if self.project.getProjectType() in \ + ["Qt4", "PyQt5", "E4Plugin", "PySide"]: + self.menu.addAction( + self.trUtf8('New resource...'), self.__newResource) else: if self.hooks["newResource"] is not None: self.menu.addAction( self.hooksMenuEntries.get("newResource", self.trUtf8('New resource...')), self.__newResource) - self.menu.addAction(self.trUtf8('Add resources...'), self.__addResourceFiles) + self.menu.addAction( + self.trUtf8('Add resources...'), self.__addResourceFiles) self.menu.addAction(self.trUtf8('Add resources directory...'), self.__addResourcesDirectory) self.menu.addSeparator() @@ -133,11 +140,13 @@ self.menu.addAction(self.trUtf8('Configure...'), self._configure) self.backMenu = QMenu(self) - if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]: + if self.project.getProjectType() in \ + ["Qt4", "PyQt5", "E4Plugin", "PySide"]: self.backMenu.addAction(self.trUtf8('Compile all resources'), self.__compileAllResources) self.backMenu.addSeparator() - self.backMenu.addAction(self.trUtf8('New resource...'), self.__newResource) + self.backMenu.addAction( + self.trUtf8('New resource...'), self.__newResource) else: if self.hooks["compileAllResources"] is not None: self.backMenu.addAction( @@ -164,7 +173,8 @@ # create the menu for multiple selected files self.multiMenu = QMenu(self) - if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]: + if self.project.getProjectType() in \ + ["Qt4", "PyQt5", "E4Plugin", "PySide"]: act = self.multiMenu.addAction(self.trUtf8('Compile resources'), self.__compileSelectedResources) self.multiMenu.addSeparator() @@ -180,7 +190,8 @@ act = self.multiMenu.addAction(self.trUtf8('Remove from project'), self._removeFile) self.multiMenuActions.append(act) - act = self.multiMenu.addAction(self.trUtf8('Delete'), self.__deleteFile) + act = self.multiMenu.addAction( + self.trUtf8('Delete'), self.__deleteFile) self.multiMenuActions.append(act) self.multiMenu.addSeparator() self.multiMenu.addAction(self.trUtf8('Expand all directories'), @@ -191,7 +202,8 @@ self.multiMenu.addAction(self.trUtf8('Configure...'), self._configure) self.dirMenu = QMenu(self) - if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]: + if self.project.getProjectType() in \ + ["Qt4", "PyQt5", "E4Plugin", "PySide"]: self.dirMenu.addAction(self.trUtf8('Compile all resources'), self.__compileAllResources) self.dirMenu.addSeparator() @@ -202,13 +214,17 @@ self.trUtf8('Compile all resources')), self.__compileAllResources) self.dirMenu.addSeparator() - act = self.dirMenu.addAction(self.trUtf8('Remove from project'), self._removeDir) + act = self.dirMenu.addAction( + self.trUtf8('Remove from project'), self._removeDir) self.dirMenuActions.append(act) - act = self.dirMenu.addAction(self.trUtf8('Delete'), self._deleteDirectory) + act = self.dirMenu.addAction( + self.trUtf8('Delete'), self._deleteDirectory) self.dirMenuActions.append(act) self.dirMenu.addSeparator() - self.dirMenu.addAction(self.trUtf8('New resource...'), self.__newResource) - self.dirMenu.addAction(self.trUtf8('Add resources...'), self.__addResourceFiles) + self.dirMenu.addAction( + self.trUtf8('New resource...'), self.__newResource) + self.dirMenu.addAction( + self.trUtf8('Add resources...'), self.__addResourceFiles) self.dirMenu.addAction(self.trUtf8('Add resources directory...'), self.__addResourcesDirectory) self.dirMenu.addSeparator() @@ -223,7 +239,8 @@ self.dirMenu.addAction(self.trUtf8('Configure...'), self._configure) self.dirMultiMenu = QMenu(self) - if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]: + if self.project.getProjectType() in \ + ["Qt4", "PyQt5", "E4Plugin", "PySide"]: self.dirMultiMenu.addAction(self.trUtf8('Compile all resources'), self.__compileAllResources) self.dirMultiMenu.addSeparator() @@ -244,7 +261,8 @@ self.dirMultiMenu.addAction(self.trUtf8('Collapse all directories'), self._collapseAllDirs) self.dirMultiMenu.addSeparator() - self.dirMultiMenu.addAction(self.trUtf8('Configure...'), self._configure) + self.dirMultiMenu.addAction( + self.trUtf8('Configure...'), self._configure) self.menu.aboutToShow.connect(self.__showContextMenu) self.multiMenu.aboutToShow.connect(self.__showContextMenuMulti) @@ -271,7 +289,8 @@ if index.isValid(): self._selectSingleItem(index) categories = self.getSelectedItemsCountCategorized( - [ProjectBrowserFileItem, ProjectBrowserSimpleDirectoryItem]) + [ProjectBrowserFileItem, + ProjectBrowserSimpleDirectoryItem]) cnt = categories["sum"] bfcnt = categories[str(ProjectBrowserFileItem)] @@ -460,10 +479,13 @@ fn = self.project.getRelativePath(fn2) files.append(fn) - from UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog + from UI.DeleteFilesConfirmationDialog import \ + DeleteFilesConfirmationDialog dlg = DeleteFilesConfirmationDialog(self.parent(), self.trUtf8("Delete resources"), - self.trUtf8("Do you really want to delete these resources from the project?"), + self.trUtf8( + "Do you really want to delete these resources from the" + " project?"), files) if dlg.exec_() == QDialog.Accepted: @@ -471,9 +493,9 @@ self.closeSourceWindow.emit(fn2) self.project.deleteFile(fn) - ############################################################################ + ########################################################################### ## Methods to handle the various compile commands - ############################################################################ + ########################################################################### def __readStdout(self): """ @@ -545,17 +567,21 @@ if not self.noDialog: E5MessageBox.information(self, self.trUtf8("Resource Compilation"), - self.trUtf8("<p>The compilation of the resource file failed.</p>" - "<p>Reason: {0}</p>").format(str(msg))) + self.trUtf8( + "<p>The compilation of the resource file" + " failed.</p><p>Reason: {0}</p>").format(str(msg))) else: if not self.noDialog: E5MessageBox.information(self, self.trUtf8("Resource Compilation"), - self.trUtf8("The compilation of the resource file failed.")) + self.trUtf8( + "The compilation of the resource file failed.")) else: - ui.showNotification(UI.PixmapCache.getPixmap("resourcesCompiler48.png"), + ui.showNotification( + UI.PixmapCache.getPixmap("resourcesCompiler48.png"), self.trUtf8("Resource Compilation"), - self.trUtf8("The compilation of the resource file failed.")) + self.trUtf8( + "The compilation of the resource file failed.")) self.compileProc = None def __compileQRC(self, fn, noDialog=False, progress=None): @@ -571,13 +597,15 @@ args = [] self.buf = "" - if self.project.pdata["PROGLANGUAGE"][0] in ["Python", "Python2", "Python3"]: + if self.project.pdata["PROGLANGUAGE"][0] in \ + ["Python", "Python2", "Python3"]: if self.project.getProjectType() in ["Qt4", "E4Plugin"]: self.rccCompiler = 'pyrcc4' if Utilities.isWindowsPlatform(): self.rccCompiler += '.exe' if PYQT_VERSION >= 0x040500: - if self.project.pdata["PROGLANGUAGE"][0] in ["Python", "Python2"]: + if self.project.pdata["PROGLANGUAGE"][0] in \ + ["Python", "Python2"]: args.append("-py2") else: args.append("-py3") @@ -586,8 +614,10 @@ if Utilities.isWindowsPlatform(): self.rccCompiler += '.exe' elif self.project.getProjectType() == "PySide": - self.rccCompiler = Utilities.generatePySideToolPath('pyside-rcc') - if self.project.pdata["PROGLANGUAGE"][0] in ["Python", "Python2"]: + self.rccCompiler = Utilities.generatePySideToolPath( + 'pyside-rcc') + if self.project.pdata["PROGLANGUAGE"][0] in \ + ["Python", "Python2"]: args.append("-py2") else: args.append("-py3") @@ -609,12 +639,13 @@ fn = os.path.join(self.project.ppath, fn) dirname, filename = os.path.split(ofn) - if self.project.pdata["PROGLANGUAGE"][0] in ["Python", "Python2", "Python3"]: - self.compiledFile = os.path.join(dirname, - self.RCFilenameFormatPython.format(filename)) + if self.project.pdata["PROGLANGUAGE"][0] in \ + ["Python", "Python2", "Python3"]: + self.compiledFile = os.path.join( + dirname, self.RCFilenameFormatPython.format(filename)) elif self.project.pdata["PROGLANGUAGE"][0] == "Ruby": self.compiledFile = os.path.join( - dirname, self.RCFilenameFormatRuby.format(filename)) + dirname, self.RCFilenameFormatRuby.format(filename)) args.append(fn) self.compileProc.finished.connect(self.__compileQRCDone) @@ -737,7 +768,8 @@ lbuf = "" for line in buf.splitlines(): line = line.strip() - if line.lower().startswith("<file>") or line.lower().startswith("<file "): + if line.lower().startswith("<file>") or \ + line.lower().startswith("<file "): lbuf = line elif lbuf: lbuf = "{0}{1}".format(lbuf, line) @@ -758,9 +790,11 @@ Public method to compile all changed resources to source files. """ if self.hooks["compileChangedResources"] is not None: - self.hooks["compileChangedResources"](self.project.pdata["RESOURCES"]) + self.hooks["compileChangedResources"]( + self.project.pdata["RESOURCES"]) else: - progress = QProgressDialog(self.trUtf8("Determining changed resources..."), + progress = QProgressDialog( + self.trUtf8("Determining changed resources..."), None, 0, 100) progress.setMinimumDuration(0) i = 0 @@ -775,12 +809,12 @@ if self.project.pdata["PROGLANGUAGE"][0] in \ ["Python", "Python2", "Python3"]: dirname, filename = os.path.split(os.path.splitext(ifn)[0]) - ofn = os.path.join(dirname, - self.RCFilenameFormatPython.format(filename)) + ofn = os.path.join( + dirname, self.RCFilenameFormatPython.format(filename)) elif self.project.pdata["PROGLANGUAGE"][0] == "Ruby": dirname, filename = os.path.split(os.path.splitext(ifn)[0]) - ofn = os.path.join(dirname, - self.RCFilenameFormatRuby.format(filename)) + ofn = os.path.join( + dirname, self.RCFilenameFormatRuby.format(filename)) else: return if not os.path.exists(ofn) or \ @@ -793,7 +827,8 @@ QApplication.processEvents() if changedResources: - progress.setLabelText(self.trUtf8("Compiling changed resources...")) + progress.setLabelText( + self.trUtf8("Compiling changed resources...")) progress.setMaximum(len(changedResources)) i = 0 progress.setValue(i) @@ -818,9 +853,9 @@ """ ProjectBaseBrowser.handlePreferencesChanged(self) - ############################################################################ + ########################################################################### ## Support for hooks below - ############################################################################ + ########################################################################### def _initHookMethods(self): """ @@ -831,8 +866,10 @@ <li>compileResource: takes filename as parameter</li> <li>compileAllResources: takes list of filenames as parameter</li> <li>compileChangedResources: takes list of filenames as parameter</li> - <li>compileSelectedResources: takes list of all form filenames as parameter</li> - <li>newResource: takes full directory path of new file as parameter</li> + <li>compileSelectedResources: takes list of all form filenames as + parameter</li> + <li>newResource: takes full directory path of new file as + parameter</li> </ul> <b>Note</b>: Filenames are relative to the project directory, if not