Project/ProjectResourcesBrowser.py

changeset 945
8cd4d08fa9f6
parent 882
34b86be88bf0
child 949
f888270da22e
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
23 from UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog 23 from UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog
24 24
25 import Preferences 25 import Preferences
26 import Utilities 26 import Utilities
27 27
28
28 class ProjectResourcesBrowser(ProjectBaseBrowser): 29 class ProjectResourcesBrowser(ProjectBaseBrowser):
29 """ 30 """
30 A class used to display the resources part of the project. 31 A class used to display the resources part of the project.
31 32
32 @signal appendStderr(str) emitted after something was received from 33 @signal appendStderr(str) emitted after something was received from
33 a QProcess on stderr 34 a QProcess on stderr
34 @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
35 @signal closeSourceWindow(str) emitted after a file has been removed/deleted 36 @signal closeSourceWindow(str) emitted after a file has been removed/deleted
36 from the project 37 from the project
37 @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. The name
38 of the menu and a reference to the menu are given. 39 of the menu and a reference to the menu are given.
39 """ 40 """
40 appendStderr = pyqtSignal(str) 41 appendStderr = pyqtSignal(str)
43 showMenu = pyqtSignal(str, QMenu) 44 showMenu = pyqtSignal(str, QMenu)
44 45
45 RCFilenameFormatPython = "{0}_rc.py" 46 RCFilenameFormatPython = "{0}_rc.py"
46 RCFilenameFormatRuby = "{0}_rc.rb" 47 RCFilenameFormatRuby = "{0}_rc.rb"
47 48
48 def __init__(self, project, parent = None): 49 def __init__(self, project, parent=None):
49 """ 50 """
50 Constructor 51 Constructor
51 52
52 @param project reference to the project object 53 @param project reference to the project object
53 @param parent parent widget of this browser (QWidget) 54 @param parent parent widget of this browser (QWidget)
76 self.dirMenuActions = [] 77 self.dirMenuActions = []
77 self.dirMultiMenuActions = [] 78 self.dirMultiMenuActions = []
78 79
79 self.menu = QMenu(self) 80 self.menu = QMenu(self)
80 if self.project.getProjectType() in ["Qt4", "E4Plugin", "PySide"]: 81 if self.project.getProjectType() in ["Qt4", "E4Plugin", "PySide"]:
81 self.menu.addAction(self.trUtf8('Compile resource'), 82 self.menu.addAction(self.trUtf8('Compile resource'),
82 self.__compileResource) 83 self.__compileResource)
83 self.menu.addAction(self.trUtf8('Compile all resources'), 84 self.menu.addAction(self.trUtf8('Compile all resources'),
84 self.__compileAllResources) 85 self.__compileAllResources)
85 self.menu.addSeparator() 86 self.menu.addSeparator()
86 else: 87 else:
87 if self.hooks["compileResource"] is not None: 88 if self.hooks["compileResource"] is not None:
88 self.menu.addAction( 89 self.menu.addAction(
89 self.hooksMenuEntries.get("compileResource", 90 self.hooksMenuEntries.get("compileResource",
90 self.trUtf8('Compile resource')), 91 self.trUtf8('Compile resource')),
91 self.__compileResource) 92 self.__compileResource)
92 if self.hooks["compileAllResources"] is not None: 93 if self.hooks["compileAllResources"] is not None:
93 self.menu.addAction( 94 self.menu.addAction(
94 self.hooksMenuEntries.get("compileAllResources", 95 self.hooksMenuEntries.get("compileAllResources",
95 self.trUtf8('Compile all resources')), 96 self.trUtf8('Compile all resources')),
96 self.__compileAllResources) 97 self.__compileAllResources)
97 if self.hooks["compileResource"] is not None or \ 98 if self.hooks["compileResource"] is not None or \
98 self.hooks["compileAllResources"] is not None: 99 self.hooks["compileAllResources"] is not None:
99 self.menu.addSeparator() 100 self.menu.addSeparator()
100 self.menu.addAction(self.trUtf8('Open'), self.__openFile) 101 self.menu.addAction(self.trUtf8('Open'), self.__openFile)
109 if self.project.getProjectType() in ["Qt4", "E4Plugin", "PySide"]: 110 if self.project.getProjectType() in ["Qt4", "E4Plugin", "PySide"]:
110 self.menu.addAction(self.trUtf8('New resource...'), self.__newResource) 111 self.menu.addAction(self.trUtf8('New resource...'), self.__newResource)
111 else: 112 else:
112 if self.hooks["newResource"] is not None: 113 if self.hooks["newResource"] is not None:
113 self.menu.addAction( 114 self.menu.addAction(
114 self.hooksMenuEntries.get("newResource", 115 self.hooksMenuEntries.get("newResource",
115 self.trUtf8('New resource...')), self.__newResource) 116 self.trUtf8('New resource...')), self.__newResource)
116 self.menu.addAction(self.trUtf8('Add resources...'), self.__addResourceFiles) 117 self.menu.addAction(self.trUtf8('Add resources...'), self.__addResourceFiles)
117 self.menu.addAction(self.trUtf8('Add resources directory...'), 118 self.menu.addAction(self.trUtf8('Add resources directory...'),
118 self.__addResourcesDirectory) 119 self.__addResourcesDirectory)
119 self.menu.addSeparator() 120 self.menu.addSeparator()
120 self.menu.addAction(self.trUtf8('Copy Path to Clipboard'), 121 self.menu.addAction(self.trUtf8('Copy Path to Clipboard'),
121 self._copyToClipboard) 122 self._copyToClipboard)
122 self.menu.addSeparator() 123 self.menu.addSeparator()
123 self.menu.addAction(self.trUtf8('Expand all directories'), 124 self.menu.addAction(self.trUtf8('Expand all directories'),
124 self._expandAllDirs) 125 self._expandAllDirs)
125 self.menu.addAction(self.trUtf8('Collapse all directories'), 126 self.menu.addAction(self.trUtf8('Collapse all directories'),
126 self._collapseAllDirs) 127 self._collapseAllDirs)
127 self.menu.addSeparator() 128 self.menu.addSeparator()
128 self.menu.addAction(self.trUtf8('Configure...'), self._configure) 129 self.menu.addAction(self.trUtf8('Configure...'), self._configure)
129 130
130 self.backMenu = QMenu(self) 131 self.backMenu = QMenu(self)
131 if self.project.getProjectType() in ["Qt4", "E4Plugin", "PySide"]: 132 if self.project.getProjectType() in ["Qt4", "E4Plugin", "PySide"]:
132 self.backMenu.addAction(self.trUtf8('Compile all resources'), 133 self.backMenu.addAction(self.trUtf8('Compile all resources'),
133 self.__compileAllResources) 134 self.__compileAllResources)
134 self.backMenu.addSeparator() 135 self.backMenu.addSeparator()
135 self.backMenu.addAction(self.trUtf8('New resource...'), self.__newResource) 136 self.backMenu.addAction(self.trUtf8('New resource...'), self.__newResource)
136 else: 137 else:
137 if self.hooks["compileAllResources"] is not None: 138 if self.hooks["compileAllResources"] is not None:
138 self.backMenu.addAction( 139 self.backMenu.addAction(
139 self.hooksMenuEntries.get("compileAllResources", 140 self.hooksMenuEntries.get("compileAllResources",
140 self.trUtf8('Compile all resources')), 141 self.trUtf8('Compile all resources')),
141 self.__compileAllResources) 142 self.__compileAllResources)
142 self.backMenu.addSeparator() 143 self.backMenu.addSeparator()
143 if self.hooks["newResource"] is not None: 144 if self.hooks["newResource"] is not None:
144 self.backMenu.addAction( 145 self.backMenu.addAction(
145 self.hooksMenuEntries.get("newResource", 146 self.hooksMenuEntries.get("newResource",
146 self.trUtf8('New resource...')), self.__newResource) 147 self.trUtf8('New resource...')), self.__newResource)
147 self.backMenu.addAction(self.trUtf8('Add resources...'), 148 self.backMenu.addAction(self.trUtf8('Add resources...'),
148 self.project.addResourceFiles) 149 self.project.addResourceFiles)
149 self.backMenu.addAction(self.trUtf8('Add resources directory...'), 150 self.backMenu.addAction(self.trUtf8('Add resources directory...'),
150 self.project.addResourceDir) 151 self.project.addResourceDir)
151 self.backMenu.addSeparator() 152 self.backMenu.addSeparator()
152 self.backMenu.addAction(self.trUtf8('Expand all directories'), 153 self.backMenu.addAction(self.trUtf8('Expand all directories'),
153 self._expandAllDirs) 154 self._expandAllDirs)
154 self.backMenu.addAction(self.trUtf8('Collapse all directories'), 155 self.backMenu.addAction(self.trUtf8('Collapse all directories'),
155 self._collapseAllDirs) 156 self._collapseAllDirs)
156 self.backMenu.addSeparator() 157 self.backMenu.addSeparator()
157 self.backMenu.addAction(self.trUtf8('Configure...'), self._configure) 158 self.backMenu.addAction(self.trUtf8('Configure...'), self._configure)
158 self.backMenu.setEnabled(False) 159 self.backMenu.setEnabled(False)
159 160
160 # create the menu for multiple selected files 161 # create the menu for multiple selected files
161 self.multiMenu = QMenu(self) 162 self.multiMenu = QMenu(self)
162 if self.project.getProjectType() in ["Qt4", "E4Plugin", "PySide"]: 163 if self.project.getProjectType() in ["Qt4", "E4Plugin", "PySide"]:
163 act = self.multiMenu.addAction(self.trUtf8('Compile resources'), 164 act = self.multiMenu.addAction(self.trUtf8('Compile resources'),
164 self.__compileSelectedResources) 165 self.__compileSelectedResources)
165 self.multiMenu.addSeparator() 166 self.multiMenu.addSeparator()
166 else: 167 else:
167 if self.hooks["compileSelectedResources"] is not None: 168 if self.hooks["compileSelectedResources"] is not None:
168 act = self.multiMenu.addAction( 169 act = self.multiMenu.addAction(
169 self.hooksMenuEntries.get("compileSelectedResources", 170 self.hooksMenuEntries.get("compileSelectedResources",
170 self.trUtf8('Compile resources')), 171 self.trUtf8('Compile resources')),
171 self.__compileSelectedResources) 172 self.__compileSelectedResources)
172 self.multiMenu.addSeparator() 173 self.multiMenu.addSeparator()
173 self.multiMenu.addAction(self.trUtf8('Open'), self.__openFile) 174 self.multiMenu.addAction(self.trUtf8('Open'), self.__openFile)
174 self.multiMenu.addSeparator() 175 self.multiMenu.addSeparator()
175 act = self.multiMenu.addAction(self.trUtf8('Remove from project'), 176 act = self.multiMenu.addAction(self.trUtf8('Remove from project'),
176 self._removeFile) 177 self._removeFile)
177 self.multiMenuActions.append(act) 178 self.multiMenuActions.append(act)
178 act = self.multiMenu.addAction(self.trUtf8('Delete'), self.__deleteFile) 179 act = self.multiMenu.addAction(self.trUtf8('Delete'), self.__deleteFile)
179 self.multiMenuActions.append(act) 180 self.multiMenuActions.append(act)
180 self.multiMenu.addSeparator() 181 self.multiMenu.addSeparator()
181 self.multiMenu.addAction(self.trUtf8('Expand all directories'), 182 self.multiMenu.addAction(self.trUtf8('Expand all directories'),
182 self._expandAllDirs) 183 self._expandAllDirs)
183 self.multiMenu.addAction(self.trUtf8('Collapse all directories'), 184 self.multiMenu.addAction(self.trUtf8('Collapse all directories'),
184 self._collapseAllDirs) 185 self._collapseAllDirs)
185 self.multiMenu.addSeparator() 186 self.multiMenu.addSeparator()
186 self.multiMenu.addAction(self.trUtf8('Configure...'), self._configure) 187 self.multiMenu.addAction(self.trUtf8('Configure...'), self._configure)
187 188
188 self.dirMenu = QMenu(self) 189 self.dirMenu = QMenu(self)
189 if self.project.getProjectType() in ["Qt4", "E4Plugin", "PySide"]: 190 if self.project.getProjectType() in ["Qt4", "E4Plugin", "PySide"]:
190 self.dirMenu.addAction(self.trUtf8('Compile all resources'), 191 self.dirMenu.addAction(self.trUtf8('Compile all resources'),
191 self.__compileAllResources) 192 self.__compileAllResources)
192 self.dirMenu.addSeparator() 193 self.dirMenu.addSeparator()
193 else: 194 else:
194 if self.hooks["compileAllResources"] is not None: 195 if self.hooks["compileAllResources"] is not None:
195 self.dirMenu.addAction( 196 self.dirMenu.addAction(
196 self.hooksMenuEntries.get("compileAllResources", 197 self.hooksMenuEntries.get("compileAllResources",
197 self.trUtf8('Compile all resources')), 198 self.trUtf8('Compile all resources')),
198 self.__compileAllResources) 199 self.__compileAllResources)
199 self.dirMenu.addSeparator() 200 self.dirMenu.addSeparator()
200 act = self.dirMenu.addAction(self.trUtf8('Remove from project'), self._removeDir) 201 act = self.dirMenu.addAction(self.trUtf8('Remove from project'), self._removeDir)
201 self.dirMenuActions.append(act) 202 self.dirMenuActions.append(act)
202 self.dirMenu.addSeparator() 203 self.dirMenu.addSeparator()
203 self.dirMenu.addAction(self.trUtf8('New resource...'), self.__newResource) 204 self.dirMenu.addAction(self.trUtf8('New resource...'), self.__newResource)
204 self.dirMenu.addAction(self.trUtf8('Add resources...'), self.__addResourceFiles) 205 self.dirMenu.addAction(self.trUtf8('Add resources...'), self.__addResourceFiles)
205 self.dirMenu.addAction(self.trUtf8('Add resources directory...'), 206 self.dirMenu.addAction(self.trUtf8('Add resources directory...'),
206 self.__addResourcesDirectory) 207 self.__addResourcesDirectory)
207 self.dirMenu.addSeparator() 208 self.dirMenu.addSeparator()
208 self.dirMenu.addAction(self.trUtf8('Copy Path to Clipboard'), 209 self.dirMenu.addAction(self.trUtf8('Copy Path to Clipboard'),
209 self._copyToClipboard) 210 self._copyToClipboard)
210 self.dirMenu.addSeparator() 211 self.dirMenu.addSeparator()
211 self.dirMenu.addAction(self.trUtf8('Expand all directories'), 212 self.dirMenu.addAction(self.trUtf8('Expand all directories'),
212 self._expandAllDirs) 213 self._expandAllDirs)
213 self.dirMenu.addAction(self.trUtf8('Collapse all directories'), 214 self.dirMenu.addAction(self.trUtf8('Collapse all directories'),
214 self._collapseAllDirs) 215 self._collapseAllDirs)
215 self.dirMenu.addSeparator() 216 self.dirMenu.addSeparator()
216 self.dirMenu.addAction(self.trUtf8('Configure...'), self._configure) 217 self.dirMenu.addAction(self.trUtf8('Configure...'), self._configure)
217 218
218 self.dirMultiMenu = QMenu(self) 219 self.dirMultiMenu = QMenu(self)
219 if self.project.getProjectType() in ["Qt4", "E4Plugin", "PySide"]: 220 if self.project.getProjectType() in ["Qt4", "E4Plugin", "PySide"]:
220 self.dirMultiMenu.addAction(self.trUtf8('Compile all resources'), 221 self.dirMultiMenu.addAction(self.trUtf8('Compile all resources'),
221 self.__compileAllResources) 222 self.__compileAllResources)
222 self.dirMultiMenu.addSeparator() 223 self.dirMultiMenu.addSeparator()
223 else: 224 else:
224 if self.hooks["compileAllResources"] is not None: 225 if self.hooks["compileAllResources"] is not None:
225 self.dirMultiMenu.addAction( 226 self.dirMultiMenu.addAction(
226 self.hooksMenuEntries.get("compileAllResources", 227 self.hooksMenuEntries.get("compileAllResources",
227 self.trUtf8('Compile all resources')), 228 self.trUtf8('Compile all resources')),
228 self.__compileAllResources) 229 self.__compileAllResources)
229 self.dirMultiMenu.addSeparator() 230 self.dirMultiMenu.addSeparator()
230 self.dirMultiMenu.addAction(self.trUtf8('Add resources...'), 231 self.dirMultiMenu.addAction(self.trUtf8('Add resources...'),
231 self.project.addResourceFiles) 232 self.project.addResourceFiles)
232 self.dirMultiMenu.addAction(self.trUtf8('Add resources directory...'), 233 self.dirMultiMenu.addAction(self.trUtf8('Add resources directory...'),
233 self.project.addResourceDir) 234 self.project.addResourceDir)
234 self.dirMultiMenu.addSeparator() 235 self.dirMultiMenu.addSeparator()
235 self.dirMultiMenu.addAction(self.trUtf8('Expand all directories'), 236 self.dirMultiMenu.addAction(self.trUtf8('Expand all directories'),
236 self._expandAllDirs) 237 self._expandAllDirs)
237 self.dirMultiMenu.addAction(self.trUtf8('Collapse all directories'), 238 self.dirMultiMenu.addAction(self.trUtf8('Collapse all directories'),
238 self._collapseAllDirs) 239 self._collapseAllDirs)
239 self.dirMultiMenu.addSeparator() 240 self.dirMultiMenu.addSeparator()
240 self.dirMultiMenu.addAction(self.trUtf8('Configure...'), self._configure) 241 self.dirMultiMenu.addAction(self.trUtf8('Configure...'), self._configure)
241 242
242 self.menu.aboutToShow.connect(self.__showContextMenu) 243 self.menu.aboutToShow.connect(self.__showContextMenu)
406 407
407 if os.path.exists(fname): 408 if os.path.exists(fname):
408 res = E5MessageBox.yesNo(self, 409 res = E5MessageBox.yesNo(self,
409 self.trUtf8("New Resource"), 410 self.trUtf8("New Resource"),
410 self.trUtf8("The file already exists! Overwrite it?"), 411 self.trUtf8("The file already exists! Overwrite it?"),
411 icon = E5MessageBox.Warning) 412 icon=E5MessageBox.Warning)
412 if not res: 413 if not res:
413 # user selected to not overwrite 414 # user selected to not overwrite
414 return 415 return
415 416
416 try: 417 try:
417 if self.project.useSystemEol(): 418 if self.project.useSystemEol():
418 newline = None 419 newline = None
419 else: 420 else:
420 newline = self.project.getEolString() 421 newline = self.project.getEolString()
421 rcfile = open(fname, 'w', encoding = "utf-8", newline = newline) 422 rcfile = open(fname, 'w', encoding="utf-8", newline=newline)
422 rcfile.write('<!DOCTYPE RCC>\n') 423 rcfile.write('<!DOCTYPE RCC>\n')
423 rcfile.write('<RCC version="1.0">\n') 424 rcfile.write('<RCC version="1.0">\n')
424 rcfile.write('<qresource>\n') 425 rcfile.write('<qresource>\n')
425 rcfile.write('</qresource>\n') 426 rcfile.write('</qresource>\n')
426 rcfile.write('</RCC>\n') 427 rcfile.write('</RCC>\n')
464 ## Methods to handle the various compile commands 465 ## Methods to handle the various compile commands
465 ############################################################################ 466 ############################################################################
466 467
467 def __readStdout(self): 468 def __readStdout(self):
468 """ 469 """
469 Private slot to handle the readyReadStandardOutput signal of the 470 Private slot to handle the readyReadStandardOutput signal of the
470 pyrcc4/rbrcc process. 471 pyrcc4/rbrcc process.
471 """ 472 """
472 if self.compileProc is None: 473 if self.compileProc is None:
473 return 474 return
474 self.compileProc.setReadChannel(QProcess.StandardOutput) 475 self.compileProc.setReadChannel(QProcess.StandardOutput)
475 476
476 while self.compileProc and self.compileProc.canReadLine(): 477 while self.compileProc and self.compileProc.canReadLine():
477 self.buf += str(self.compileProc.readLine(), 478 self.buf += str(self.compileProc.readLine(),
478 Preferences.getSystem("IOEncoding"), 479 Preferences.getSystem("IOEncoding"),
479 'replace') 480 'replace')
480 481
481 def __readStderr(self): 482 def __readStderr(self):
482 """ 483 """
483 Private slot to handle the readyReadStandardError signal of the 484 Private slot to handle the readyReadStandardError signal of the
484 pyrcc4/rbrcc process. 485 pyrcc4/rbrcc process.
485 """ 486 """
486 if self.compileProc is None: 487 if self.compileProc is None:
487 return 488 return
488 489
489 ioEncoding = Preferences.getSystem("IOEncoding") 490 ioEncoding = Preferences.getSystem("IOEncoding")
490 491
491 self.compileProc.setReadChannel(QProcess.StandardError) 492 self.compileProc.setReadChannel(QProcess.StandardError)
492 while self.compileProc and self.compileProc.canReadLine(): 493 while self.compileProc and self.compileProc.canReadLine():
493 s = self.rccCompiler + ': ' 494 s = self.rccCompiler + ': '
494 error = str(self.compileProc.readLine(), 495 error = str(self.compileProc.readLine(),
495 ioEncoding, 'replace') 496 ioEncoding, 'replace')
496 s += error 497 s += error
497 self.appendStderr.emit(s) 498 self.appendStderr.emit(s)
498 499
499 def __compileQRCDone(self, exitCode, exitStatus): 500 def __compileQRCDone(self, exitCode, exitStatus):
510 try: 511 try:
511 if self.project.useSystemEol(): 512 if self.project.useSystemEol():
512 newline = None 513 newline = None
513 else: 514 else:
514 newline = self.project.getEolString() 515 newline = self.project.getEolString()
515 f = open(ofn, "w", encoding = "utf-8", newline = newline) 516 f = open(ofn, "w", encoding="utf-8", newline=newline)
516 for line in self.buf.splitlines(): 517 for line in self.buf.splitlines():
517 f.write(line + "\n") 518 f.write(line + "\n")
518 f.close() 519 f.close()
519 if self.compiledFile not in self.project.pdata["SOURCES"]: 520 if self.compiledFile not in self.project.pdata["SOURCES"]:
520 self.project.appendFile(ofn) 521 self.project.appendFile(ofn)
534 E5MessageBox.information(self, 535 E5MessageBox.information(self,
535 self.trUtf8("Resource Compilation"), 536 self.trUtf8("Resource Compilation"),
536 self.trUtf8("The compilation of the resource file failed.")) 537 self.trUtf8("The compilation of the resource file failed."))
537 self.compileProc = None 538 self.compileProc = None
538 539
539 def __compileQRC(self, fn, noDialog = False, progress = None): 540 def __compileQRC(self, fn, noDialog=False, progress=None):
540 """ 541 """
541 Privat method to compile a .qrc file to a .py file. 542 Privat method to compile a .qrc file to a .py file.
542 543
543 @param fn filename of the .ui file to be compiled 544 @param fn filename of the .ui file to be compiled
544 @param noDialog flag indicating silent operations 545 @param noDialog flag indicating silent operations
580 ofn, ext = os.path.splitext(fn) 581 ofn, ext = os.path.splitext(fn)
581 fn = os.path.join(self.project.ppath, fn) 582 fn = os.path.join(self.project.ppath, fn)
582 583
583 dirname, filename = os.path.split(ofn) 584 dirname, filename = os.path.split(ofn)
584 if self.project.pdata["PROGLANGUAGE"][0] in ["Python", "Python2", "Python3"]: 585 if self.project.pdata["PROGLANGUAGE"][0] in ["Python", "Python2", "Python3"]:
585 self.compiledFile = os.path.join(dirname, 586 self.compiledFile = os.path.join(dirname,
586 self.RCFilenameFormatPython.format(filename)) 587 self.RCFilenameFormatPython.format(filename))
587 elif self.project.pdata["PROGLANGUAGE"][0] == "Ruby": 588 elif self.project.pdata["PROGLANGUAGE"][0] == "Ruby":
588 self.compiledFile = os.path.join( 589 self.compiledFile = os.path.join(
589 dirname, self.RCFilenameFormatRuby.format(filename)) 590 dirname, self.RCFilenameFormatRuby.format(filename))
590 591
630 """ 631 """
631 if self.hooks["compileAllResources"] is not None: 632 if self.hooks["compileAllResources"] is not None:
632 self.hooks["compileAllResources"](self.project.pdata["RESOURCES"]) 633 self.hooks["compileAllResources"](self.project.pdata["RESOURCES"])
633 else: 634 else:
634 numResources = len(self.project.pdata["RESOURCES"]) 635 numResources = len(self.project.pdata["RESOURCES"])
635 progress = QProgressDialog(self.trUtf8("Compiling resources..."), 636 progress = QProgressDialog(self.trUtf8("Compiling resources..."),
636 self.trUtf8("Abort"), 0, numResources, self) 637 self.trUtf8("Abort"), 0, numResources, self)
637 progress.setModal(True) 638 progress.setModal(True)
638 progress.setMinimumDuration(0) 639 progress.setMinimumDuration(0)
639 i = 0 640 i = 0
640 641
664 665
665 if self.hooks["compileSelectedResources"] is not None: 666 if self.hooks["compileSelectedResources"] is not None:
666 self.hooks["compileSelectedResources"](files) 667 self.hooks["compileSelectedResources"](files)
667 else: 668 else:
668 numResources = len(files) 669 numResources = len(files)
669 progress = QProgressDialog(self.trUtf8("Compiling resources..."), 670 progress = QProgressDialog(self.trUtf8("Compiling resources..."),
670 self.trUtf8("Abort"), 0, numResources, self) 671 self.trUtf8("Abort"), 0, numResources, self)
671 progress.setModal(True) 672 progress.setModal(True)
672 progress.setMinimumDuration(0) 673 progress.setMinimumDuration(0)
673 i = 0 674 i = 0
674 675
697 @param filename filename of the resource file (string) 698 @param filename filename of the resource file (string)
698 @param mtime modification time to check against 699 @param mtime modification time to check against
699 @return flag indicating some file is newer (boolean) 700 @return flag indicating some file is newer (boolean)
700 """ 701 """
701 try: 702 try:
702 f = open(filename, "r", encoding = "utf-8") 703 f = open(filename, "r", encoding="utf-8")
703 buf = f.read() 704 buf = f.read()
704 f.close() 705 f.close()
705 except IOError: 706 except IOError:
706 return False 707 return False
707 708
729 Public method to compile all changed resources to source files. 730 Public method to compile all changed resources to source files.
730 """ 731 """
731 if self.hooks["compileChangedResources"] is not None: 732 if self.hooks["compileChangedResources"] is not None:
732 self.hooks["compileChangedResources"](self.project.pdata["RESOURCES"]) 733 self.hooks["compileChangedResources"](self.project.pdata["RESOURCES"])
733 else: 734 else:
734 progress = QProgressDialog(self.trUtf8("Determining changed resources..."), 735 progress = QProgressDialog(self.trUtf8("Determining changed resources..."),
735 None, 0, 100) 736 None, 0, 100)
736 progress.setMinimumDuration(0) 737 progress.setMinimumDuration(0)
737 i = 0 738 i = 0
738 739
739 # get list of changed resources 740 # get list of changed resources
744 QApplication.processEvents() 745 QApplication.processEvents()
745 ifn = os.path.join(self.project.ppath, fn) 746 ifn = os.path.join(self.project.ppath, fn)
746 if self.project.pdata["PROGLANGUAGE"][0] in \ 747 if self.project.pdata["PROGLANGUAGE"][0] in \
747 ["Python", "Python2", "Python3"]: 748 ["Python", "Python2", "Python3"]:
748 dirname, filename = os.path.split(os.path.splitext(ifn)[0]) 749 dirname, filename = os.path.split(os.path.splitext(ifn)[0])
749 ofn = os.path.join(dirname, 750 ofn = os.path.join(dirname,
750 self.RCFilenameFormatPython.format(filename)) 751 self.RCFilenameFormatPython.format(filename))
751 elif self.project.pdata["PROGLANGUAGE"][0] == "Ruby": 752 elif self.project.pdata["PROGLANGUAGE"][0] == "Ruby":
752 dirname, filename = os.path.split(os.path.splitext(ifn)[0]) 753 dirname, filename = os.path.split(os.path.splitext(ifn)[0])
753 ofn = os.path.join(dirname, 754 ofn = os.path.join(dirname,
754 self.RCFilenameFormatRuby.format(filename)) 755 self.RCFilenameFormatRuby.format(filename))
755 else: 756 else:
756 return 757 return
757 if not os.path.exists(ofn) or \ 758 if not os.path.exists(ofn) or \
758 os.stat(ifn).st_mtime > os.stat(ofn).st_mtime: 759 os.stat(ifn).st_mtime > os.stat(ofn).st_mtime:
808 809
809 <b>Note</b>: Filenames are relative to the project directory, if not 810 <b>Note</b>: Filenames are relative to the project directory, if not
810 specified differently. 811 specified differently.
811 """ 812 """
812 self.hooks = { 813 self.hooks = {
813 "compileResource" : None, 814 "compileResource": None,
814 "compileAllResources" : None, 815 "compileAllResources": None,
815 "compileChangedResources" : None, 816 "compileChangedResources": None,
816 "compileSelectedResources" : None, 817 "compileSelectedResources": None,
817 "newResource" : None, 818 "newResource": None,
818 } 819 }

eric ide

mercurial