15 from PyQt4.QtCore import * |
15 from PyQt4.QtCore import * |
16 from PyQt4.QtGui import * |
16 from PyQt4.QtGui import * |
17 |
17 |
18 from E4Gui.E4Application import e4App |
18 from E4Gui.E4Application import e4App |
19 |
19 |
20 from Ui_FindFileDialog import Ui_FindFileDialog |
20 from .Ui_FindFileDialog import Ui_FindFileDialog |
21 |
21 |
22 import Utilities |
22 import Utilities |
23 import Preferences |
23 import Preferences |
24 |
24 |
25 class FindFileDialog(QDialog, Ui_FindFileDialog): |
25 class FindFileDialog(QDialog, Ui_FindFileDialog): |
285 if not self.filterCheckBox.isChecked(): |
285 if not self.filterCheckBox.isChecked(): |
286 filters = [] |
286 filters = [] |
287 if self.sourcesCheckBox.isChecked(): |
287 if self.sourcesCheckBox.isChecked(): |
288 filters.extend( |
288 filters.extend( |
289 ["^%s$" % assoc.replace(".", "\.").replace("*", ".*") \ |
289 ["^%s$" % assoc.replace(".", "\.").replace("*", ".*") \ |
290 for assoc in Preferences.getEditorLexerAssocs().keys() \ |
290 for assoc in list(Preferences.getEditorLexerAssocs().keys()) \ |
291 if assoc not in self.formsExt + self.interfacesExt]) |
291 if assoc not in self.formsExt + self.interfacesExt]) |
292 if self.formsCheckBox.isChecked(): |
292 if self.formsCheckBox.isChecked(): |
293 filters.append(self.filterForms) |
293 filters.append(self.filterForms) |
294 if self.interfacesCheckBox.isChecked(): |
294 if self.interfacesCheckBox.isChecked(): |
295 filters.append(self.filterInterfaces) |
295 filters.append(self.filterInterfaces) |
321 flags = re.UNICODE | re.LOCALE |
321 flags = re.UNICODE | re.LOCALE |
322 if not cs: |
322 if not cs: |
323 flags |= re.IGNORECASE |
323 flags |= re.IGNORECASE |
324 try: |
324 try: |
325 search = re.compile(txt, flags) |
325 search = re.compile(txt, flags) |
326 except re.error, why: |
326 except re.error as why: |
327 QMessageBox.critical(None, |
327 QMessageBox.critical(None, |
328 self.trUtf8("Invalid search expression"), |
328 self.trUtf8("Invalid search expression"), |
329 self.trUtf8("""<p>The search expression is not valid.</p>""" |
329 self.trUtf8("""<p>The search expression is not valid.</p>""" |
330 """<p>Error: {0}</p>""").format(unicode(why))) |
330 """<p>Error: {0}</p>""").format(str(why))) |
331 self.stopButton.setEnabled(False) |
331 self.stopButton.setEnabled(False) |
332 self.findButton.setEnabled(True) |
332 self.findButton.setEnabled(True) |
333 self.findButton.setDefault(True) |
333 self.findButton.setDefault(True) |
334 return |
334 return |
335 |
335 |
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, 'rb') |
369 f = open(fn, 'r') |
370 text, encoding = Utilities.decode(f.read()) |
370 text = f.read() |
371 lines = text.splitlines() |
371 lines = text.splitlines() |
372 f.close() |
372 f.close() |
373 except IOError: |
373 except IOError: |
374 progress += 1 |
374 progress += 1 |
375 self.findProgress.setValue(progress) |
375 self.findProgress.setValue(progress) |
519 else: |
519 else: |
520 fn = file |
520 fn = file |
521 |
521 |
522 # read the file and split it into textlines |
522 # read the file and split it into textlines |
523 try: |
523 try: |
524 f = open(fn, 'rb') |
524 f = open(fn, 'r') |
525 text, encoding = Utilities.decode(f.read()) |
525 text = f.read() |
526 lines = text.splitlines() |
526 lines = text.splitlines() |
527 f.close() |
527 f.close() |
528 except IOError, err: |
528 except IOError as err: |
529 QMessageBox.critical(self, |
529 QMessageBox.critical(self, |
530 self.trUtf8("Replace in Files"), |
530 self.trUtf8("Replace in Files"), |
531 self.trUtf8("""<p>Could not read the file <b>{0}</b>.""" |
531 self.trUtf8("""<p>Could not read the file <b>{0}</b>.""" |
532 """ Skipping it.</p><p>Reason: {1}</p>""")\ |
532 """ Skipping it.</p><p>Reason: {1}</p>""")\ |
533 .format(fn, unicode(err)) |
533 .format(fn, str(err)) |
534 ) |
534 ) |
535 progress += 1 |
535 progress += 1 |
536 self.findProgress.setValue(progress) |
536 self.findProgress.setValue(progress) |
537 continue |
537 continue |
538 |
538 |
544 rline = citm.data(0, self.replaceRole) |
544 rline = citm.data(0, self.replaceRole) |
545 lines[line - 1] = rline |
545 lines[line - 1] = rline |
546 |
546 |
547 # write the file |
547 # write the file |
548 txt = Utilities.linesep().join(lines) |
548 txt = Utilities.linesep().join(lines) |
549 txt, encoding = Utilities.encode(txt, encoding) |
|
550 try: |
549 try: |
551 f = open(fn, 'wb') |
550 f = open(fn, 'w') |
552 f.write(txt) |
551 f.write(txt) |
553 f.close() |
552 f.close() |
554 except IOError, err: |
553 except IOError as err: |
555 QMessageBox.critical(self, |
554 QMessageBox.critical(self, |
556 self.trUtf8("Replace in Files"), |
555 self.trUtf8("Replace in Files"), |
557 self.trUtf8("""<p>Could not save the file <b>{0}</b>.""" |
556 self.trUtf8("""<p>Could not save the file <b>{0}</b>.""" |
558 """ Skipping it.</p><p>Reason: {1}</p>""")\ |
557 """ Skipping it.</p><p>Reason: {1}</p>""")\ |
559 .format(fn, unicode(err)) |
558 .format(fn, str(err)) |
560 ) |
559 ) |
561 |
560 |
562 progress += 1 |
561 progress += 1 |
563 self.findProgress.setValue(progress) |
562 self.findProgress.setValue(progress) |
564 |
563 |