def removeErrorHighlighting(self): #Unhighlight a line if showErrorLine was called earlier if self.errorLineStart >= 0: HighlightingStyledDocument.updateHighlightingInRange( self, self.errorLineStart, self.errorLineLen) self.errorLineStart = -1 self.errorLineLen = -1
def insertString(self, offset, str, a, addUndoEvent=1): if self.needToSetEnvironment: # Give the environment and key words to the Highlighting Document self.setEnvironmentWords(self.editor.program.getVarsToHighlight()) self.setKeywords(keyword.kwlist) self.needToSetEnvironment = 0 if self.errorLineStart >= 0: self.removeErrorHighlighting() if self.highlightLineStart >= 0: self.removeLineHighlighting() if str == '\t': str = " " # Added to make auto indent work if str == '\n': defaultElement = self.getDefaultRootElement() rowIndex = defaultElement.getElementIndex(offset) rowStart = defaultElement.getElement(rowIndex).getStartOffset() rowEnd = defaultElement.getElement(rowIndex).getEndOffset() - 1 rowText = self.getText( rowStart, rowEnd - rowStart) # .expandtabs() newRowText = rowText.lstrip() numSpaces = (len(rowText) - len(newRowText)) str = "\n" + (" " * numSpaces) self.editor.modified = 1 self.editor.gui.loadButton.enabled = 1 if addUndoEvent: self.addUndoEvent(INSERT_EVENT, offset, str) HighlightingStyledDocument.insertString(self, offset, str, self.textAttrib)
def removeErrorHighlighting(self): #Unhighlight a line if showErrorLine was called earlier if self.errorLineStart >= 0: HighlightingStyledDocument.updateHighlightingInRange(self, self.errorLineStart, self.errorLineLen) self.errorLineStart = -1 self.errorLineLen = -1
def insertString(self, offset, str, a, addUndoEvent=1): if self.needToSetEnvironment: # Give the environment and key words to the Highlighting Document self.setEnvironmentWords(self.editor.program.getVarsToHighlight()) self.setKeywords(keyword.kwlist) self.needToSetEnvironment = 0 if self.errorLineStart >= 0: self.removeErrorHighlighting() if self.highlightLineStart >= 0: self.removeLineHighlighting() if str == '\t': str = " " # Added to make auto indent work if str == '\n': defaultElement = self.getDefaultRootElement() rowIndex = defaultElement.getElementIndex(offset) rowStart = defaultElement.getElement(rowIndex).getStartOffset() rowEnd = defaultElement.getElement(rowIndex).getEndOffset() - 1 rowText = self.getText(rowStart, rowEnd - rowStart) # .expandtabs() newRowText = rowText.lstrip() numSpaces = (len(rowText) - len(newRowText)) str = "\n" + (" " * numSpaces) self.editor.modified = 1 self.editor.gui.loadButton.enabled = 1 if addUndoEvent: self.addUndoEvent(INSERT_EVENT, offset, str) HighlightingStyledDocument.insertString(self, offset, str, self.textAttrib)
def remove(self, offset, len, addUndoEvent=1): if self.errorLineStart >= 0: self.removeErrorHighlighting() if self.highlightLineStart >= 0: self.removeLineHighlighting() self.editor.modified = 1 self.editor.gui.loadButton.enabled = 1 if addUndoEvent: self.addUndoEvent(REMOVE_EVENT, offset, self.getText(offset, len)) HighlightingStyledDocument.remove(self, offset, len)
def changeFontSize(self, fontSize): newFontSize = int(fontSize) swing.text.StyleConstants.setFontSize(self.errorLineAttrib, newFontSize) swing.text.StyleConstants.setFontSize(self.commentAttrib, newFontSize) swing.text.StyleConstants.setFontSize(self.stringAttrib, newFontSize) swing.text.StyleConstants.setFontSize(self.textAttrib, newFontSize) swing.text.StyleConstants.setFontSize(self.jesEnvironmentWordAttrib, newFontSize) swing.text.StyleConstants.setFontSize(self.rParenAttrib, newFontSize) swing.text.StyleConstants.setFontSize(self.lParenAttrib, newFontSize); swing.text.StyleConstants.setFontSize(self.keywordAttrib, newFontSize) HighlightingStyledDocument.updateHighlightingInRange(self, 0, HighlightingStyledDocument.getLength(self)) self.editor.gui.gutter.repaint()
def changeFontSize(self, fontSize): newFontSize = int(fontSize) swing.text.StyleConstants.setFontSize(self.errorLineAttrib, newFontSize) swing.text.StyleConstants.setFontSize(self.commentAttrib, newFontSize) swing.text.StyleConstants.setFontSize(self.stringAttrib, newFontSize) swing.text.StyleConstants.setFontSize(self.textAttrib, newFontSize) swing.text.StyleConstants.setFontSize(self.jesEnvironmentWordAttrib, newFontSize) swing.text.StyleConstants.setFontSize(self.rParenAttrib, newFontSize) swing.text.StyleConstants.setFontSize(self.lParenAttrib, newFontSize) swing.text.StyleConstants.setFontSize(self.keywordAttrib, newFontSize) HighlightingStyledDocument.updateHighlightingInRange( self, 0, HighlightingStyledDocument.getLength(self)) self.editor.gui.gutter.repaint()
def showErrorLine(self, lineNumber): #remove any old error highlighting, because we only want to show one error # at a time. Plus, the system only keeps track of one error, so we need to # unhighlight the old error before setting the new one (AW 5/15/03) if self.errorLineStart >= 0: self.removeErrorHighlighting() #Search for the start offset of the error line docText = self.getText(0, self.getLength()) line = 1 offset = 0 while line < lineNumber: offset = docText.find('\n', offset) + 1 line += 1 #Search for the end offset of the error line #offset += 1 endOffset = docText.find('\n', offset) if endOffset == -1: endOffset = len(docText) #Set error line position and length object variables self.errorLineStart = offset self.errorLineLen = endOffset - offset #Set the correct text attribute for the error line HighlightingStyledDocument.setCharacterAttributes(self, self.errorLineStart, self.errorLineLen, self.errorLineAttrib, 1) #Set cusor to error line to ensure that the error line will be visible self.editor.setCaretPosition(self.errorLineStart)
def showErrorLine(self, lineNumber): #remove any old error highlighting, because we only want to show one error # at a time. Plus, the system only keeps track of one error, so we need to # unhighlight the old error before setting the new one (AW 5/15/03) if self.errorLineStart >= 0: self.removeErrorHighlighting() #Search for the start offset of the error line docText = self.getText(0, self.getLength()) line = 1 offset = 0 while line < lineNumber: offset = docText.find('\n', offset) + 1 line += 1 #Search for the end offset of the error line #offset += 1 endOffset = docText.find('\n', offset) if endOffset == -1: endOffset = len(docText) #Set error line position and length object variables self.errorLineStart = offset self.errorLineLen = endOffset - offset #Set the correct text attribute for the error line HighlightingStyledDocument.setCharacterAttributes( self, self.errorLineStart, self.errorLineLen, self.errorLineAttrib, 1) #Set cusor to error line to ensure that the error line will be visible self.editor.setCaretPosition(self.errorLineStart)
def __init__(self, editor): self.editor = editor self.textAttrib = swing.text.SimpleAttributeSet() self.keywordAttrib = swing.text.SimpleAttributeSet() self.jesEnvironmentWordAttrib = swing.text.SimpleAttributeSet() self.errorLineAttrib = swing.text.SimpleAttributeSet() self.highlightLineAttrib = swing.text.SimpleAttributeSet() self.commentAttrib = swing.text.SimpleAttributeSet() self.stringAttrib = swing.text.SimpleAttributeSet() self.lParenAttrib = swing.text.SimpleAttributeSet() self.rParenAttrib = swing.text.SimpleAttributeSet() self.needToSetEnvironment = 1 self.fontSize = JESConfig.getInstance().getIntegerProperty( JESConfig.CONFIG_FONT) swing.text.StyleConstants.setForeground(self.stringAttrib, JESConstants.STRING_COLOR) swing.text.StyleConstants.setFontFamily(self.stringAttrib, "Monospaced") swing.text.StyleConstants.setForeground(self.commentAttrib, JESConstants.COMMENT_COLOR) swing.text.StyleConstants.setFontFamily(self.commentAttrib, "Monospaced") swing.text.StyleConstants.setForeground( self.jesEnvironmentWordAttrib, JESConstants.ENVIRONMENT_WORD_COLOR) swing.text.StyleConstants.setBold(self.jesEnvironmentWordAttrib, KEYWORD_BOLD) swing.text.StyleConstants.setFontSize(self.jesEnvironmentWordAttrib, self.fontSize) swing.text.StyleConstants.setFontSize(self.textAttrib, self.fontSize) swing.text.StyleConstants.setBackground(self.textAttrib, awt.Color.white) swing.text.StyleConstants.setFontFamily(self.jesEnvironmentWordAttrib, "Monospaced") swing.text.StyleConstants.setFontFamily(self.textAttrib, "Monospaced") swing.text.StyleConstants.setForeground(self.keywordAttrib, JESConstants.KEYWORD_COLOR) swing.text.StyleConstants.setBold(self.keywordAttrib, KEYWORD_BOLD) swing.text.StyleConstants.setFontSize(self.keywordAttrib, self.fontSize) swing.text.StyleConstants.setFontFamily(self.keywordAttrib, "Monospaced") swing.text.StyleConstants.setForeground(self.lParenAttrib, JESConstants.LPAREN_COLOR) swing.text.StyleConstants.setBold(self.lParenAttrib, INVALID_PAREN_BOLD) swing.text.StyleConstants.setFontSize(self.lParenAttrib, self.fontSize) swing.text.StyleConstants.setFontFamily(self.lParenAttrib, "Monospaced") swing.text.StyleConstants.setForeground(self.rParenAttrib, JESConstants.RPAREN_COLOR) swing.text.StyleConstants.setBold(self.rParenAttrib, INVALID_PAREN_BOLD) swing.text.StyleConstants.setFontSize(self.rParenAttrib, self.fontSize) swing.text.StyleConstants.setFontFamily(self.rParenAttrib, "Monospaced") swing.text.StyleConstants.setForeground(self.errorLineAttrib, ERROR_LINE_FONT_COLOR) swing.text.StyleConstants.setBackground(self.errorLineAttrib, ERROR_LINE_BACKGROUND_COLOR) swing.text.StyleConstants.setFontFamily(self.errorLineAttrib, "Monospaced") swing.text.StyleConstants.setForeground(self.highlightLineAttrib, HIGHLIGHT_LINE_FONT_COLOR) swing.text.StyleConstants.setBackground( self.highlightLineAttrib, HIGHLIGHT_LINE_BACKGROUND_COLOR) swing.text.StyleConstants.setFontFamily(self.highlightLineAttrib, "Monospaced") #self.undoEvents = [] #Sets up the UndoManager which handles all undos/redos self.undoManager = swing.undo.UndoManager() self.undoManager.setLimit(MAX_UNDO_EVENTS_TO_RETAIN) HighlightingStyledDocument.setKeywordStyle(self, self.keywordAttrib) HighlightingStyledDocument.setEnvironmentWordStyle( self, self.jesEnvironmentWordAttrib) HighlightingStyledDocument.setStringStyle(self, self.stringAttrib) HighlightingStyledDocument.setLParenStyle(self, self.lParenAttrib) HighlightingStyledDocument.setRParenStyle(self, self.rParenAttrib) HighlightingStyledDocument.setCommentStyle(self, self.commentAttrib) HighlightingStyledDocument.setDefaultStyle(self, self.textAttrib) #The following variables are set when showErrorLine is called. They #are then used to unhighlight the line when the next text modification #is made. self.errorLineStart = -1 self.errorLineLen = -1 self.highlightLineStart = -1 self.highlightLineLen = -1
def __init__(self, editor): self.editor = editor self.textAttrib = swing.text.SimpleAttributeSet() self.keywordAttrib = swing.text.SimpleAttributeSet() self.jesEnvironmentWordAttrib = swing.text.SimpleAttributeSet() self.errorLineAttrib = swing.text.SimpleAttributeSet() self.highlightLineAttrib = swing.text.SimpleAttributeSet() self.commentAttrib = swing.text.SimpleAttributeSet() self.stringAttrib = swing.text.SimpleAttributeSet() self.lParenAttrib = swing.text.SimpleAttributeSet() self.rParenAttrib = swing.text.SimpleAttributeSet() self.needToSetEnvironment = 1 self.fontSize = JESConfig.getInstance().getIntegerProperty( JESConfig.CONFIG_FONT ) swing.text.StyleConstants.setForeground(self.stringAttrib, JESConstants.STRING_COLOR) swing.text.StyleConstants.setFontFamily(self.stringAttrib, "Monospaced"); swing.text.StyleConstants.setForeground(self.commentAttrib, JESConstants.COMMENT_COLOR) swing.text.StyleConstants.setFontFamily(self.commentAttrib, "Monospaced"); swing.text.StyleConstants.setForeground(self.jesEnvironmentWordAttrib, JESConstants.ENVIRONMENT_WORD_COLOR) swing.text.StyleConstants.setBold(self.jesEnvironmentWordAttrib, KEYWORD_BOLD) swing.text.StyleConstants.setFontSize(self.jesEnvironmentWordAttrib, self.fontSize) swing.text.StyleConstants.setFontSize(self.textAttrib, self.fontSize) swing.text.StyleConstants.setBackground(self.textAttrib, awt.Color.white) swing.text.StyleConstants.setFontFamily(self.jesEnvironmentWordAttrib, "Monospaced"); swing.text.StyleConstants.setFontFamily(self.textAttrib, "Monospaced"); swing.text.StyleConstants.setForeground(self.keywordAttrib, JESConstants.KEYWORD_COLOR) swing.text.StyleConstants.setBold(self.keywordAttrib, KEYWORD_BOLD) swing.text.StyleConstants.setFontSize(self.keywordAttrib, self.fontSize) swing.text.StyleConstants.setFontFamily(self.keywordAttrib, "Monospaced"); swing.text.StyleConstants.setForeground(self.lParenAttrib, JESConstants.LPAREN_COLOR) swing.text.StyleConstants.setBold(self.lParenAttrib, INVALID_PAREN_BOLD) swing.text.StyleConstants.setFontSize(self.lParenAttrib, self.fontSize) swing.text.StyleConstants.setFontFamily(self.lParenAttrib, "Monospaced"); swing.text.StyleConstants.setForeground(self.rParenAttrib, JESConstants.RPAREN_COLOR) swing.text.StyleConstants.setBold(self.rParenAttrib, INVALID_PAREN_BOLD) swing.text.StyleConstants.setFontSize(self.rParenAttrib, self.fontSize) swing.text.StyleConstants.setFontFamily(self.rParenAttrib, "Monospaced"); swing.text.StyleConstants.setForeground(self.errorLineAttrib, ERROR_LINE_FONT_COLOR) swing.text.StyleConstants.setBackground(self.errorLineAttrib, ERROR_LINE_BACKGROUND_COLOR) swing.text.StyleConstants.setFontFamily(self.errorLineAttrib, "Monospaced") swing.text.StyleConstants.setForeground(self.highlightLineAttrib, HIGHLIGHT_LINE_FONT_COLOR) swing.text.StyleConstants.setBackground(self.highlightLineAttrib, HIGHLIGHT_LINE_BACKGROUND_COLOR) swing.text.StyleConstants.setFontFamily(self.highlightLineAttrib, "Monospaced") #self.undoEvents = [] #Sets up the UndoManager which handles all undos/redos self.undoManager = swing.undo.UndoManager() self.undoManager.setLimit(MAX_UNDO_EVENTS_TO_RETAIN) HighlightingStyledDocument.setKeywordStyle(self, self.keywordAttrib) HighlightingStyledDocument.setEnvironmentWordStyle(self, self.jesEnvironmentWordAttrib) HighlightingStyledDocument.setStringStyle(self, self.stringAttrib) HighlightingStyledDocument.setLParenStyle(self, self.lParenAttrib) HighlightingStyledDocument.setRParenStyle(self, self.rParenAttrib) HighlightingStyledDocument.setCommentStyle(self, self.commentAttrib) HighlightingStyledDocument.setDefaultStyle(self, self.textAttrib) #The following variables are set when showErrorLine is called. They #are then used to unhighlight the line when the next text modification #is made. self.errorLineStart = -1 self.errorLineLen = -1 self.highlightLineStart = -1 self.highlightLineLen = -1