13 |
13 |
14 from PyQt5.QtCore import ( |
14 from PyQt5.QtCore import ( |
15 QSignalMapper, QPoint, QTimer, QFileInfo, pyqtSignal, QSize, QRegExp, Qt, |
15 QSignalMapper, QPoint, QTimer, QFileInfo, pyqtSignal, QSize, QRegExp, Qt, |
16 QCoreApplication |
16 QCoreApplication |
17 ) |
17 ) |
18 from PyQt5.QtGui import QCursor, QKeySequence, QPalette, QFont, QPixmap |
18 from PyQt5.QtGui import QKeySequence, QPalette, QFont, QPixmap |
19 from PyQt5.QtWidgets import ( |
19 from PyQt5.QtWidgets import ( |
20 QWidget, QWhatsThis, QActionGroup, QDialog, QInputDialog, QApplication, |
20 QWidget, QWhatsThis, QActionGroup, QDialog, QInputDialog, QApplication, |
21 QMenu, QVBoxLayout, QHBoxLayout, QLabel |
21 QMenu, QVBoxLayout, QHBoxLayout, QLabel |
22 ) |
22 ) |
23 from PyQt5.QtPrintSupport import QPrinter, QPrintDialog, QAbstractPrintDialog |
23 from PyQt5.QtPrintSupport import QPrinter, QPrintDialog, QAbstractPrintDialog |
26 from E5Gui.E5Action import E5Action, createActionGroup |
26 from E5Gui.E5Action import E5Action, createActionGroup |
27 from E5Gui import E5MessageBox, E5FileDialog |
27 from E5Gui import E5MessageBox, E5FileDialog |
28 from E5Gui.E5MainWindow import E5MainWindow |
28 from E5Gui.E5MainWindow import E5MainWindow |
29 from E5Gui.E5ClickableLabel import E5ClickableLabel |
29 from E5Gui.E5ClickableLabel import E5ClickableLabel |
30 from E5Gui.E5ZoomWidget import E5ZoomWidget |
30 from E5Gui.E5ZoomWidget import E5ZoomWidget |
|
31 from E5Gui.E5OverrideCursor import E5OverrideCursor |
31 |
32 |
32 from .QsciScintillaCompat import QsciScintillaCompat |
33 from .QsciScintillaCompat import QsciScintillaCompat |
33 |
34 |
34 import UI.PixmapCache |
35 import UI.PixmapCache |
35 import UI.Config |
36 import UI.Config |
2517 Private method to load the given file. |
2518 Private method to load the given file. |
2518 |
2519 |
2519 @param fileName name of the file to load (string) |
2520 @param fileName name of the file to load (string) |
2520 @param filetype type of the source file (string) |
2521 @param filetype type of the source file (string) |
2521 """ |
2522 """ |
2522 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
|
2523 |
|
2524 self.__loadEditorConfig(fileName=fileName) |
2523 self.__loadEditorConfig(fileName=fileName) |
2525 |
2524 |
2526 try: |
2525 try: |
2527 encoding = self.__getEditorConfig("DefaultEncoding", |
2526 with E5OverrideCursor(): |
2528 nodefault=True) |
2527 encoding = self.__getEditorConfig("DefaultEncoding", |
2529 if encoding: |
2528 nodefault=True) |
2530 txt, self.encoding = Utilities.readEncodedFileWithEncoding( |
2529 if encoding: |
2531 fileName, encoding) |
2530 txt, self.encoding = Utilities.readEncodedFileWithEncoding( |
2532 else: |
2531 fileName, encoding) |
2533 txt, self.encoding = Utilities.readEncodedFile(fileName) |
2532 else: |
|
2533 txt, self.encoding = Utilities.readEncodedFile(fileName) |
2534 except (UnicodeDecodeError, IOError) as why: |
2534 except (UnicodeDecodeError, IOError) as why: |
2535 QApplication.restoreOverrideCursor() |
|
2536 E5MessageBox.critical( |
2535 E5MessageBox.critical( |
2537 self, self.tr('Open File'), |
2536 self, self.tr('Open File'), |
2538 self.tr('<p>The file <b>{0}</b> could not be opened.</p>' |
2537 self.tr('<p>The file <b>{0}</b> could not be opened.</p>' |
2539 '<p>Reason: {1}</p>') |
2538 '<p>Reason: {1}</p>') |
2540 .format(fileName, str(why))) |
2539 .format(fileName, str(why))) |
2541 QApplication.restoreOverrideCursor() |
|
2542 return |
2540 return |
2543 |
2541 |
2544 self.__textEdit.setText(txt) |
2542 with E5OverrideCursor(): |
2545 QApplication.restoreOverrideCursor() |
2543 self.__textEdit.setText(txt) |
2546 |
2544 |
2547 if filetype is None: |
2545 if filetype is None: |
2548 self.filetype = "" |
2546 self.filetype = "" |
2549 else: |
2547 else: |
2550 self.filetype = filetype |
2548 self.filetype = filetype |
2551 self.__setCurrentFile(fileName) |
2549 self.__setCurrentFile(fileName) |
2552 |
2550 |
2553 self.__textEdit.setModified(False) |
2551 self.__textEdit.setModified(False) |
2554 self.setWindowModified(False) |
2552 self.setWindowModified(False) |
2555 |
2553 |
2556 self.__convertTabs() |
2554 self.__convertTabs() |
2557 |
2555 |
2558 eolMode = self.__getEditorConfig("EOLMode", nodefault=True) |
2556 eolMode = self.__getEditorConfig("EOLMode", nodefault=True) |
2559 if eolMode is None: |
2557 if eolMode is None: |
2560 fileEol = self.__textEdit.detectEolString(txt) |
2558 fileEol = self.__textEdit.detectEolString(txt) |
2561 self.__textEdit.setEolModeByEolString(fileEol) |
2559 self.__textEdit.setEolModeByEolString(fileEol) |
2562 else: |
2560 else: |
2563 self.__textEdit.convertEols(eolMode) |
2561 self.__textEdit.convertEols(eolMode) |
2564 |
2562 |
2565 self.__statusBar.showMessage(self.tr("File loaded"), 2000) |
2563 self.__statusBar.showMessage(self.tr("File loaded"), 2000) |
2566 |
2564 |
2567 def __convertTabs(self): |
2565 def __convertTabs(self): |
2568 """ |
2566 """ |
2610 @param fileName name of the file to be written to |
2608 @param fileName name of the file to be written to |
2611 @type str |
2609 @type str |
2612 @return flag indicating success |
2610 @return flag indicating success |
2613 @rtype bool |
2611 @rtype bool |
2614 """ |
2612 """ |
2615 QApplication.setOverrideCursor(Qt.WaitCursor) |
|
2616 |
|
2617 config = self.__loadEditorConfigObject(fileName) |
2613 config = self.__loadEditorConfigObject(fileName) |
2618 |
2614 |
2619 eol = self.__getEditorConfig("EOLMode", nodefault=True, config=config) |
2615 eol = self.__getEditorConfig("EOLMode", nodefault=True, config=config) |
2620 if eol is not None: |
2616 if eol is not None: |
2621 self.__textEdit.convertEols(eol) |
2617 self.__textEdit.convertEols(eol) |
2634 else: |
2630 else: |
2635 txt += eol |
2631 txt += eol |
2636 |
2632 |
2637 # now write text to the file |
2633 # now write text to the file |
2638 try: |
2634 try: |
2639 editorConfigEncoding = self.__getEditorConfig( |
2635 with E5OverrideCursor(): |
2640 "DefaultEncoding", nodefault=True, config=config) |
2636 editorConfigEncoding = self.__getEditorConfig( |
2641 self.encoding = Utilities.writeEncodedFile( |
2637 "DefaultEncoding", nodefault=True, config=config) |
2642 fileName, txt, self.encoding, |
2638 self.encoding = Utilities.writeEncodedFile( |
2643 forcedEncoding=editorConfigEncoding) |
2639 fileName, txt, self.encoding, |
|
2640 forcedEncoding=editorConfigEncoding) |
2644 except (IOError, Utilities.CodingError, UnicodeError) as why: |
2641 except (IOError, Utilities.CodingError, UnicodeError) as why: |
2645 QApplication.restoreOverrideCursor() |
|
2646 E5MessageBox.critical( |
2642 E5MessageBox.critical( |
2647 self, self.tr('Save File'), |
2643 self, self.tr('Save File'), |
2648 self.tr('<p>The file <b>{0}</b> could not be saved.<br/>' |
2644 self.tr('<p>The file <b>{0}</b> could not be saved.<br/>' |
2649 'Reason: {1}</p>') |
2645 'Reason: {1}</p>') |
2650 .format(fileName, str(why))) |
2646 .format(fileName, str(why))) |
2651 return False |
2647 return False |
2652 |
2648 |
2653 QApplication.restoreOverrideCursor() |
|
2654 self.__statusBar.showMessage(self.tr("File saved"), 2000) |
2649 self.__statusBar.showMessage(self.tr("File saved"), 2000) |
2655 |
2650 |
2656 return True |
2651 return True |
2657 |
2652 |
2658 def setWindowModified(self, modified): |
2653 def setWindowModified(self, modified): |