UI/FindFileDialog.py

changeset 45
9a18f4dbb493
parent 42
23b45a742e17
child 53
c3eb7cc1ff8b
equal deleted inserted replaced
44:fe5cd20cb0eb 45:9a18f4dbb493
364 fn = os.path.join(self.project.ppath, file) 364 fn = os.path.join(self.project.ppath, file)
365 else: 365 else:
366 fn = file 366 fn = file
367 # read the file and split it into textlines 367 # read the file and split it into textlines
368 try: 368 try:
369 f = open(fn, 'r') 369 text, encoding = Utilities.readEncodedFile(fn)
370 text = f.read()
371 lines = text.splitlines() 370 lines = text.splitlines()
372 f.close() 371 except (UnicodeError, IOError):
373 except (IOError, UnicodeError):
374 progress += 1 372 progress += 1
375 self.findProgress.setValue(progress) 373 self.findProgress.setValue(progress)
376 continue 374 continue
377 375
378 # now perform the search and display the lines found 376 # now perform the search and display the lines found
523 else: 521 else:
524 fn = file 522 fn = file
525 523
526 # read the file and split it into textlines 524 # read the file and split it into textlines
527 try: 525 try:
528 f = open(fn, 'r') 526 text, encoding = Utilities.readEncodedFile(fn)
529 text = f.read()
530 lines = text.splitlines() 527 lines = text.splitlines()
531 f.close() 528 except (UnicodeError, IOError):
532 except IOError as err:
533 QMessageBox.critical(self, 529 QMessageBox.critical(self,
534 self.trUtf8("Replace in Files"), 530 self.trUtf8("Replace in Files"),
535 self.trUtf8("""<p>Could not read the file <b>{0}</b>.""" 531 self.trUtf8("""<p>Could not read the file <b>{0}</b>."""
536 """ Skipping it.</p><p>Reason: {1}</p>""")\ 532 """ Skipping it.</p><p>Reason: {1}</p>""")\
537 .format(fn, str(err)) 533 .format(fn, str(err))
549 lines[line - 1] = rline 545 lines[line - 1] = rline
550 546
551 # write the file 547 # write the file
552 txt = Utilities.linesep().join(lines) 548 txt = Utilities.linesep().join(lines)
553 try: 549 try:
554 f = open(fn, 'w') 550 Utilities.writeEncodedFile(fn, txt, encoding)
555 f.write(txt) 551 except (IOError, Utilities.CodingError, UnicodeError) as err:
556 f.close()
557 except IOError as err:
558 QMessageBox.critical(self, 552 QMessageBox.critical(self,
559 self.trUtf8("Replace in Files"), 553 self.trUtf8("Replace in Files"),
560 self.trUtf8("""<p>Could not save the file <b>{0}</b>.""" 554 self.trUtf8("""<p>Could not save the file <b>{0}</b>."""
561 """ Skipping it.</p><p>Reason: {1}</p>""")\ 555 """ Skipping it.</p><p>Reason: {1}</p>""")\
562 .format(fn, str(err)) 556 .format(fn, str(err))

eric ide

mercurial