Ejemplo n.º 1
0
 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