Project/ProjectResourcesBrowser.py

changeset 12
1d8dd9706f46
parent 0
de9c2efb9d02
child 13
1af94a91f439
equal deleted inserted replaced
11:b0996e4a289e 12:1d8dd9706f46
14 from PyQt4.QtCore import * 14 from PyQt4.QtCore import *
15 from PyQt4.QtGui import * 15 from PyQt4.QtGui import *
16 16
17 from E4Gui.E4Application import e4App 17 from E4Gui.E4Application import e4App
18 18
19 from ProjectBrowserModel import ProjectBrowserFileItem, \ 19 from .ProjectBrowserModel import ProjectBrowserFileItem, \
20 ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem, \ 20 ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem, \
21 ProjectBrowserResourceType 21 ProjectBrowserResourceType
22 from ProjectBaseBrowser import ProjectBaseBrowser 22 from .ProjectBaseBrowser import ProjectBaseBrowser
23 23
24 from UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog 24 from UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog
25 import UI.PixmapCache 25 import UI.PixmapCache
26 26
27 import Preferences 27 import Preferences
269 self._selectSingleItem(index) 269 self._selectSingleItem(index)
270 categories = self.getSelectedItemsCountCategorized(\ 270 categories = self.getSelectedItemsCountCategorized(\
271 [ProjectBrowserFileItem, ProjectBrowserSimpleDirectoryItem]) 271 [ProjectBrowserFileItem, ProjectBrowserSimpleDirectoryItem])
272 cnt = categories["sum"] 272 cnt = categories["sum"]
273 273
274 bfcnt = categories[unicode(ProjectBrowserFileItem)] 274 bfcnt = categories[str(ProjectBrowserFileItem)]
275 sdcnt = categories[unicode(ProjectBrowserSimpleDirectoryItem)] 275 sdcnt = categories[str(ProjectBrowserSimpleDirectoryItem)]
276 if cnt > 1 and cnt == bfcnt: 276 if cnt > 1 and cnt == bfcnt:
277 self.multiMenu.popup(self.mapToGlobal(coord)) 277 self.multiMenu.popup(self.mapToGlobal(coord))
278 elif cnt > 1 and cnt == sdcnt: 278 elif cnt > 1 and cnt == sdcnt:
279 self.dirMultiMenu.popup(self.mapToGlobal(coord)) 279 self.dirMultiMenu.popup(self.mapToGlobal(coord))
280 else: 280 else:
419 if res != QMessageBox.Yes: 419 if res != QMessageBox.Yes:
420 # user selected to not overwrite 420 # user selected to not overwrite
421 return 421 return
422 422
423 try: 423 try:
424 rcfile = open(fname, 'wb') 424 rcfile = open(fname, 'w')
425 rcfile.write('<!DOCTYPE RCC>\n') 425 rcfile.write('<!DOCTYPE RCC>\n')
426 rcfile.write('<RCC version="1.0">\n') 426 rcfile.write('<RCC version="1.0">\n')
427 rcfile.write('<qresource>\n') 427 rcfile.write('<qresource>\n')
428 rcfile.write('</qresource>\n') 428 rcfile.write('</qresource>\n')
429 rcfile.write('</RCC>\n') 429 rcfile.write('</RCC>\n')
430 rcfile.close() 430 rcfile.close()
431 except IOError, e: 431 except IOError as e:
432 QMessageBox.critical(self, 432 QMessageBox.critical(self,
433 self.trUtf8("New Resource"), 433 self.trUtf8("New Resource"),
434 self.trUtf8("<p>The new resource file <b>{0}</b> could not be created.<br>" 434 self.trUtf8("<p>The new resource file <b>{0}</b> could not be created.<br>"
435 "Problem: {1}</p>").format(fname, unicode(e))) 435 "Problem: {1}</p>").format(fname, str(e)))
436 return 436 return
437 437
438 self.project.appendFile(fname) 438 self.project.appendFile(fname)
439 self.emit(SIGNAL('sourceFile'), fname) 439 self.emit(SIGNAL('sourceFile'), fname)
440 440
474 if self.compileProc is None: 474 if self.compileProc is None:
475 return 475 return
476 self.compileProc.setReadChannel(QProcess.StandardOutput) 476 self.compileProc.setReadChannel(QProcess.StandardOutput)
477 477
478 while self.compileProc and self.compileProc.canReadLine(): 478 while self.compileProc and self.compileProc.canReadLine():
479 self.buf += unicode(self.compileProc.readLine()) 479 self.buf += str(self.compileProc.readLine(),
480 Preferences.getSystem("IOEncoding"),
481 'replace')
480 482
481 def __readStderr(self): 483 def __readStderr(self):
482 """ 484 """
483 Private slot to handle the readyReadStandardError signal of the 485 Private slot to handle the readyReadStandardError signal of the
484 pyrcc4/rbrcc process. 486 pyrcc4/rbrcc process.
485 """ 487 """
486 if self.compileProc is None: 488 if self.compileProc is None:
487 return 489 return
488 490
489 ioEncoding = str(Preferences.getSystem("IOEncoding")) 491 ioEncoding = Preferences.getSystem("IOEncoding")
490 492
491 self.compileProc.setReadChannel(QProcess.StandardError) 493 self.compileProc.setReadChannel(QProcess.StandardError)
492 while self.compileProc and self.compileProc.canReadLine(): 494 while self.compileProc and self.compileProc.canReadLine():
493 s = self.rccCompiler + ': ' 495 s = self.rccCompiler + ': '
494 error = unicode(self.compileProc.readLine(), 496 error = str(self.compileProc.readLine(),
495 ioEncoding, 'replace') 497 ioEncoding, 'replace')
496 s += error 498 s += error
497 self.emit(SIGNAL('appendStderr'), s) 499 self.emit(SIGNAL('appendStderr'), s)
498 500
499 def __compileQRCDone(self, exitCode, exitStatus): 501 def __compileQRCDone(self, exitCode, exitStatus):
506 self.compileRunning = False 508 self.compileRunning = False
507 e4App().getObject("ViewManager").enableEditorsCheckFocusIn(True) 509 e4App().getObject("ViewManager").enableEditorsCheckFocusIn(True)
508 if exitStatus == QProcess.NormalExit and exitCode == 0 and self.buf: 510 if exitStatus == QProcess.NormalExit and exitCode == 0 and self.buf:
509 ofn = os.path.join(self.project.ppath, self.compiledFile) 511 ofn = os.path.join(self.project.ppath, self.compiledFile)
510 try: 512 try:
511 f = open(ofn, "wb") 513 f = open(ofn, "w")
512 for line in self.buf.splitlines(): 514 for line in self.buf.splitlines():
513 f.write(line.encode("utf8") + os.linesep) 515 f.write(line + os.linesep)
514 f.close() 516 f.close()
515 if self.compiledFile not in self.project.pdata["SOURCES"]: 517 if self.compiledFile not in self.project.pdata["SOURCES"]:
516 self.project.appendFile(ofn) 518 self.project.appendFile(ofn)
517 if not self.noDialog: 519 if not self.noDialog:
518 QMessageBox.information(None, 520 QMessageBox.information(None,
519 self.trUtf8("Resource Compilation"), 521 self.trUtf8("Resource Compilation"),
520 self.trUtf8("The compilation of the resource file" 522 self.trUtf8("The compilation of the resource file"
521 " was successful.")) 523 " was successful."))
522 except IOError, msg: 524 except IOError as msg:
523 if not self.noDialog: 525 if not self.noDialog:
524 QMessageBox.information(None, 526 QMessageBox.information(None,
525 self.trUtf8("Resource Compilation"), 527 self.trUtf8("Resource Compilation"),
526 self.trUtf8("<p>The compilation of the resource file failed.</p>" 528 self.trUtf8("<p>The compilation of the resource file failed.</p>"
527 "<p>Reason: {0}</p>").format(unicode(msg))) 529 "<p>Reason: {0}</p>").format(str(msg)))
528 else: 530 else:
529 if not self.noDialog: 531 if not self.noDialog:
530 QMessageBox.information(None, 532 QMessageBox.information(None,
531 self.trUtf8("Resource Compilation"), 533 self.trUtf8("Resource Compilation"),
532 self.trUtf8("The compilation of the resource file failed.")) 534 self.trUtf8("The compilation of the resource file failed."))

eric ide

mercurial