Project/ProjectResourcesBrowser.py

changeset 2995
63d874899b8b
parent 2771
281c9b30dd91
child 3020
542e97d4ecb3
child 3057
10516539f238
equal deleted inserted replaced
2994:5ae1349b8fb4 2995:63d874899b8b
29 class ProjectResourcesBrowser(ProjectBaseBrowser): 29 class ProjectResourcesBrowser(ProjectBaseBrowser):
30 """ 30 """
31 A class used to display the resources part of the project. 31 A class used to display the resources part of the project.
32 32
33 @signal appendStderr(str) emitted after something was received from 33 @signal appendStderr(str) emitted after something was received from
34 a QProcess on stderr 34 a QProcess on stderr
35 @signal sourceFile(str) emitted to open a resources file in an editor 35 @signal sourceFile(str) emitted to open a resources file in an editor
36 @signal closeSourceWindow(str) emitted after a file has been removed/deleted 36 @signal closeSourceWindow(str) emitted after a file has been
37 from the project 37 removed/deleted from the project
38 @signal showMenu(str, QMenu) emitted when a menu is about to be shown. The name 38 @signal showMenu(str, QMenu) emitted when a menu is about to be shown.
39 of the menu and a reference to the menu are given. 39 The name of the menu and a reference to the menu are given.
40 """ 40 """
41 appendStderr = pyqtSignal(str) 41 appendStderr = pyqtSignal(str)
42 showMenu = pyqtSignal(str, QMenu) 42 showMenu = pyqtSignal(str, QMenu)
43 43
44 RCFilenameFormatPython = "{0}_rc.py" 44 RCFilenameFormatPython = "{0}_rc.py"
49 Constructor 49 Constructor
50 50
51 @param project reference to the project object 51 @param project reference to the project object
52 @param parent parent widget of this browser (QWidget) 52 @param parent parent widget of this browser (QWidget)
53 """ 53 """
54 ProjectBaseBrowser.__init__(self, project, ProjectBrowserResourceType, parent) 54 ProjectBaseBrowser.__init__(self, project, ProjectBrowserResourceType,
55 parent)
55 56
56 self.selectedItemsFilter = \ 57 self.selectedItemsFilter = \
57 [ProjectBrowserFileItem, ProjectBrowserSimpleDirectoryItem] 58 [ProjectBrowserFileItem, ProjectBrowserSimpleDirectoryItem]
58 59
59 self.setWindowTitle(self.trUtf8('Resources')) 60 self.setWindowTitle(self.trUtf8('Resources'))
60 61
61 self.setWhatsThis(self.trUtf8( 62 self.setWhatsThis(self.trUtf8(
62 """<b>Project Resources Browser</b>""" 63 """<b>Project Resources Browser</b>"""
63 """<p>This allows to easily see all resources contained in the current""" 64 """<p>This allows to easily see all resources contained in the"""
64 """ project. Several actions can be executed via the context menu.</p>""" 65 """ current project. Several actions can be executed via the"""
66 """ context menu.</p>"""
65 )) 67 ))
66 68
67 self.compileProc = None 69 self.compileProc = None
68 70
69 def _createPopupMenus(self): 71 def _createPopupMenus(self):
74 self.multiMenuActions = [] 76 self.multiMenuActions = []
75 self.dirMenuActions = [] 77 self.dirMenuActions = []
76 self.dirMultiMenuActions = [] 78 self.dirMultiMenuActions = []
77 79
78 self.menu = QMenu(self) 80 self.menu = QMenu(self)
79 if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]: 81 if self.project.getProjectType() in \
82 ["Qt4", "PyQt5", "E4Plugin", "PySide"]:
80 self.menu.addAction(self.trUtf8('Compile resource'), 83 self.menu.addAction(self.trUtf8('Compile resource'),
81 self.__compileResource) 84 self.__compileResource)
82 self.menu.addAction(self.trUtf8('Compile all resources'), 85 self.menu.addAction(self.trUtf8('Compile all resources'),
83 self.__compileAllResources) 86 self.__compileAllResources)
84 self.menu.addSeparator() 87 self.menu.addSeparator()
98 self.menu.addSeparator() 101 self.menu.addSeparator()
99 self.menu.addAction(self.trUtf8('Open'), self.__openFile) 102 self.menu.addAction(self.trUtf8('Open'), self.__openFile)
100 self.menu.addSeparator() 103 self.menu.addSeparator()
101 act = self.menu.addAction(self.trUtf8('Rename file'), self._renameFile) 104 act = self.menu.addAction(self.trUtf8('Rename file'), self._renameFile)
102 self.menuActions.append(act) 105 self.menuActions.append(act)
103 act = self.menu.addAction(self.trUtf8('Remove from project'), self._removeFile) 106 act = self.menu.addAction(
107 self.trUtf8('Remove from project'), self._removeFile)
104 self.menuActions.append(act) 108 self.menuActions.append(act)
105 act = self.menu.addAction(self.trUtf8('Delete'), self.__deleteFile) 109 act = self.menu.addAction(self.trUtf8('Delete'), self.__deleteFile)
106 self.menuActions.append(act) 110 self.menuActions.append(act)
107 self.menu.addSeparator() 111 self.menu.addSeparator()
108 if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]: 112 if self.project.getProjectType() in \
109 self.menu.addAction(self.trUtf8('New resource...'), self.__newResource) 113 ["Qt4", "PyQt5", "E4Plugin", "PySide"]:
114 self.menu.addAction(
115 self.trUtf8('New resource...'), self.__newResource)
110 else: 116 else:
111 if self.hooks["newResource"] is not None: 117 if self.hooks["newResource"] is not None:
112 self.menu.addAction( 118 self.menu.addAction(
113 self.hooksMenuEntries.get("newResource", 119 self.hooksMenuEntries.get("newResource",
114 self.trUtf8('New resource...')), self.__newResource) 120 self.trUtf8('New resource...')), self.__newResource)
115 self.menu.addAction(self.trUtf8('Add resources...'), self.__addResourceFiles) 121 self.menu.addAction(
122 self.trUtf8('Add resources...'), self.__addResourceFiles)
116 self.menu.addAction(self.trUtf8('Add resources directory...'), 123 self.menu.addAction(self.trUtf8('Add resources directory...'),
117 self.__addResourcesDirectory) 124 self.__addResourcesDirectory)
118 self.menu.addSeparator() 125 self.menu.addSeparator()
119 self.menu.addAction(self.trUtf8('Copy Path to Clipboard'), 126 self.menu.addAction(self.trUtf8('Copy Path to Clipboard'),
120 self._copyToClipboard) 127 self._copyToClipboard)
125 self._collapseAllDirs) 132 self._collapseAllDirs)
126 self.menu.addSeparator() 133 self.menu.addSeparator()
127 self.menu.addAction(self.trUtf8('Configure...'), self._configure) 134 self.menu.addAction(self.trUtf8('Configure...'), self._configure)
128 135
129 self.backMenu = QMenu(self) 136 self.backMenu = QMenu(self)
130 if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]: 137 if self.project.getProjectType() in \
138 ["Qt4", "PyQt5", "E4Plugin", "PySide"]:
131 self.backMenu.addAction(self.trUtf8('Compile all resources'), 139 self.backMenu.addAction(self.trUtf8('Compile all resources'),
132 self.__compileAllResources) 140 self.__compileAllResources)
133 self.backMenu.addSeparator() 141 self.backMenu.addSeparator()
134 self.backMenu.addAction(self.trUtf8('New resource...'), self.__newResource) 142 self.backMenu.addAction(
143 self.trUtf8('New resource...'), self.__newResource)
135 else: 144 else:
136 if self.hooks["compileAllResources"] is not None: 145 if self.hooks["compileAllResources"] is not None:
137 self.backMenu.addAction( 146 self.backMenu.addAction(
138 self.hooksMenuEntries.get("compileAllResources", 147 self.hooksMenuEntries.get("compileAllResources",
139 self.trUtf8('Compile all resources')), 148 self.trUtf8('Compile all resources')),
156 self.backMenu.addAction(self.trUtf8('Configure...'), self._configure) 165 self.backMenu.addAction(self.trUtf8('Configure...'), self._configure)
157 self.backMenu.setEnabled(False) 166 self.backMenu.setEnabled(False)
158 167
159 # create the menu for multiple selected files 168 # create the menu for multiple selected files
160 self.multiMenu = QMenu(self) 169 self.multiMenu = QMenu(self)
161 if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]: 170 if self.project.getProjectType() in \
171 ["Qt4", "PyQt5", "E4Plugin", "PySide"]:
162 act = self.multiMenu.addAction(self.trUtf8('Compile resources'), 172 act = self.multiMenu.addAction(self.trUtf8('Compile resources'),
163 self.__compileSelectedResources) 173 self.__compileSelectedResources)
164 self.multiMenu.addSeparator() 174 self.multiMenu.addSeparator()
165 else: 175 else:
166 if self.hooks["compileSelectedResources"] is not None: 176 if self.hooks["compileSelectedResources"] is not None:
172 self.multiMenu.addAction(self.trUtf8('Open'), self.__openFile) 182 self.multiMenu.addAction(self.trUtf8('Open'), self.__openFile)
173 self.multiMenu.addSeparator() 183 self.multiMenu.addSeparator()
174 act = self.multiMenu.addAction(self.trUtf8('Remove from project'), 184 act = self.multiMenu.addAction(self.trUtf8('Remove from project'),
175 self._removeFile) 185 self._removeFile)
176 self.multiMenuActions.append(act) 186 self.multiMenuActions.append(act)
177 act = self.multiMenu.addAction(self.trUtf8('Delete'), self.__deleteFile) 187 act = self.multiMenu.addAction(
188 self.trUtf8('Delete'), self.__deleteFile)
178 self.multiMenuActions.append(act) 189 self.multiMenuActions.append(act)
179 self.multiMenu.addSeparator() 190 self.multiMenu.addSeparator()
180 self.multiMenu.addAction(self.trUtf8('Expand all directories'), 191 self.multiMenu.addAction(self.trUtf8('Expand all directories'),
181 self._expandAllDirs) 192 self._expandAllDirs)
182 self.multiMenu.addAction(self.trUtf8('Collapse all directories'), 193 self.multiMenu.addAction(self.trUtf8('Collapse all directories'),
183 self._collapseAllDirs) 194 self._collapseAllDirs)
184 self.multiMenu.addSeparator() 195 self.multiMenu.addSeparator()
185 self.multiMenu.addAction(self.trUtf8('Configure...'), self._configure) 196 self.multiMenu.addAction(self.trUtf8('Configure...'), self._configure)
186 197
187 self.dirMenu = QMenu(self) 198 self.dirMenu = QMenu(self)
188 if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]: 199 if self.project.getProjectType() in \
200 ["Qt4", "PyQt5", "E4Plugin", "PySide"]:
189 self.dirMenu.addAction(self.trUtf8('Compile all resources'), 201 self.dirMenu.addAction(self.trUtf8('Compile all resources'),
190 self.__compileAllResources) 202 self.__compileAllResources)
191 self.dirMenu.addSeparator() 203 self.dirMenu.addSeparator()
192 else: 204 else:
193 if self.hooks["compileAllResources"] is not None: 205 if self.hooks["compileAllResources"] is not None:
194 self.dirMenu.addAction( 206 self.dirMenu.addAction(
195 self.hooksMenuEntries.get("compileAllResources", 207 self.hooksMenuEntries.get("compileAllResources",
196 self.trUtf8('Compile all resources')), 208 self.trUtf8('Compile all resources')),
197 self.__compileAllResources) 209 self.__compileAllResources)
198 self.dirMenu.addSeparator() 210 self.dirMenu.addSeparator()
199 act = self.dirMenu.addAction(self.trUtf8('Remove from project'), self._removeDir) 211 act = self.dirMenu.addAction(
212 self.trUtf8('Remove from project'), self._removeDir)
200 self.dirMenuActions.append(act) 213 self.dirMenuActions.append(act)
201 act = self.dirMenu.addAction(self.trUtf8('Delete'), self._deleteDirectory) 214 act = self.dirMenu.addAction(
215 self.trUtf8('Delete'), self._deleteDirectory)
202 self.dirMenuActions.append(act) 216 self.dirMenuActions.append(act)
203 self.dirMenu.addSeparator() 217 self.dirMenu.addSeparator()
204 self.dirMenu.addAction(self.trUtf8('New resource...'), self.__newResource) 218 self.dirMenu.addAction(
205 self.dirMenu.addAction(self.trUtf8('Add resources...'), self.__addResourceFiles) 219 self.trUtf8('New resource...'), self.__newResource)
220 self.dirMenu.addAction(
221 self.trUtf8('Add resources...'), self.__addResourceFiles)
206 self.dirMenu.addAction(self.trUtf8('Add resources directory...'), 222 self.dirMenu.addAction(self.trUtf8('Add resources directory...'),
207 self.__addResourcesDirectory) 223 self.__addResourcesDirectory)
208 self.dirMenu.addSeparator() 224 self.dirMenu.addSeparator()
209 self.dirMenu.addAction(self.trUtf8('Copy Path to Clipboard'), 225 self.dirMenu.addAction(self.trUtf8('Copy Path to Clipboard'),
210 self._copyToClipboard) 226 self._copyToClipboard)
215 self._collapseAllDirs) 231 self._collapseAllDirs)
216 self.dirMenu.addSeparator() 232 self.dirMenu.addSeparator()
217 self.dirMenu.addAction(self.trUtf8('Configure...'), self._configure) 233 self.dirMenu.addAction(self.trUtf8('Configure...'), self._configure)
218 234
219 self.dirMultiMenu = QMenu(self) 235 self.dirMultiMenu = QMenu(self)
220 if self.project.getProjectType() in ["Qt4", "PyQt5", "E4Plugin", "PySide"]: 236 if self.project.getProjectType() in \
237 ["Qt4", "PyQt5", "E4Plugin", "PySide"]:
221 self.dirMultiMenu.addAction(self.trUtf8('Compile all resources'), 238 self.dirMultiMenu.addAction(self.trUtf8('Compile all resources'),
222 self.__compileAllResources) 239 self.__compileAllResources)
223 self.dirMultiMenu.addSeparator() 240 self.dirMultiMenu.addSeparator()
224 else: 241 else:
225 if self.hooks["compileAllResources"] is not None: 242 if self.hooks["compileAllResources"] is not None:
236 self.dirMultiMenu.addAction(self.trUtf8('Expand all directories'), 253 self.dirMultiMenu.addAction(self.trUtf8('Expand all directories'),
237 self._expandAllDirs) 254 self._expandAllDirs)
238 self.dirMultiMenu.addAction(self.trUtf8('Collapse all directories'), 255 self.dirMultiMenu.addAction(self.trUtf8('Collapse all directories'),
239 self._collapseAllDirs) 256 self._collapseAllDirs)
240 self.dirMultiMenu.addSeparator() 257 self.dirMultiMenu.addSeparator()
241 self.dirMultiMenu.addAction(self.trUtf8('Configure...'), self._configure) 258 self.dirMultiMenu.addAction(
259 self.trUtf8('Configure...'), self._configure)
242 260
243 self.menu.aboutToShow.connect(self.__showContextMenu) 261 self.menu.aboutToShow.connect(self.__showContextMenu)
244 self.multiMenu.aboutToShow.connect(self.__showContextMenuMulti) 262 self.multiMenu.aboutToShow.connect(self.__showContextMenuMulti)
245 self.dirMenu.aboutToShow.connect(self.__showContextMenuDir) 263 self.dirMenu.aboutToShow.connect(self.__showContextMenuDir)
246 self.dirMultiMenu.aboutToShow.connect(self.__showContextMenuDirMulti) 264 self.dirMultiMenu.aboutToShow.connect(self.__showContextMenuDirMulti)
263 if cnt <= 1: 281 if cnt <= 1:
264 index = self.indexAt(coord) 282 index = self.indexAt(coord)
265 if index.isValid(): 283 if index.isValid():
266 self._selectSingleItem(index) 284 self._selectSingleItem(index)
267 categories = self.getSelectedItemsCountCategorized( 285 categories = self.getSelectedItemsCountCategorized(
268 [ProjectBrowserFileItem, ProjectBrowserSimpleDirectoryItem]) 286 [ProjectBrowserFileItem,
287 ProjectBrowserSimpleDirectoryItem])
269 cnt = categories["sum"] 288 cnt = categories["sum"]
270 289
271 bfcnt = categories[str(ProjectBrowserFileItem)] 290 bfcnt = categories[str(ProjectBrowserFileItem)]
272 sdcnt = categories[str(ProjectBrowserSimpleDirectoryItem)] 291 sdcnt = categories[str(ProjectBrowserSimpleDirectoryItem)]
273 if cnt > 1 and cnt == bfcnt: 292 if cnt > 1 and cnt == bfcnt:
452 fn2 = itm.fileName() 471 fn2 = itm.fileName()
453 fullNames.append(fn2) 472 fullNames.append(fn2)
454 fn = self.project.getRelativePath(fn2) 473 fn = self.project.getRelativePath(fn2)
455 files.append(fn) 474 files.append(fn)
456 475
457 from UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog 476 from UI.DeleteFilesConfirmationDialog import \
477 DeleteFilesConfirmationDialog
458 dlg = DeleteFilesConfirmationDialog(self.parent(), 478 dlg = DeleteFilesConfirmationDialog(self.parent(),
459 self.trUtf8("Delete resources"), 479 self.trUtf8("Delete resources"),
460 self.trUtf8("Do you really want to delete these resources from the project?"), 480 self.trUtf8(
481 "Do you really want to delete these resources from the"
482 " project?"),
461 files) 483 files)
462 484
463 if dlg.exec_() == QDialog.Accepted: 485 if dlg.exec_() == QDialog.Accepted:
464 for fn2, fn in zip(fullNames, files): 486 for fn2, fn in zip(fullNames, files):
465 self.closeSourceWindow.emit(fn2) 487 self.closeSourceWindow.emit(fn2)
466 self.project.deleteFile(fn) 488 self.project.deleteFile(fn)
467 489
468 ############################################################################ 490 ###########################################################################
469 ## Methods to handle the various compile commands 491 ## Methods to handle the various compile commands
470 ############################################################################ 492 ###########################################################################
471 493
472 def __readStdout(self): 494 def __readStdout(self):
473 """ 495 """
474 Private slot to handle the readyReadStandardOutput signal of the 496 Private slot to handle the readyReadStandardOutput signal of the
475 pyrcc4/rbrcc process. 497 pyrcc4/rbrcc process.
537 " was successful.")) 559 " was successful."))
538 except IOError as msg: 560 except IOError as msg:
539 if not self.noDialog: 561 if not self.noDialog:
540 E5MessageBox.information(self, 562 E5MessageBox.information(self,
541 self.trUtf8("Resource Compilation"), 563 self.trUtf8("Resource Compilation"),
542 self.trUtf8("<p>The compilation of the resource file failed.</p>" 564 self.trUtf8(
543 "<p>Reason: {0}</p>").format(str(msg))) 565 "<p>The compilation of the resource file"
566 " failed.</p><p>Reason: {0}</p>").format(str(msg)))
544 else: 567 else:
545 if not self.noDialog: 568 if not self.noDialog:
546 E5MessageBox.information(self, 569 E5MessageBox.information(self,
547 self.trUtf8("Resource Compilation"), 570 self.trUtf8("Resource Compilation"),
548 self.trUtf8("The compilation of the resource file failed.")) 571 self.trUtf8(
572 "The compilation of the resource file failed."))
549 else: 573 else:
550 ui.showNotification(UI.PixmapCache.getPixmap("resourcesCompiler48.png"), 574 ui.showNotification(
575 UI.PixmapCache.getPixmap("resourcesCompiler48.png"),
551 self.trUtf8("Resource Compilation"), 576 self.trUtf8("Resource Compilation"),
552 self.trUtf8("The compilation of the resource file failed.")) 577 self.trUtf8(
578 "The compilation of the resource file failed."))
553 self.compileProc = None 579 self.compileProc = None
554 580
555 def __compileQRC(self, fn, noDialog=False, progress=None): 581 def __compileQRC(self, fn, noDialog=False, progress=None):
556 """ 582 """
557 Privat method to compile a .qrc file to a .py file. 583 Privat method to compile a .qrc file to a .py file.
563 """ 589 """
564 self.compileProc = QProcess() 590 self.compileProc = QProcess()
565 args = [] 591 args = []
566 self.buf = "" 592 self.buf = ""
567 593
568 if self.project.pdata["PROGLANGUAGE"][0] in ["Python", "Python2", "Python3"]: 594 if self.project.pdata["PROGLANGUAGE"][0] in \
595 ["Python", "Python2", "Python3"]:
569 if self.project.getProjectType() in ["Qt4", "E4Plugin"]: 596 if self.project.getProjectType() in ["Qt4", "E4Plugin"]:
570 self.rccCompiler = 'pyrcc4' 597 self.rccCompiler = 'pyrcc4'
571 if Utilities.isWindowsPlatform(): 598 if Utilities.isWindowsPlatform():
572 self.rccCompiler += '.exe' 599 self.rccCompiler += '.exe'
573 if PYQT_VERSION >= 0x040500: 600 if PYQT_VERSION >= 0x040500:
574 if self.project.pdata["PROGLANGUAGE"][0] in ["Python", "Python2"]: 601 if self.project.pdata["PROGLANGUAGE"][0] in \
602 ["Python", "Python2"]:
575 args.append("-py2") 603 args.append("-py2")
576 else: 604 else:
577 args.append("-py3") 605 args.append("-py3")
578 elif self.project.getProjectType() == "PyQt5": 606 elif self.project.getProjectType() == "PyQt5":
579 self.rccCompiler = 'pyrcc5' 607 self.rccCompiler = 'pyrcc5'
580 if Utilities.isWindowsPlatform(): 608 if Utilities.isWindowsPlatform():
581 self.rccCompiler += '.exe' 609 self.rccCompiler += '.exe'
582 elif self.project.getProjectType() == "PySide": 610 elif self.project.getProjectType() == "PySide":
583 self.rccCompiler = Utilities.generatePySideToolPath('pyside-rcc') 611 self.rccCompiler = Utilities.generatePySideToolPath(
584 if self.project.pdata["PROGLANGUAGE"][0] in ["Python", "Python2"]: 612 'pyside-rcc')
613 if self.project.pdata["PROGLANGUAGE"][0] in \
614 ["Python", "Python2"]:
585 args.append("-py2") 615 args.append("-py2")
586 else: 616 else:
587 args.append("-py3") 617 args.append("-py3")
588 else: 618 else:
589 return None 619 return None
601 631
602 ofn, ext = os.path.splitext(fn) 632 ofn, ext = os.path.splitext(fn)
603 fn = os.path.join(self.project.ppath, fn) 633 fn = os.path.join(self.project.ppath, fn)
604 634
605 dirname, filename = os.path.split(ofn) 635 dirname, filename = os.path.split(ofn)
606 if self.project.pdata["PROGLANGUAGE"][0] in ["Python", "Python2", "Python3"]: 636 if self.project.pdata["PROGLANGUAGE"][0] in \
607 self.compiledFile = os.path.join(dirname, 637 ["Python", "Python2", "Python3"]:
608 self.RCFilenameFormatPython.format(filename)) 638 self.compiledFile = os.path.join(
639 dirname, self.RCFilenameFormatPython.format(filename))
609 elif self.project.pdata["PROGLANGUAGE"][0] == "Ruby": 640 elif self.project.pdata["PROGLANGUAGE"][0] == "Ruby":
610 self.compiledFile = os.path.join( 641 self.compiledFile = os.path.join(
611 dirname, self.RCFilenameFormatRuby.format(filename)) 642 dirname, self.RCFilenameFormatRuby.format(filename))
612 643
613 args.append(fn) 644 args.append(fn)
614 self.compileProc.finished.connect(self.__compileQRCDone) 645 self.compileProc.finished.connect(self.__compileQRCDone)
615 self.compileProc.readyReadStandardOutput.connect(self.__readStdout) 646 self.compileProc.readyReadStandardOutput.connect(self.__readStdout)
616 self.compileProc.readyReadStandardError.connect(self.__readStderr) 647 self.compileProc.readyReadStandardError.connect(self.__readStderr)
729 760
730 qrcDirName = os.path.dirname(filename) 761 qrcDirName = os.path.dirname(filename)
731 lbuf = "" 762 lbuf = ""
732 for line in buf.splitlines(): 763 for line in buf.splitlines():
733 line = line.strip() 764 line = line.strip()
734 if line.lower().startswith("<file>") or line.lower().startswith("<file "): 765 if line.lower().startswith("<file>") or \
766 line.lower().startswith("<file "):
735 lbuf = line 767 lbuf = line
736 elif lbuf: 768 elif lbuf:
737 lbuf = "{0}{1}".format(lbuf, line) 769 lbuf = "{0}{1}".format(lbuf, line)
738 if lbuf.lower().endswith("</file>"): 770 if lbuf.lower().endswith("</file>"):
739 rfile = lbuf.split(">", 1)[1].split("<", 1)[0] 771 rfile = lbuf.split(">", 1)[1].split("<", 1)[0]
750 def compileChangedResources(self): 782 def compileChangedResources(self):
751 """ 783 """
752 Public method to compile all changed resources to source files. 784 Public method to compile all changed resources to source files.
753 """ 785 """
754 if self.hooks["compileChangedResources"] is not None: 786 if self.hooks["compileChangedResources"] is not None:
755 self.hooks["compileChangedResources"](self.project.pdata["RESOURCES"]) 787 self.hooks["compileChangedResources"](
756 else: 788 self.project.pdata["RESOURCES"])
757 progress = QProgressDialog(self.trUtf8("Determining changed resources..."), 789 else:
790 progress = QProgressDialog(
791 self.trUtf8("Determining changed resources..."),
758 None, 0, 100) 792 None, 0, 100)
759 progress.setMinimumDuration(0) 793 progress.setMinimumDuration(0)
760 i = 0 794 i = 0
761 795
762 # get list of changed resources 796 # get list of changed resources
767 QApplication.processEvents() 801 QApplication.processEvents()
768 ifn = os.path.join(self.project.ppath, fn) 802 ifn = os.path.join(self.project.ppath, fn)
769 if self.project.pdata["PROGLANGUAGE"][0] in \ 803 if self.project.pdata["PROGLANGUAGE"][0] in \
770 ["Python", "Python2", "Python3"]: 804 ["Python", "Python2", "Python3"]:
771 dirname, filename = os.path.split(os.path.splitext(ifn)[0]) 805 dirname, filename = os.path.split(os.path.splitext(ifn)[0])
772 ofn = os.path.join(dirname, 806 ofn = os.path.join(
773 self.RCFilenameFormatPython.format(filename)) 807 dirname, self.RCFilenameFormatPython.format(filename))
774 elif self.project.pdata["PROGLANGUAGE"][0] == "Ruby": 808 elif self.project.pdata["PROGLANGUAGE"][0] == "Ruby":
775 dirname, filename = os.path.split(os.path.splitext(ifn)[0]) 809 dirname, filename = os.path.split(os.path.splitext(ifn)[0])
776 ofn = os.path.join(dirname, 810 ofn = os.path.join(
777 self.RCFilenameFormatRuby.format(filename)) 811 dirname, self.RCFilenameFormatRuby.format(filename))
778 else: 812 else:
779 return 813 return
780 if not os.path.exists(ofn) or \ 814 if not os.path.exists(ofn) or \
781 os.stat(ifn).st_mtime > os.stat(ofn).st_mtime: 815 os.stat(ifn).st_mtime > os.stat(ofn).st_mtime:
782 changedResources.append(fn) 816 changedResources.append(fn)
785 i += 1 819 i += 1
786 progress.setValue(i) 820 progress.setValue(i)
787 QApplication.processEvents() 821 QApplication.processEvents()
788 822
789 if changedResources: 823 if changedResources:
790 progress.setLabelText(self.trUtf8("Compiling changed resources...")) 824 progress.setLabelText(
825 self.trUtf8("Compiling changed resources..."))
791 progress.setMaximum(len(changedResources)) 826 progress.setMaximum(len(changedResources))
792 i = 0 827 i = 0
793 progress.setValue(i) 828 progress.setValue(i)
794 QApplication.processEvents() 829 QApplication.processEvents()
795 for fn in changedResources: 830 for fn in changedResources:
810 """ 845 """
811 Public slot used to handle the preferencesChanged signal. 846 Public slot used to handle the preferencesChanged signal.
812 """ 847 """
813 ProjectBaseBrowser.handlePreferencesChanged(self) 848 ProjectBaseBrowser.handlePreferencesChanged(self)
814 849
815 ############################################################################ 850 ###########################################################################
816 ## Support for hooks below 851 ## Support for hooks below
817 ############################################################################ 852 ###########################################################################
818 853
819 def _initHookMethods(self): 854 def _initHookMethods(self):
820 """ 855 """
821 Protected method to initialize the hooks dictionary. 856 Protected method to initialize the hooks dictionary.
822 857
823 Supported hook methods are: 858 Supported hook methods are:
824 <ul> 859 <ul>
825 <li>compileResource: takes filename as parameter</li> 860 <li>compileResource: takes filename as parameter</li>
826 <li>compileAllResources: takes list of filenames as parameter</li> 861 <li>compileAllResources: takes list of filenames as parameter</li>
827 <li>compileChangedResources: takes list of filenames as parameter</li> 862 <li>compileChangedResources: takes list of filenames as parameter</li>
828 <li>compileSelectedResources: takes list of all form filenames as parameter</li> 863 <li>compileSelectedResources: takes list of all form filenames as
829 <li>newResource: takes full directory path of new file as parameter</li> 864 parameter</li>
865 <li>newResource: takes full directory path of new file as
866 parameter</li>
830 </ul> 867 </ul>
831 868
832 <b>Note</b>: Filenames are relative to the project directory, if not 869 <b>Note</b>: Filenames are relative to the project directory, if not
833 specified differently. 870 specified differently.
834 """ 871 """

eric ide

mercurial