def __init__(self, parent = None): QsciScintilla.__init__(self, parent) # Time that should enlapse for the tool tip to show self.tool_tip_delay = 1 # Whether or not annotations should be displayed self.annotations_active = False # Set python as language lexer = QsciLexerPython() api = Qsci.QsciAPIs(lexer) self.setLexer(lexer) self.lexer = lexer # NOTE: For some reasone self.lexer() doesn't work # Addictional API api.prepare() lexer.setFoldComments(True) lexer.setFoldCompact(False) # QsciScintilla editing defaults self.setAutoCompletionThreshold(1) self.setAutoCompletionSource(QsciScintilla.AcsAll) self.setAutoIndent(True) self.setIndentationsUseTabs(False) self.setTabIndents(True) self.setBackspaceUnindents(True) self.setIndentationWidth(4) # QScintilla code guides self.setIndentationGuides(True) self.setEdgeMode(QsciScintilla.EDGE_LINE) # Margin 0 is used to display problem markers (errors and warnings) self.setMarginType(0, QsciScintilla.SymbolMargin) self.setMarginWidth(0, 16) self.setMarginMarkerMask(0, 8) # Margin 1 is used to display line numbers self.setMarginType(1, QsciScintilla.TextMarginRightJustified) self._adjust_margin_width() self.setMarginLineNumbers(1, True) self.setMarginMarkerMask(1, 0) # Margin 2 is used to display folding commands self.setMarginType(2, QsciScintilla.SymbolMargin) self.setFolding(QsciScintilla.CircledTreeFoldStyle) # Syntax errors highlight symbols crosscircle_icon = QPixmap("images/crosscircle.png") self._syntax_error_marker = self.markerDefine(crosscircle_icon, 3) self._syntax_error_indicator = self.indicatorDefine( QsciScintilla.SquiggleIndicator) self.setIndicatorForegroundColor(Qt.red, self._syntax_error_indicator) # SyntaxError list self._syntax_errors = [] # Ensure the margin width is enough to show line numbers self.linesChanged.connect(self._adjust_margin_width) # Enable mouse tracking for tooltips QsciScintilla.setMouseTracking(self, True) # Line tool tip timer self._tool_tip_timer = QTimer(self) self._tool_tip_timer.setSingleShot(True) self._tool_tip_timer.timeout.connect(self._show_tool_tip) # Keep track of the mouse position self._mouse_position = None self._global_mouse_position = None
def __init__(self, parent=None): super(SimplePythonEditorTextField, self).__init__(parent) # defaults self._filename = '' self._folder = '' self._changed = False self._parent = parent self._unsearched = True # Connect some actions self.textChanged.connect(self.on_textChanged) # disk file monitor self.fileWatcher = QtCore.QFileSystemWatcher() self.fileWatcher.fileChanged.connect(self.on_fileChanged) # # Setup the editor # # Set the default font font = QtGui.QFont() font.setFamily('Courier') font.setFixedPitch(True) font.setPointSize(9.5) self.setFont(font) self.setMarginsFont(font) # Margin 0 is used for line numbers fontmetrics = QtGui.QFontMetrics(font) self.setMarginsFont(font) self.setMarginWidth(0, fontmetrics.width("0000") + 6) self.setMarginLineNumbers(0, True) self.setMarginsBackgroundColor(QtGui.QColor("#cccccc")) # Brace matching: enable for a brace immediately before or after # the current position # self.setBraceMatching(QsciScintilla.SloppyBraceMatch) # Current line visible with special background color self.setCaretLineVisible(True) self.setCaretLineBackgroundColor(QtGui.QColor("#ffe4e4")) # Unix end of line chars self.setEolMode(self.EolUnix) # Set Python lexer # Set style for Python comments (style number 1) to a fixed-width # courier. # lexer = QsciLexerPython() lexer.setDefaultFont(font) lexer.setFoldCompact(False) # so folding ends at the end of functions # not at the start of the next object self.setLexer(lexer) self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, 'Courier') # unset control charaters I need access to commands = self.standardCommands() # free ctrl-L to goto line command = commands.find(QsciCommand.LineCut) command.setKey(0) # Set python tabs self.setTabIndents(True) self.setTabWidth(4) self.setIndentationsUseTabs(False) #AutoIndentation self.setAutoIndent(True) self.setIndentationGuides(True) self.setIndentationWidth(4) # Code folding self.setMarginWidth(1, 14) self.setFolding(QsciScintilla.BoxedTreeFoldStyle) # Edge Mode shows a red vetical bar at 80 chars self.setEdgeMode(QsciScintilla.EdgeLine) self.setEdgeColumn(80) # self.setEdgeColor(QtGui.QColor("#FF0000")) # Don't want to see the horizontal scrollbar at all # Use raw message to Scintilla here (all messages are documented # here: http://www.scintilla.org/ScintillaDoc.html) self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 1) # not too small self.setMinimumSize(fontmetrics.averageCharWidth()*92, 450)
def __init__(self, parent=None): super(SimplePythonEditorTextField, self).__init__(parent) # defaults self._filename = '' self._folder = '' self._changed = False self._parent = parent self._unsearched = True # Connect some actions self.textChanged.connect(self.on_textChanged) # disk file monitor self.fileWatcher = QtCore.QFileSystemWatcher() self.fileWatcher.fileChanged.connect(self.on_fileChanged) # # Setup the editor # # Set the default font font = QtGui.QFont() font.setFamily('Courier') font.setFixedPitch(True) font.setPointSize(9.5) self.setFont(font) self.setMarginsFont(font) # Margin 0 is used for line numbers fontmetrics = QtGui.QFontMetrics(font) self.setMarginsFont(font) self.setMarginWidth(0, fontmetrics.width("0000") + 6) self.setMarginLineNumbers(0, True) self.setMarginsBackgroundColor(QtGui.QColor("#cccccc")) # Brace matching: enable for a brace immediately before or after # the current position # self.setBraceMatching(QsciScintilla.SloppyBraceMatch) # Current line visible with special background color self.setCaretLineVisible(True) self.setCaretLineBackgroundColor(QtGui.QColor("#ffe4e4")) # Unix end of line chars self.setEolMode(self.EolUnix) # Set Python lexer # Set style for Python comments (style number 1) to a fixed-width # courier. # lexer = QsciLexerPython() lexer.setDefaultFont(font) lexer.setFoldCompact(False) # so folding ends at the end of functions # not at the start of the next object self.setLexer(lexer) self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, 'Courier') # unset control charaters I need access to commands = self.standardCommands() # free ctrl-L to goto line command = commands.find(QsciCommand.LineCut) command.setKey(0) # Set python tabs self.setTabIndents(True) self.setTabWidth(4) self.setIndentationsUseTabs(False) #AutoIndentation self.setAutoIndent(True) self.setIndentationGuides(True) self.setIndentationWidth(4) # Code folding self.setMarginWidth(1, 14) self.setFolding(QsciScintilla.BoxedTreeFoldStyle) # Edge Mode shows a red vetical bar at 80 chars self.setEdgeMode(QsciScintilla.EdgeLine) self.setEdgeColumn(80) # self.setEdgeColor(QtGui.QColor("#FF0000")) # Don't want to see the horizontal scrollbar at all # Use raw message to Scintilla here (all messages are documented # here: http://www.scintilla.org/ScintillaDoc.html) self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 1) # not too small self.setMinimumSize(fontmetrics.averageCharWidth()*92, 450)