QScintilla/Editor.py

changeset 53
c3eb7cc1ff8b
parent 45
9a18f4dbb493
child 55
b5c84934de9c
equal deleted inserted replaced
52:ba69827929ee 53:c3eb7cc1ff8b
13 13
14 from PyQt4.Qsci import QsciScintilla, QsciMacro 14 from PyQt4.Qsci import QsciScintilla, QsciMacro
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 e5App
19 19
20 from . import Exporters 20 from . import Exporters
21 from . import Lexers 21 from . import Lexers
22 from . import TypingCompleters 22 from . import TypingCompleters
23 from .QsciScintillaCompat import QsciScintillaCompat, QSCINTILLA_VERSION 23 from .QsciScintillaCompat import QsciScintillaCompat, QSCINTILLA_VERSION
1277 if self.lexer_ is not None and \ 1277 if self.lexer_ is not None and \
1278 (self.lexer_.lexer() == "container" or self.lexer_.lexer() is None): 1278 (self.lexer_.lexer() == "container" or self.lexer_.lexer() is None):
1279 self.disconnect(self, SIGNAL("SCN_STYLENEEDED(int)"), self.__styleNeeded) 1279 self.disconnect(self, SIGNAL("SCN_STYLENEEDED(int)"), self.__styleNeeded)
1280 1280
1281 language = "" 1281 language = ""
1282 project = e4App().getObject("Project") 1282 project = e5App().getObject("Project")
1283 if project.isOpen() and project.isProjectFile(filename): 1283 if project.isOpen() and project.isProjectFile(filename):
1284 language = project.getEditorLexerAssoc(os.path.basename(filename)) 1284 language = project.getEditorLexerAssoc(os.path.basename(filename))
1285 if not language: 1285 if not language:
1286 filename = os.path.basename(filename) 1286 filename = os.path.basename(filename)
1287 language = Preferences.getEditorLexerAssoc(filename) 1287 language = Preferences.getEditorLexerAssoc(filename)
1972 def printFile(self): 1972 def printFile(self):
1973 """ 1973 """
1974 Public slot to print the text. 1974 Public slot to print the text.
1975 """ 1975 """
1976 printer = Printer(mode = QPrinter.HighResolution) 1976 printer = Printer(mode = QPrinter.HighResolution)
1977 sb = e4App().getObject("UserInterface").statusBar() 1977 sb = e5App().getObject("UserInterface").statusBar()
1978 printDialog = QPrintDialog(printer, self) 1978 printDialog = QPrintDialog(printer, self)
1979 if self.hasSelectedText(): 1979 if self.hasSelectedText():
1980 printDialog.addEnabledOption(QAbstractPrintDialog.PrintSelection) 1980 printDialog.addEnabledOption(QAbstractPrintDialog.PrintSelection)
1981 if printDialog.exec_() == QDialog.Accepted: 1981 if printDialog.exec_() == QDialog.Accepted:
1982 sb.showMessage(self.trUtf8('Printing...')) 1982 sb.showMessage(self.trUtf8('Printing...'))
3777 """ 3777 """
3778 prEnable = False 3778 prEnable = False
3779 coEnable = False 3779 coEnable = False
3780 3780
3781 # first check if the file belongs to a project 3781 # first check if the file belongs to a project
3782 project = e4App().getObject("Project") 3782 project = e5App().getObject("Project")
3783 if project.isOpen() and project.isProjectSource(self.fileName): 3783 if project.isOpen() and project.isProjectSource(self.fileName):
3784 fn = project.getMainScript(True) 3784 fn = project.getMainScript(True)
3785 if fn is not None: 3785 if fn is not None:
3786 tfn = Utilities.getTestFileName(fn) 3786 tfn = Utilities.getTestFileName(fn)
3787 basename = os.path.splitext(fn)[0] 3787 basename = os.path.splitext(fn)[0]
3821 3821
3822 def __showContextMenuGraphics(self): 3822 def __showContextMenuGraphics(self):
3823 """ 3823 """
3824 Private slot handling the aboutToShow signal of the diagrams context menu. 3824 Private slot handling the aboutToShow signal of the diagrams context menu.
3825 """ 3825 """
3826 project = e4App().getObject("Project") 3826 project = e5App().getObject("Project")
3827 if project.isOpen() and project.isProjectSource(self.fileName): 3827 if project.isOpen() and project.isProjectSource(self.fileName):
3828 self.applicationDiagramMenuAct.setEnabled(True) 3828 self.applicationDiagramMenuAct.setEnabled(True)
3829 else: 3829 else:
3830 self.applicationDiagramMenuAct.setEnabled(False) 3830 self.applicationDiagramMenuAct.setEnabled(False)
3831 3831
4021 """ 4021 """
4022 files = [] 4022 files = []
4023 4023
4024 # first check if the file belongs to a project and there is 4024 # first check if the file belongs to a project and there is
4025 # a project coverage file 4025 # a project coverage file
4026 project = e4App().getObject("Project") 4026 project = e5App().getObject("Project")
4027 if project.isOpen() and project.isProjectSource(self.fileName): 4027 if project.isOpen() and project.isProjectSource(self.fileName):
4028 fn = project.getMainScript(True) 4028 fn = project.getMainScript(True)
4029 if fn is not None: 4029 if fn is not None:
4030 tfn = Utilities.getTestFileName(fn) 4030 tfn = Utilities.getTestFileName(fn)
4031 basename = os.path.splitext(fn)[0] 4031 basename = os.path.splitext(fn)[0]
4160 """ 4160 """
4161 files = [] 4161 files = []
4162 4162
4163 # first check if the file belongs to a project and there is 4163 # first check if the file belongs to a project and there is
4164 # a project profile file 4164 # a project profile file
4165 project = e4App().getObject("Project") 4165 project = e5App().getObject("Project")
4166 if project.isOpen() and project.isProjectSource(self.fileName): 4166 if project.isOpen() and project.isProjectSource(self.fileName):
4167 fn = project.getMainScript(True) 4167 fn = project.getMainScript(True)
4168 if fn is not None: 4168 if fn is not None:
4169 tfn = Utilities.getTestFileName(fn) 4169 tfn = Utilities.getTestFileName(fn)
4170 basename = os.path.splitext(fn)[0] 4170 basename = os.path.splitext(fn)[0]
4533 self.__changeBreakPoints) 4533 self.__changeBreakPoints)
4534 self.disconnect(self.breakpointModel, 4534 self.disconnect(self.breakpointModel,
4535 SIGNAL("rowsInserted(const QModelIndex &, int, int)"), 4535 SIGNAL("rowsInserted(const QModelIndex &, int, int)"),
4536 self.__addBreakPoints) 4536 self.__addBreakPoints)
4537 4537
4538 self.disconnect(e4App().getObject("Project"), SIGNAL("projectPropertiesChanged"), 4538 self.disconnect(e5App().getObject("Project"), SIGNAL("projectPropertiesChanged"),
4539 self.__projectPropertiesChanged) 4539 self.__projectPropertiesChanged)
4540 4540
4541 if self.spell: 4541 if self.spell:
4542 self.spell.stopIncrementalCheck() 4542 self.spell.stopIncrementalCheck()
4543 4543
4980 self.trUtf8("""Include module names?"""), 4980 self.trUtf8("""Include module names?"""),
4981 QMessageBox.StandardButtons(\ 4981 QMessageBox.StandardButtons(\
4982 QMessageBox.No | \ 4982 QMessageBox.No | \
4983 QMessageBox.Yes), 4983 QMessageBox.Yes),
4984 QMessageBox.Yes) 4984 QMessageBox.Yes)
4985 self.applicationDiagram = ApplicationDiagram(e4App().getObject("Project"), 4985 self.applicationDiagram = ApplicationDiagram(e5App().getObject("Project"),
4986 self, noModules = (res == QMessageBox.No)) 4986 self, noModules = (res == QMessageBox.No))
4987 self.applicationDiagram.show() 4987 self.applicationDiagram.show()
4988 4988
4989 ####################################################################### 4989 #######################################################################
4990 ## Typing aids related methods below 4990 ## Typing aids related methods below
5011 """ 5011 """
5012 if cmd == QsciScintilla.SCI_TAB: 5012 if cmd == QsciScintilla.SCI_TAB:
5013 line, index = self.getCursorPosition() 5013 line, index = self.getCursorPosition()
5014 tmplName = self.getWordLeft(line, index) 5014 tmplName = self.getWordLeft(line, index)
5015 if tmplName: 5015 if tmplName:
5016 if e4App().getObject("TemplateViewer").hasTemplate(tmplName): 5016 if e5App().getObject("TemplateViewer").hasTemplate(tmplName):
5017 self.__applyTemplate(tmplName) 5017 self.__applyTemplate(tmplName)
5018 return 5018 return
5019 else: 5019 else:
5020 templateNames = \ 5020 templateNames = \
5021 e4App().getObject("TemplateViewer").getTemplateNames(tmplName) 5021 e5App().getObject("TemplateViewer").getTemplateNames(tmplName)
5022 if len(templateNames) == 1: 5022 if len(templateNames) == 1:
5023 self.__applyTemplate(templateNames[0]) 5023 self.__applyTemplate(templateNames[0])
5024 return 5024 return
5025 elif len(templateNames) > 1: 5025 elif len(templateNames) > 1:
5026 self.showUserList(TemplateCompletionListID, 5026 self.showUserList(TemplateCompletionListID,
5043 """ 5043 """
5044 Private method to apply a template by name. 5044 Private method to apply a template by name.
5045 5045
5046 @param templateName name of the template to apply (string) 5046 @param templateName name of the template to apply (string)
5047 """ 5047 """
5048 if e4App().getObject("TemplateViewer").hasTemplate(templateName): 5048 if e5App().getObject("TemplateViewer").hasTemplate(templateName):
5049 self.extendSelectionWordLeft() 5049 self.extendSelectionWordLeft()
5050 e4App().getObject("TemplateViewer").applyNamedTemplate(templateName) 5050 e5App().getObject("TemplateViewer").applyNamedTemplate(templateName)
5051 5051
5052 ####################################################################### 5052 #######################################################################
5053 ## Project related methods 5053 ## Project related methods
5054 ####################################################################### 5054 #######################################################################
5055 5055
5056 def __projectPropertiesChanged(self): 5056 def __projectPropertiesChanged(self):
5057 """ 5057 """
5058 Private slot to handle changes of the project properties. 5058 Private slot to handle changes of the project properties.
5059 """ 5059 """
5060 project = e4App().getObject("Project") 5060 project = e5App().getObject("Project")
5061 if self.spell: 5061 if self.spell:
5062 pwl, pel = project.getProjectDictionaries() 5062 pwl, pel = project.getProjectDictionaries()
5063 self.__setSpellingLanguage(project.getProjectSpellLanguage(), 5063 self.__setSpellingLanguage(project.getProjectSpellLanguage(),
5064 pwl = pwl, pel = pel) 5064 pwl = pwl, pel = pel)
5065 5065
5066 def addedToProject(self): 5066 def addedToProject(self):
5067 """ 5067 """
5068 Public method to signal, that this editor has been added to a project. 5068 Public method to signal, that this editor has been added to a project.
5069 """ 5069 """
5070 project = e4App().getObject("Project") 5070 project = e5App().getObject("Project")
5071 if self.spell: 5071 if self.spell:
5072 pwl, pel = project.getProjectDictionaries() 5072 pwl, pel = project.getProjectDictionaries()
5073 self.__setSpellingLanguage(project.getProjectSpellLanguage(), 5073 self.__setSpellingLanguage(project.getProjectSpellLanguage(),
5074 pwl = pwl, pel = pel) 5074 pwl = pwl, pel = pel)
5075 self.connect(project, SIGNAL("projectPropertiesChanged"), 5075 self.connect(project, SIGNAL("projectPropertiesChanged"),
5099 self.__spellCheckStringsOnly = Preferences.getEditor("SpellCheckStringsOnly") 5099 self.__spellCheckStringsOnly = Preferences.getEditor("SpellCheckStringsOnly")
5100 if self.spell is None: 5100 if self.spell is None:
5101 self.spell = SpellChecker(self, self.spellingIndicator, 5101 self.spell = SpellChecker(self, self.spellingIndicator,
5102 checkRegion = self.isSpellCheckRegion) 5102 checkRegion = self.isSpellCheckRegion)
5103 self.setSpellingForProject() 5103 self.setSpellingForProject()
5104 self.connect(e4App().getObject("Project"), SIGNAL("projectPropertiesChanged"), 5104 self.connect(e5App().getObject("Project"), SIGNAL("projectPropertiesChanged"),
5105 self.__projectPropertiesChanged) 5105 self.__projectPropertiesChanged)
5106 self.spell.setMinimumWordSize( 5106 self.spell.setMinimumWordSize(
5107 Preferences.getEditor("SpellCheckingMinWordSize")) 5107 Preferences.getEditor("SpellCheckingMinWordSize"))
5108 5108
5109 self.setAutoSpellChecking() 5109 self.setAutoSpellChecking()
5114 def setSpellingForProject(self): 5114 def setSpellingForProject(self):
5115 """ 5115 """
5116 Public method to set the spell checking options for files belonging 5116 Public method to set the spell checking options for files belonging
5117 to the current project. 5117 to the current project.
5118 """ 5118 """
5119 project = e4App().getObject("Project") 5119 project = e5App().getObject("Project")
5120 if self.fileName and \ 5120 if self.fileName and \
5121 project.isOpen() and \ 5121 project.isOpen() and \
5122 project.isProjectSource(self.fileName): 5122 project.isProjectSource(self.fileName):
5123 pwl, pel = project.getProjectDictionaries() 5123 pwl, pel = project.getProjectDictionaries()
5124 self.__setSpellingLanguage(project.getProjectSpellLanguage(), 5124 self.__setSpellingLanguage(project.getProjectSpellLanguage(),

eric ide

mercurial