Project/ProjectResourcesBrowser.py

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

eric ide

mercurial