eric6/ViewManager/ViewManager.py

changeset 7259
7c017076c12e
parent 7229
53054eb5b15a
child 7277
adecbc6335c5
equal deleted inserted replaced
7258:aff39db4dacc 7259:7c017076c12e
8 """ 8 """
9 9
10 10
11 import os 11 import os
12 12
13 from PyQt5.QtCore import pyqtSignal, pyqtSlot, QSignalMapper, QTimer, \ 13 from PyQt5.QtCore import (
14 QFileInfo, QRegExp, Qt, QCoreApplication, QPoint 14 pyqtSignal, pyqtSlot, QSignalMapper, QTimer, QFileInfo, QRegExp, Qt,
15 QCoreApplication, QPoint
16 )
15 from PyQt5.QtGui import QColor, QKeySequence, QPalette, QPixmap 17 from PyQt5.QtGui import QColor, QKeySequence, QPalette, QPixmap
16 from PyQt5.QtWidgets import QLineEdit, QToolBar, QWidgetAction, QDialog, \ 18 from PyQt5.QtWidgets import (
17 QApplication, QMenu, QComboBox, QWidget 19 QLineEdit, QToolBar, QWidgetAction, QDialog, QApplication, QMenu,
20 QComboBox, QWidget
21 )
18 from PyQt5.Qsci import QsciScintilla 22 from PyQt5.Qsci import QsciScintilla
19 23
20 from E5Gui.E5Application import e5App 24 from E5Gui.E5Application import e5App
21 from E5Gui import E5FileDialog, E5MessageBox 25 from E5Gui import E5FileDialog, E5MessageBox
22 26
5444 self.sbZoom.setEnabled(False) 5448 self.sbZoom.setEnabled(False)
5445 else: 5449 else:
5446 self.sbZoom.setEnabled(True) 5450 self.sbZoom.setEnabled(True)
5447 self.sbZoom.setValue(now.getZoom()) 5451 self.sbZoom.setValue(now.getZoom())
5448 5452
5449 if not isinstance(now, (Editor, Shell)) and \ 5453 if (
5450 now is not self.quickFindtextCombo: 5454 not isinstance(now, (Editor, Shell)) and
5455 now is not self.quickFindtextCombo
5456 ):
5451 self.searchActGrp.setEnabled(False) 5457 self.searchActGrp.setEnabled(False)
5452 5458
5453 if now is self.quickFindtextCombo: 5459 if now is self.quickFindtextCombo:
5454 self.searchActGrp.setEnabled(True) 5460 self.searchActGrp.setEnabled(True)
5455 5461
5684 Private slot to handle the incremental quick search. 5690 Private slot to handle the incremental quick search.
5685 """ 5691 """
5686 # first we have to check if quick search is active 5692 # first we have to check if quick search is active
5687 # and try to activate it if not 5693 # and try to activate it if not
5688 if self.__quickSearchToolbarVisibility is None: 5694 if self.__quickSearchToolbarVisibility is None:
5689 self.__quickSearchToolbarVisibility = \ 5695 self.__quickSearchToolbarVisibility = (
5690 self.__quickSearchToolbar.isVisible() 5696 self.__quickSearchToolbar.isVisible()
5697 )
5691 if not self.__quickSearchToolbar.isVisible(): 5698 if not self.__quickSearchToolbar.isVisible():
5692 self.__quickSearchToolbar.show() 5699 self.__quickSearchToolbar.show()
5693 if not self.quickFindtextCombo.lineEdit().hasFocus(): 5700 if not self.quickFindtextCombo.lineEdit().hasFocus():
5694 aw = self.activeWindow() 5701 aw = self.activeWindow()
5695 self.quickFindtextCombo.lastActive = aw 5702 self.quickFindtextCombo.lastActive = aw
5755 Private slot to handle the quickFindPrev toolbutton action. 5762 Private slot to handle the quickFindPrev toolbutton action.
5756 """ 5763 """
5757 # first we have to check if quick search is active 5764 # first we have to check if quick search is active
5758 # and try to activate it if not 5765 # and try to activate it if not
5759 if self.__quickSearchToolbarVisibility is None: 5766 if self.__quickSearchToolbarVisibility is None:
5760 self.__quickSearchToolbarVisibility = \ 5767 self.__quickSearchToolbarVisibility = (
5761 self.__quickSearchToolbar.isVisible() 5768 self.__quickSearchToolbar.isVisible()
5769 )
5762 if not self.__quickSearchToolbar.isVisible(): 5770 if not self.__quickSearchToolbar.isVisible():
5763 self.__quickSearchToolbar.show() 5771 self.__quickSearchToolbar.show()
5764 if not self.quickFindtextCombo.lineEdit().hasFocus(): 5772 if not self.quickFindtextCombo.lineEdit().hasFocus():
5765 aw = self.activeWindow() 5773 aw = self.activeWindow()
5766 self.quickFindtextCombo.lastActive = aw 5774 self.quickFindtextCombo.lastActive = aw
6552 """<p>The spelling dictionary file <b>{0}</b> could""" 6560 """<p>The spelling dictionary file <b>{0}</b> could"""
6553 """ not be read.</p><p>Reason: {1}</p>""").format( 6561 """ not be read.</p><p>Reason: {1}</p>""").format(
6554 dictionaryFile, str(err))) 6562 dictionaryFile, str(err)))
6555 return 6563 return
6556 6564
6557 fileInfo = dictionaryFile if len(dictionaryFile) < 40 \ 6565 fileInfo = (
6566 dictionaryFile if len(dictionaryFile) < 40
6558 else "...{0}".format(dictionaryFile[-40:]) 6567 else "...{0}".format(dictionaryFile[-40:])
6559 from QScintilla.SpellingDictionaryEditDialog import \ 6568 )
6569 from QScintilla.SpellingDictionaryEditDialog import (
6560 SpellingDictionaryEditDialog 6570 SpellingDictionaryEditDialog
6571 )
6561 dlg = SpellingDictionaryEditDialog( 6572 dlg = SpellingDictionaryEditDialog(
6562 data, 6573 data,
6563 QCoreApplication.translate('ViewManager', "Editing {0}") 6574 QCoreApplication.translate('ViewManager', "Editing {0}")
6564 .format(fileInfo), 6575 .format(fileInfo),
6565 self.ui) 6576 self.ui)
6712 self.bookmarkActGrp.setEnabled(True) 6723 self.bookmarkActGrp.setEnabled(True)
6713 self.__enableSpellingActions() 6724 self.__enableSpellingActions()
6714 self.astViewerAct.setEnabled(True) 6725 self.astViewerAct.setEnabled(True)
6715 6726
6716 # activate the autosave timer 6727 # activate the autosave timer
6717 if not self.autosaveTimer.isActive() and \ 6728 if (
6718 self.autosaveInterval > 0: 6729 not self.autosaveTimer.isActive() and
6730 self.autosaveInterval > 0
6731 ):
6719 self.autosaveTimer.start(self.autosaveInterval * 60000) 6732 self.autosaveTimer.start(self.autosaveInterval * 60000)
6720 6733
6721 def __autosave(self): 6734 def __autosave(self):
6722 """ 6735 """
6723 Private slot to save the contents of all editors automatically. 6736 Private slot to save the contents of all editors automatically.
6873 editor.zoomTo(zoom) 6886 editor.zoomTo(zoom)
6874 6887
6875 # reload the autosave timer setting 6888 # reload the autosave timer setting
6876 self.autosaveInterval = Preferences.getEditor("AutosaveInterval") 6889 self.autosaveInterval = Preferences.getEditor("AutosaveInterval")
6877 if len(self.editors): 6890 if len(self.editors):
6878 if self.autosaveTimer.isActive() and \ 6891 if (
6879 self.autosaveInterval == 0: 6892 self.autosaveTimer.isActive() and
6893 self.autosaveInterval == 0
6894 ):
6880 self.autosaveTimer.stop() 6895 self.autosaveTimer.stop()
6881 elif not self.autosaveTimer.isActive() and \ 6896 elif (
6882 self.autosaveInterval > 0: 6897 not self.autosaveTimer.isActive() and
6898 self.autosaveInterval > 0
6899 ):
6883 self.autosaveTimer.start(self.autosaveInterval * 60000) 6900 self.autosaveTimer.start(self.autosaveInterval * 60000)
6884 6901
6885 self.__enableSpellingActions() 6902 self.__enableSpellingActions()
6886 6903
6887 def __editorSaved(self, fn, editor): 6904 def __editorSaved(self, fn, editor):
6993 """ 7010 """
6994 Private method to insert a new line below the current one even if 7011 Private method to insert a new line below the current one even if
6995 cursor is not at the end of the line. 7012 cursor is not at the end of the line.
6996 """ 7013 """
6997 focusWidget = QApplication.focusWidget() 7014 focusWidget = QApplication.focusWidget()
6998 if focusWidget == e5App().getObject("Shell") or \ 7015 if (
6999 focusWidget == self.quickFindtextCombo: 7016 focusWidget == e5App().getObject("Shell") or
7017 focusWidget == self.quickFindtextCombo
7018 ):
7000 return 7019 return
7001 else: 7020 else:
7002 aw = self.activeWindow() 7021 aw = self.activeWindow()
7003 if aw: 7022 if aw:
7004 aw.newLineBelow() 7023 aw.newLineBelow()
7096 3: CWD 7115 3: CWD
7097 7116
7098 @return name of directory to start (string) 7117 @return name of directory to start (string)
7099 """ 7118 """
7100 # if we have an active source, return its path 7119 # if we have an active source, return its path
7101 if self.activeWindow() is not None and \ 7120 if (
7102 self.activeWindow().getFileName(): 7121 self.activeWindow() is not None and
7122 self.activeWindow().getFileName()
7123 ):
7103 return os.path.dirname(self.activeWindow().getFileName()) 7124 return os.path.dirname(self.activeWindow().getFileName())
7104 7125
7105 # check, if there is an active project and return its path 7126 # check, if there is an active project and return its path
7106 elif e5App().getObject("Project").isOpen(): 7127 elif e5App().getObject("Project").isOpen():
7107 return e5App().getObject("Project").ppath 7128 return e5App().getObject("Project").ppath
7108 7129
7109 else: 7130 else:
7110 return Preferences.getMultiProject("Workspace") or \ 7131 return (
7132 Preferences.getMultiProject("Workspace") or
7111 Utilities.getHomeDir() 7133 Utilities.getHomeDir()
7134 )
7112 7135
7113 def _getOpenFileFilter(self): 7136 def _getOpenFileFilter(self):
7114 """ 7137 """
7115 Protected method to return the active filename filter for a file open 7138 Protected method to return the active filename filter for a file open
7116 dialog. 7139 dialog.
7118 The appropriate filename filter is determined by file extension of 7141 The appropriate filename filter is determined by file extension of
7119 the currently active editor. 7142 the currently active editor.
7120 7143
7121 @return name of the filename filter (string) or None 7144 @return name of the filename filter (string) or None
7122 """ 7145 """
7123 if self.activeWindow() is not None and \ 7146 if (
7124 self.activeWindow().getFileName(): 7147 self.activeWindow() is not None and
7148 self.activeWindow().getFileName()
7149 ):
7125 ext = os.path.splitext(self.activeWindow().getFileName())[1] 7150 ext = os.path.splitext(self.activeWindow().getFileName())[1]
7126 rx = QRegExp(r".*\*\.{0}[ )].*".format(ext[1:])) 7151 rx = QRegExp(r".*\*\.{0}[ )].*".format(ext[1:]))
7127 import QScintilla.Lexers 7152 import QScintilla.Lexers
7128 filters = QScintilla.Lexers.getOpenFileFiltersList() 7153 filters = QScintilla.Lexers.getOpenFileFiltersList()
7129 index = -1 7154 index = -1

eric ide

mercurial