eric6/ViewManager/ViewManager.py

branch
maintenance
changeset 7286
7eb04391adf7
parent 7214
f434af227a41
parent 7282
33e92c553b0b
child 7345
bc0ee7fadd03
equal deleted inserted replaced
7226:babe80d84a3e 7286:7eb04391adf7
5 5
6 """ 6 """
7 Module implementing the viewmanager base class. 7 Module implementing the viewmanager base class.
8 """ 8 """
9 9
10 from __future__ import unicode_literals
11 10
12 import os 11 import os
13 12
14 from PyQt5.QtCore import pyqtSignal, pyqtSlot, QSignalMapper, QTimer, \ 13 from PyQt5.QtCore import (
15 QFileInfo, QRegExp, Qt, QCoreApplication, QPoint 14 pyqtSignal, pyqtSlot, QSignalMapper, QTimer, QFileInfo, QRegExp, Qt,
15 QCoreApplication, QPoint
16 )
16 from PyQt5.QtGui import QColor, QKeySequence, QPalette, QPixmap 17 from PyQt5.QtGui import QColor, QKeySequence, QPalette, QPixmap
17 from PyQt5.QtWidgets import QLineEdit, QToolBar, QWidgetAction, QDialog, \ 18 from PyQt5.QtWidgets import (
18 QApplication, QMenu, QComboBox, QWidget 19 QLineEdit, QToolBar, QWidgetAction, QDialog, QApplication, QMenu,
20 QComboBox, QWidget
21 )
19 from PyQt5.Qsci import QsciScintilla 22 from PyQt5.Qsci import QsciScintilla
20 23
21 from E5Gui.E5Application import e5App 24 from E5Gui.E5Application import e5App
22 from E5Gui import E5FileDialog, E5MessageBox 25 from E5Gui import E5FileDialog, E5MessageBox
23 26
337 @return flag indicating cascading of windows is available 340 @return flag indicating cascading of windows is available
338 @exception RuntimeError Not implemented 341 @exception RuntimeError Not implemented
339 """ 342 """
340 raise RuntimeError('Not implemented') 343 raise RuntimeError('Not implemented')
341 344
345 return False
346
342 def canTile(self): 347 def canTile(self):
343 """ 348 """
344 Public method to signal if tiling of managed windows is available. 349 Public method to signal if tiling of managed windows is available.
345 350
346 @return flag indicating tiling of windows is available 351 @return flag indicating tiling of windows is available
347 @exception RuntimeError Not implemented 352 @exception RuntimeError Not implemented
348 """ 353 """
349 raise RuntimeError('Not implemented') 354 raise RuntimeError('Not implemented')
350 355
356 return False
357
351 def tile(self): 358 def tile(self):
352 """ 359 """
353 Public method to tile the managed windows. 360 Public method to tile the managed windows.
354 361
355 @exception RuntimeError Not implemented 362 @exception RuntimeError Not implemented
370 377
371 @return reference to the active editor 378 @return reference to the active editor
372 @exception RuntimeError Not implemented 379 @exception RuntimeError Not implemented
373 """ 380 """
374 raise RuntimeError('Not implemented') 381 raise RuntimeError('Not implemented')
382
383 return None # __IGNORE_WARNING_M831__
375 384
376 def _removeAllViews(self): 385 def _removeAllViews(self):
377 """ 386 """
378 Protected method to remove all views (i.e. windows). 387 Protected method to remove all views (i.e. windows).
379 388
1061 QCoreApplication.translate('ViewManager', 'Join Lines'), 1070 QCoreApplication.translate('ViewManager', 'Join Lines'),
1062 QCoreApplication.translate('ViewManager', 'Join Lines'), 1071 QCoreApplication.translate('ViewManager', 'Join Lines'),
1063 QKeySequence(QCoreApplication.translate( 1072 QKeySequence(QCoreApplication.translate(
1064 'ViewManager', "Ctrl+J", "Edit|Join Lines")), 1073 'ViewManager', "Ctrl+J", "Edit|Join Lines")),
1065 0, 1074 0,
1066 self.copyActGrp, 'vm_edit_join_lines') 1075 self.editActGrp, 'vm_edit_join_lines')
1067 self.joinAct.setStatusTip(QCoreApplication.translate( 1076 self.joinAct.setStatusTip(QCoreApplication.translate(
1068 'ViewManager', 'Join Lines')) 1077 'ViewManager', 'Join Lines'))
1069 self.joinAct.setWhatsThis(QCoreApplication.translate( 1078 self.joinAct.setWhatsThis(QCoreApplication.translate(
1070 'ViewManager', 1079 'ViewManager',
1071 """<b>Join Lines</b>""" 1080 """<b>Join Lines</b>"""
5439 self.sbZoom.setEnabled(False) 5448 self.sbZoom.setEnabled(False)
5440 else: 5449 else:
5441 self.sbZoom.setEnabled(True) 5450 self.sbZoom.setEnabled(True)
5442 self.sbZoom.setValue(now.getZoom()) 5451 self.sbZoom.setValue(now.getZoom())
5443 5452
5444 if not isinstance(now, (Editor, Shell)) and \ 5453 if (
5445 now is not self.quickFindtextCombo: 5454 not isinstance(now, (Editor, Shell)) and
5455 now is not self.quickFindtextCombo
5456 ):
5446 self.searchActGrp.setEnabled(False) 5457 self.searchActGrp.setEnabled(False)
5447 5458
5448 if now is self.quickFindtextCombo: 5459 if now is self.quickFindtextCombo:
5449 self.searchActGrp.setEnabled(True) 5460 self.searchActGrp.setEnabled(True)
5450 5461
5679 Private slot to handle the incremental quick search. 5690 Private slot to handle the incremental quick search.
5680 """ 5691 """
5681 # first we have to check if quick search is active 5692 # first we have to check if quick search is active
5682 # and try to activate it if not 5693 # and try to activate it if not
5683 if self.__quickSearchToolbarVisibility is None: 5694 if self.__quickSearchToolbarVisibility is None:
5684 self.__quickSearchToolbarVisibility = \ 5695 self.__quickSearchToolbarVisibility = (
5685 self.__quickSearchToolbar.isVisible() 5696 self.__quickSearchToolbar.isVisible()
5697 )
5686 if not self.__quickSearchToolbar.isVisible(): 5698 if not self.__quickSearchToolbar.isVisible():
5687 self.__quickSearchToolbar.show() 5699 self.__quickSearchToolbar.show()
5688 if not self.quickFindtextCombo.lineEdit().hasFocus(): 5700 if not self.quickFindtextCombo.lineEdit().hasFocus():
5689 aw = self.activeWindow() 5701 aw = self.activeWindow()
5690 self.quickFindtextCombo.lastActive = aw 5702 self.quickFindtextCombo.lastActive = aw
5750 Private slot to handle the quickFindPrev toolbutton action. 5762 Private slot to handle the quickFindPrev toolbutton action.
5751 """ 5763 """
5752 # first we have to check if quick search is active 5764 # first we have to check if quick search is active
5753 # and try to activate it if not 5765 # and try to activate it if not
5754 if self.__quickSearchToolbarVisibility is None: 5766 if self.__quickSearchToolbarVisibility is None:
5755 self.__quickSearchToolbarVisibility = \ 5767 self.__quickSearchToolbarVisibility = (
5756 self.__quickSearchToolbar.isVisible() 5768 self.__quickSearchToolbar.isVisible()
5769 )
5757 if not self.__quickSearchToolbar.isVisible(): 5770 if not self.__quickSearchToolbar.isVisible():
5758 self.__quickSearchToolbar.show() 5771 self.__quickSearchToolbar.show()
5759 if not self.quickFindtextCombo.lineEdit().hasFocus(): 5772 if not self.quickFindtextCombo.lineEdit().hasFocus():
5760 aw = self.activeWindow() 5773 aw = self.activeWindow()
5761 self.quickFindtextCombo.lastActive = aw 5774 self.quickFindtextCombo.lastActive = aw
6547 """<p>The spelling dictionary file <b>{0}</b> could""" 6560 """<p>The spelling dictionary file <b>{0}</b> could"""
6548 """ not be read.</p><p>Reason: {1}</p>""").format( 6561 """ not be read.</p><p>Reason: {1}</p>""").format(
6549 dictionaryFile, str(err))) 6562 dictionaryFile, str(err)))
6550 return 6563 return
6551 6564
6552 fileInfo = dictionaryFile if len(dictionaryFile) < 40 \ 6565 fileInfo = (
6566 dictionaryFile if len(dictionaryFile) < 40
6553 else "...{0}".format(dictionaryFile[-40:]) 6567 else "...{0}".format(dictionaryFile[-40:])
6554 from QScintilla.SpellingDictionaryEditDialog import \ 6568 )
6569 from QScintilla.SpellingDictionaryEditDialog import (
6555 SpellingDictionaryEditDialog 6570 SpellingDictionaryEditDialog
6571 )
6556 dlg = SpellingDictionaryEditDialog( 6572 dlg = SpellingDictionaryEditDialog(
6557 data, 6573 data,
6558 QCoreApplication.translate('ViewManager', "Editing {0}") 6574 QCoreApplication.translate('ViewManager', "Editing {0}")
6559 .format(fileInfo), 6575 .format(fileInfo),
6560 self.ui) 6576 self.ui)
6707 self.bookmarkActGrp.setEnabled(True) 6723 self.bookmarkActGrp.setEnabled(True)
6708 self.__enableSpellingActions() 6724 self.__enableSpellingActions()
6709 self.astViewerAct.setEnabled(True) 6725 self.astViewerAct.setEnabled(True)
6710 6726
6711 # activate the autosave timer 6727 # activate the autosave timer
6712 if not self.autosaveTimer.isActive() and \ 6728 if (
6713 self.autosaveInterval > 0: 6729 not self.autosaveTimer.isActive() and
6730 self.autosaveInterval > 0
6731 ):
6714 self.autosaveTimer.start(self.autosaveInterval * 60000) 6732 self.autosaveTimer.start(self.autosaveInterval * 60000)
6715 6733
6716 def __autosave(self): 6734 def __autosave(self):
6717 """ 6735 """
6718 Private slot to save the contents of all editors automatically. 6736 Private slot to save the contents of all editors automatically.
6868 editor.zoomTo(zoom) 6886 editor.zoomTo(zoom)
6869 6887
6870 # reload the autosave timer setting 6888 # reload the autosave timer setting
6871 self.autosaveInterval = Preferences.getEditor("AutosaveInterval") 6889 self.autosaveInterval = Preferences.getEditor("AutosaveInterval")
6872 if len(self.editors): 6890 if len(self.editors):
6873 if self.autosaveTimer.isActive() and \ 6891 if (
6874 self.autosaveInterval == 0: 6892 self.autosaveTimer.isActive() and
6893 self.autosaveInterval == 0
6894 ):
6875 self.autosaveTimer.stop() 6895 self.autosaveTimer.stop()
6876 elif not self.autosaveTimer.isActive() and \ 6896 elif (
6877 self.autosaveInterval > 0: 6897 not self.autosaveTimer.isActive() and
6898 self.autosaveInterval > 0
6899 ):
6878 self.autosaveTimer.start(self.autosaveInterval * 60000) 6900 self.autosaveTimer.start(self.autosaveInterval * 60000)
6879 6901
6880 self.__enableSpellingActions() 6902 self.__enableSpellingActions()
6881 6903
6882 def __editorSaved(self, fn, editor): 6904 def __editorSaved(self, fn, editor):
6988 """ 7010 """
6989 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
6990 cursor is not at the end of the line. 7012 cursor is not at the end of the line.
6991 """ 7013 """
6992 focusWidget = QApplication.focusWidget() 7014 focusWidget = QApplication.focusWidget()
6993 if focusWidget == e5App().getObject("Shell") or \ 7015 if (
6994 focusWidget == self.quickFindtextCombo: 7016 focusWidget == e5App().getObject("Shell") or
7017 focusWidget == self.quickFindtextCombo
7018 ):
6995 return 7019 return
6996 else: 7020 else:
6997 aw = self.activeWindow() 7021 aw = self.activeWindow()
6998 if aw: 7022 if aw:
6999 aw.newLineBelow() 7023 aw.newLineBelow()
7091 3: CWD 7115 3: CWD
7092 7116
7093 @return name of directory to start (string) 7117 @return name of directory to start (string)
7094 """ 7118 """
7095 # if we have an active source, return its path 7119 # if we have an active source, return its path
7096 if self.activeWindow() is not None and \ 7120 if (
7097 self.activeWindow().getFileName(): 7121 self.activeWindow() is not None and
7122 self.activeWindow().getFileName()
7123 ):
7098 return os.path.dirname(self.activeWindow().getFileName()) 7124 return os.path.dirname(self.activeWindow().getFileName())
7099 7125
7100 # check, if there is an active project and return its path 7126 # check, if there is an active project and return its path
7101 elif e5App().getObject("Project").isOpen(): 7127 elif e5App().getObject("Project").isOpen():
7102 return e5App().getObject("Project").ppath 7128 return e5App().getObject("Project").ppath
7103 7129
7104 else: 7130 else:
7105 return Preferences.getMultiProject("Workspace") or \ 7131 return (
7132 Preferences.getMultiProject("Workspace") or
7106 Utilities.getHomeDir() 7133 Utilities.getHomeDir()
7134 )
7107 7135
7108 def _getOpenFileFilter(self): 7136 def _getOpenFileFilter(self):
7109 """ 7137 """
7110 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
7111 dialog. 7139 dialog.
7113 The appropriate filename filter is determined by file extension of 7141 The appropriate filename filter is determined by file extension of
7114 the currently active editor. 7142 the currently active editor.
7115 7143
7116 @return name of the filename filter (string) or None 7144 @return name of the filename filter (string) or None
7117 """ 7145 """
7118 if self.activeWindow() is not None and \ 7146 if (
7119 self.activeWindow().getFileName(): 7147 self.activeWindow() is not None and
7148 self.activeWindow().getFileName()
7149 ):
7120 ext = os.path.splitext(self.activeWindow().getFileName())[1] 7150 ext = os.path.splitext(self.activeWindow().getFileName())[1]
7121 rx = QRegExp(r".*\*\.{0}[ )].*".format(ext[1:])) 7151 rx = QRegExp(r".*\*\.{0}[ )].*".format(ext[1:]))
7122 import QScintilla.Lexers 7152 import QScintilla.Lexers
7123 filters = QScintilla.Lexers.getOpenFileFiltersList() 7153 filters = QScintilla.Lexers.getOpenFileFiltersList()
7124 index = -1 7154 index = -1

eric ide

mercurial