eric7/Project/ProjectResourcesBrowser.py

branch
eric7
changeset 9152
8a68afaf1ba2
parent 9150
0eab9aafa3b2
child 9153
506e35e424d5
equal deleted inserted replaced
9151:8c5296fe3056 9152:8a68afaf1ba2
7 Module implementing a class used to display the resources part of the project. 7 Module implementing a class used to display the resources part of the project.
8 """ 8 """
9 9
10 import os 10 import os
11 import contextlib 11 import contextlib
12 12 import pathlib
13 from PyQt6.QtCore import QThread, QFileInfo, pyqtSignal, QProcess 13
14 from PyQt6.QtCore import QThread, pyqtSignal, QProcess
14 from PyQt6.QtWidgets import QDialog, QApplication, QMenu 15 from PyQt6.QtWidgets import QDialog, QApplication, QMenu
15 16
16 from EricWidgets.EricApplication import ericApp 17 from EricWidgets.EricApplication import ericApp
17 from EricWidgets import EricMessageBox, EricFileDialog 18 from EricWidgets import EricMessageBox, EricFileDialog
18 from EricWidgets.EricProgressDialog import EricProgressDialog 19 from EricWidgets.EricProgressDialog import EricProgressDialog
475 476
476 if not fname: 477 if not fname:
477 # user aborted or didn't enter a filename 478 # user aborted or didn't enter a filename
478 return 479 return
479 480
480 ext = QFileInfo(fname).suffix() 481 fpath = pathlib.Path(fname)
481 if not ext: 482 if not fpath.suffix:
482 ex = selectedFilter.split("(*")[1].split(")")[0] 483 ex = selectedFilter.split("(*")[1].split(")")[0]
483 if ex: 484 if ex:
484 fname += ex 485 fpath = fpath.with_suffix(ex)
485 486 if fpath.exists():
486 if os.path.exists(fname):
487 res = EricMessageBox.yesNo( 487 res = EricMessageBox.yesNo(
488 self, 488 self,
489 self.tr("New Resource"), 489 self.tr("New Resource"),
490 self.tr("The file already exists! Overwrite it?"), 490 self.tr("The file already exists! Overwrite it?"),
491 icon=EricMessageBox.Warning) 491 icon=EricMessageBox.Warning)
494 return 494 return
495 495
496 try: 496 try:
497 newline = (None if self.project.useSystemEol() 497 newline = (None if self.project.useSystemEol()
498 else self.project.getEolString()) 498 else self.project.getEolString())
499 with open(fname, 'w', encoding="utf-8", 499 with fpath.open('w', encoding="utf-8",
500 newline=newline) as rcfile: 500 newline=newline) as rcfile:
501 rcfile.write('<!DOCTYPE RCC>\n') 501 rcfile.write('<!DOCTYPE RCC>\n')
502 rcfile.write('<RCC version="1.0">\n') 502 rcfile.write('<RCC version="1.0">\n')
503 rcfile.write('<qresource>\n') 503 rcfile.write('<qresource>\n')
504 rcfile.write('</qresource>\n') 504 rcfile.write('</qresource>\n')
505 rcfile.write('</RCC>\n') 505 rcfile.write('</RCC>\n')
508 self, 508 self,
509 self.tr("New Resource"), 509 self.tr("New Resource"),
510 self.tr( 510 self.tr(
511 "<p>The new resource file <b>{0}</b> could not" 511 "<p>The new resource file <b>{0}</b> could not"
512 " be created.<br>Problem: {1}</p>") 512 " be created.<br>Problem: {1}</p>")
513 .format(fname, str(e))) 513 .format(str(fpath), str(e)))
514 return 514 return
515 515
516 self.project.appendFile(fname) 516 self.project.appendFile(str(fpath))
517 self.sourceFile.emit(fname) 517 self.sourceFile.emit(str(fpath))
518 518
519 def __deleteFile(self): 519 def __deleteFile(self):
520 """ 520 """
521 Private method to delete a resource file from the project. 521 Private method to delete a resource file from the project.
522 """ 522 """

eric ide

mercurial