def __init__(self): super(ScriptPage, self).__init__() self.setupUi(self) self.scriptCodeEditor.setUtf8(1) lex = Qsci.QsciLexerPython(self) api = Qsci.QsciAPIs(lex) api.load(API_FILE) api.prepare() self.current_script = None # type: model.Script self.scriptCodeEditor.setLexer(lex) self.scriptCodeEditor.setBraceMatching( Qsci.QsciScintilla.SloppyBraceMatch) self.scriptCodeEditor.setAutoIndent(True) self.scriptCodeEditor.setBackspaceUnindents(True) self.scriptCodeEditor.setIndentationWidth(4) self.scriptCodeEditor.setIndentationGuides(True) self.scriptCodeEditor.setIndentationsUseTabs(False) self.scriptCodeEditor.setAutoCompletionThreshold(3) self.scriptCodeEditor.setAutoCompletionSource( Qsci.QsciScintilla.AcsAll) self.scriptCodeEditor.setCallTipsStyle( Qsci.QsciScintilla.CallTipsNoContext) lex.setFont(ui_common.monospace_font())
def set_Lexer(self, type=2): #设置解释器 dic = { 0: Qsci.QsciLexerBash(), 1: Qsci.QsciLexerCPP(), 2: Qsci.QsciLexerPython(), 3: Qsci.QsciLexerJava(), } textLexer = dic[type] # textLexer->setColor(QColor(Qt:: yellow), QsciLexerCPP::CommentLine); // 设置自带的注释行为绿色 self.setLexer(textLexer)
def __init__(self, parent=None): super().__init__(parent=parent) self.lexer = Qsci.QsciLexerPython() api = Qsci.QsciAPIs(self.lexer) api.prepare() self.setLexer(self.lexer) self.setAutoCompletionThreshold(1) self.setAutoCompletionSource(Qsci.QsciScintilla.AcsAPIs) self.init_ui() return
def __init__(self, parent=None, *, fontsize=11, fontfamily='monospace', autocompletion_words=(), autocomplete_python=True, theme='dark', **kwds): super().__init__(parent) # Fonts self.setAllFonts(fontfamily, fontsize) self.setMarginSensitivity(1, False) self.setCaretLineVisible(True) # Configure lexer and api for autocompletion lexer = Qsci.QsciLexerPython(self) lexer.setDefaultFont(self.font()) words = list(autocompletion_words) if autocomplete_python: words.extend(PYTHON_WORDS) if words: api = Qsci.QsciAPIs(lexer) for word in words: api.add(word) api.prepare() self.setLexer(lexer) # Set font for lexer again? bfamily = bytes(fontfamily, encoding='utf8') self.SendScintilla(Qsci.QsciScintilla.SCI_STYLESETFONT, 1, bfamily) self.setAllFonts(fontfamily, fontsize, True) # General indentation behavior self.setAutoIndent(True) self.setTabWidth(4) self.setIndentationsUseTabs(False) self.setTabIndents(True) self.setBackspaceUnindents(True) self.setIndentationGuides(True) # Configure autocompletion and brace matching self.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch) self.setAutoCompletionThreshold(2) self.setAutoCompletionSource(Qsci.QsciScintilla.AcsAPIs) # Set colors self._theme = theme color_kwds = {k: v for (k, v) in kwds.items() if k.endswith('_color')} self.setTheme(theme, **color_kwds) # Check for any rogue parameter if kwds: raise TypeError('invalid parameter: %r' % kwds.popitem()[0])
def new_editor(self) -> Qsci.QsciScintilla: """""" # Create editor object editor = Qsci.QsciScintilla() # Set editor font font = QtGui.QFont() font.setFamily('Consolas') font.setFixedPitch(True) font.setPointSize(10) editor.setFont(font) editor.setMarginsFont(font) # Set margin for line numbers font_metrics = QtGui.QFontMetrics(font) editor.setMarginWidth(0, font_metrics.width("00000") + 6) editor.setMarginLineNumbers(0, True) editor.setMarginsBackgroundColor(QtGui.QColor("#cccccc")) # Set brace matching editor.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch) # Hide horizontal scroll bar editor.SendScintilla(Qsci.QsciScintilla.SCI_SETHSCROLLBAR, 0) # Set current line color editor.setCaretLineVisible(True) editor.setCaretLineBackgroundColor(QtGui.QColor("#ffe4e4")) # Set Python lexer lexer = Qsci.QsciLexerPython() lexer.setDefaultFont(font) editor.setLexer(lexer) # Add minimum editor size editor.setMinimumSize(600, 450) # Enable auto complete editor.setAutoCompletionSource(Qsci.QsciScintilla.AcsAll) editor.setAutoCompletionThreshold(2) editor.setAutoCompletionCaseSensitivity(False) editor.setAutoCompletionReplaceWord(False) # Use space indentation editor.setIndentationsUseTabs(False) editor.setTabWidth(4) editor.setIndentationGuides(True) # Enable folding editor.setFolding(True) return editor
def __init__(self, *args, action, **kwargs): self._action = action super().__init__(*args, **kwargs) self._sci = Qsci.QsciScintilla(self) self._sci.setUtf8(True) self._sci.setEolMode(self._sci.EolUnix) self._sci.setIndentationsUseTabs(True) self._sci.setIndentationGuides(True) self._sci.setCaretLineVisible(True) self._sci.setMargins(1) self._sci.setMarginType(0, self._sci.NumberMargin) self._sci.setMarginWidth(0, '000') self._sci.setLexer(Qsci.QsciLexerCPP(self._sci)) self._sci.setText(self._action.source()) self._report = QtWidgets.QTreeWidget(self) self._report.setColumnCount(2) self._report.setHeaderHidden(True) self._report.itemClicked.connect(self._reportClicked) self._errorMarker = self._sci.markerDefine(self._sci.Background) self._sci.setMarkerBackgroundColor(QtCore.Qt.red, self._errorMarker) self._warningMarker = self._sci.markerDefine(self._sci.Background) self._sci.setMarkerBackgroundColor(QtCore.Qt.yellow, self._warningMarker) btnOK = QtWidgets.QPushButton(_('Done'), self) btnCancel = QtWidgets.QPushButton(_('Cancel'), self) bld = LayoutBuilder(self) with bld.vbox() as vbox: vbox.addWidget(self._sci, stretch=5) vbox.addWidget(self._report, stretch=1) with bld.hbox() as buttons: buttons.addStretch(1) buttons.addWidget(btnCancel) buttons.addWidget(btnOK) btnOK.clicked.connect(self.accept) btnCancel.clicked.connect(self.reject) with Settings().grouped('IDE') as settings: if settings.contains('WindowGeometry'): self.restoreGeometry(settings.value('WindowGeometry')) else: self.resize(1024, 768) self._timer = QtCore.QTimer(self) self._timer.timeout.connect(self._tryCompile) self._timer.setSingleShot(True) self._sci.textChanged.connect(self._onTextChanged) self._tryCompile()
def setup_editor(self): "define the editor panel" # self.editor = qtw.QTextEdit(self) self.editor = qsc.QsciScintilla(self) self.editor.setWrapMode(qsc.QsciScintilla.WrapWord) self.editor.setBraceMatching(qsc.QsciScintilla.SloppyBraceMatch) self.editor.setAutoIndent(True) self.editor.setFolding(qsc.QsciScintilla.PlainFoldStyle) self.editor.setCaretLineVisible(True) self.editor.setCaretLineBackgroundColor(gui.QColor("#ffe4e4")) self.editor.setLexer(qsc.QsciLexerMarkdown()) self.editor.setEnabled(False) return self.editor
def __init__(self, parent=None, text=""): QtWidgets.QDialog.__init__(self, parent) self.resize(400, 300) vbox = QtWidgets.QVBoxLayout() self.textedit = Qsci.QsciScintilla(None) self.textedit.setFont(QtGui.QFont("mono", 10)) self.textedit.setEdgeMode(Qsci.QsciScintilla.EdgeLine) self.textedit.setEdgeColumn(35) self.textedit.setEdgeColor(QtGui.QColor("#FF0000")) self.textedit.setText(text) self.textedit.cursorPositionChanged.connect(self.curPosChanged) quit_button = QtWidgets.QPushButton("OK") quit_button.clicked.connect(self.ok) self.label = QtWidgets.QLabel() vbox.addWidget(self.textedit) vbox.addWidget(quit_button) vbox.addWidget(self.label) self.setLayout(vbox) self.text = ""
def setup_text(self): "define the scintilla widget's properties" # Set the default font font = gui.QFont() font.setFamily('Courier') font.setFixedPitch(True) font.setPointSize(10) self.text.setFont(font) self.text.setMarginsFont(font) # Margin 0 is used for line numbers fontmetrics = gui.QFontMetrics(font) self.text.setMarginsFont(font) self.text.setMarginWidth(0, fontmetrics.width("00000")) self.text.setMarginLineNumbers(0, True) self.text.setMarginsBackgroundColor(gui.QColor("#cccccc")) # Enable brace matching, auto-indent, code-folding self.text.setBraceMatching(sci.QsciScintilla.SloppyBraceMatch) self.text.setAutoIndent(True) self.text.setFolding(sci.QsciScintilla.PlainFoldStyle) # Current line visible with special background color self.text.setCaretLineVisible(True) self.text.setCaretLineBackgroundColor(gui.QColor("#ffe4e4")) # Set HTML lexer lexer = sci.QsciLexerDiff() lexer.setDefaultFont(font) self.text.setLexer(lexer)
def _config_autocomplete(self): # if source is set, make use of all variables self.setAutoCompletionSource(Qsci.QsciScintilla.AcsAll if self.autocomplete_source else Qsci.QsciScintilla.AcsNone) # invoke autocompletion when typed 1 character self.setAutoCompletionThreshold(1) # autocompletion case-insensitive self.setAutoCompletionCaseSensitivity(False) # don't replace typed text, but append self.setAutoCompletionReplaceWord(False) # don't complete word even if there's only one suggestion self.setAutoCompletionUseSingle(Qsci.QsciScintilla.AcusNever) # show calltips independent of context self.setCallTipsStyle(Qsci.QsciScintilla.CallTipsNoContext) #self.setCallTipsStyle(Qsci.QsciScintilla.CallTipsNoAutoCompletionContext) #self.setCallTipsStyle(Qsci.QsciScintilla.CallTipsContext) # display all applicable calltips self.setCallTipsVisible(0) # show calltips beneath the typed text self.setCallTipsPosition(Qsci.QsciScintilla.CallTipsBelowText) # configure calltip colors self.setCallTipsBackgroundColor(QtGui.QColor('#fffff0')) self.setCallTipsForegroundColor(QtGui.QColor(QtCore.Qt.black)) self.setCallTipsHighlightColor(QtGui.QColor(QtCore.Qt.blue)) ## `Qsci.QsciAPIs` internal autocomplete object self.autocomplete = Qsci.QsciAPIs(self.lexer) self.reset_autocomplete_source()
def __init__(self, parent, title='', caption='', data='', size=(600, 400)): "create a window with a scintilla text widget and an ok button" self._parent = parent super().__init__(parent) self.setWindowTitle(title) ## self.setWindowIcon(self._parent._parent.appicon) self.resize(size[0], size[1]) vbox = qtw.QVBoxLayout() hbox = qtw.QHBoxLayout() hbox.addWidget(qtw.QLabel(caption, self)) vbox.addLayout(hbox) hbox = qtw.QHBoxLayout() self.text = sci.QsciScintilla(self) self.setup_text() self.text.setText(data) self.text.setReadOnly(True) hbox.addWidget(self.text) vbox.addLayout(hbox) hbox = qtw.QHBoxLayout() ok_button = qtw.QPushButton('&Ok', self) ok_button.clicked.connect(self.close) ok_button.setDefault(True) hbox.addStretch() hbox.addWidget(ok_button) hbox.addStretch() vbox.addLayout(hbox) self.setLayout(vbox) do = qtw.QAction('Done', self) do.triggered.connect(self.close) do.setShortcut('Esc') self.addAction(do)
def __init__(self, parent): super ().__init__(parent) font = QtGui.QFont() font.setFamily('Courier') font.setFixedPitch(True) font.setPointSize(10) self.setFont(font) self.setMarginsFont(font) fontMetrics = QtGui.QFontMetrics(font) self.setMarginsFont(font) self.setMarginWidth(0, fontMetrics.width("00000") + 6) self.setMarginLineNumbers(0, True) self.setMarginsBackgroundColor(QtGui.QColor("#cccccc")) self.markerDefine(Qsci.QsciScintilla.RightArrow, self.SC_MARK_MINUS) self.setMarkerBackgroundColor(QtGui.QColor("#ee1111"), self.SC_MARK_MINUS) self.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch) self.setCaretLineVisible(True) self.setCaretLineBackgroundColor(QtGui.QColor("#ffe4e4")) lexer = Qsci.QsciLexerPython() lexer.setDefaultFont(font) self.setLexer(lexer) self.SendScintilla(Qsci.QsciScintilla.SCI_SETEOLMODE, Qsci.QsciScintilla.SC_EOL_CR) self.setTabWidth(4) self.setIndentationsUseTabs(False) self.setAutoIndent(True) self.setAcceptDrops(True)
def text_setting(self, text): # set font font = QtGui.QFont() font.setFamily ('Consolas') font.setBold(True) font.setFixedPitch(True) font.setPointSize(12) # set lex lex = Qsci.QsciLexerCPP() lex.setFont(font) text.setLexer(lex) text.setTabWidth(4) text.setUtf8(True) text.setFolding(Qsci.QsciScintilla.BoxedTreeFoldStyle) # set indentation text.setIndentationWidth(4) text.setIndentationGuides(True) text.setAutoIndent(True) text.setAutoCompletionSource(Qsci.QsciScintilla.AcsAll); text.setAutoCompletionThreshold(3) # set brace matching text.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch) # set Margins text.setMarginsFont(font) fontmetrics = QtGui.QFontMetrics(font) text.setMarginWidth(0, fontmetrics.width("00") + 6) text.setMarginLineNumbers(0, True)
def __init__(self, parent=None): """ very similar to: https://stackoverflow.com/questions/40002373/qscintilla-based-text-editor-in-pyqt5-with-clickable-functions-and-variables """ super(SimplePythonEditorWidget, self).__init__(parent) # Set the default font font = QFont() font.setFamily('Courier') font.setFixedPitch(True) font.setPointSize(10) self.setFont(font) self.setMarginsFont(font) self.set_font(font) self.setMarginLineNumbers(0, True) self.setMarginsBackgroundColor(QColor("#cccccc")) # Clickable margin 1 for showing markers self.setMarginSensitivity(1, True) if qt_version == 'pyqt4': self.connect(self, QtCore.SIGNAL('marginClicked(int, int, Qt::KeyboardModifiers)'), self.on_margin_clicked) else: self.marginClicked.connect(self.on_margin_clicked) self.markerDefine(Qsci.QsciScintilla.RightArrow, self.ARROW_MARKER_NUM) self.setMarkerBackgroundColor(QColor("#ee1111"), self.ARROW_MARKER_NUM) # Brace matching: enable for a brace immediately before or after # the current position self.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch) # Current line visible with special background color self.setCaretLineVisible(True) self.setCaretLineBackgroundColor(QColor("#ffe4e4")) # Set Python lexer # Set style for Python comments (style number 1) to a fixed-width # courier. lexer = Qsci.QsciLexerPython() lexer.setDefaultFont(font) self.setLexer(lexer) if qt_version == 'pyqt4': self.SendScintilla(Qsci.QsciScintilla.SCI_STYLESETFONT, 1, 'Courier') else: font_style = bytearray(str.encode("Courier")) self.SendScintilla(Qsci.QsciScintilla.SCI_STYLESETFONT, 1, font_style) # 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(Qsci.QsciScintilla.SCI_SETHSCROLLBAR, 0)
def setNoneAutocomplete(self): #AutoCompletion self.autocomplete = Qsci.QsciAPIs(self.lexer) self.autocomplete.clear() self.autocomplete.prepare() self.setAutoCompletionThreshold(3) self.setAutoCompletionSource(QsciScintilla.AcsAPIs)
def set_document(self, document): """ Set the document on the underlying widget. """ qdoc = self.qsci_doc_cache.get(document.uuid) if qdoc is None: qdoc = self.qsci_doc_cache[document.uuid] = Qsci.QsciDocument() self.qsci_doc = qdoc # take a strong ref since PyQt doesn't self.widget.setDocument(qdoc)
def new_file(self): if self.tab_widget.tabText(self.tab_widget.currentIndex()) is not 'new': text = Qsci.QsciScintilla() self.text_setting(text) self.tab_widget.addTab(text, 'new') self.tab_widget.setCurrentWidget(text) self.text = text # set the current text editor to be self.text else: return
def __init__(self, parent=None): Qsci.QsciScintilla.__init__(self, parent) self.setLexer(Qsci.QsciLexerXML()) self.text_object = TextObject("") self.highlight_index = self.indicatorDefine(self.RoundBoxIndicator, -1) self.setIndicatorDrawUnder(True, self.highlight_index) self.setIndicatorForegroundColor(QtGui.QColor("#dddddd"), self.highlight_index) self.orig_text = self.text_object.orig_text
def __init__(self, parent=None): """ Initialize the class by setting up the editor @param parent: parent of the widget """ super(XmlCodeEditor, self).__init__(parent) self.lexer_ = Qsci.QsciLexerXML(self) self.initial_content = None self.parsed_content = None
def setEditorType(self, tpe: EditorType, inner=False): self.editType = tpe if not inner: self.editorTypeBox.setCurrentIndex(tpe.value) if tpe == EditorType.JSON: self.editor.changeLexer(Qsci.QsciLexerJSON(self.editor), 'JSON') elif tpe == EditorType.XML: self.editor.changeLexer(Qsci.QsciLexerXML(self.editor), 'XML') elif tpe == EditorType.HTML: self.editor.changeLexer(Qsci.QsciLexerHTML(self.editor), 'HTML') elif tpe == EditorType.Javascript: self.editor.changeLexer(Qsci.QsciLexerJavaScript(self.editor), 'Javascript') else: self.editor.changeLexer(Qsci.QsciLexerMarkdown(self.editor), 'Text<') self.editorTypeChanged.emit(tpe.value)
def __init__(self, parent=None): super().__init__(parent) # Set the default font self.font = QFont() self.font.setFamily('Courier') self.font.setFixedPitch(True) self.font.setPointSize(10) self.setFont(self.font) self.setMarginsFont(self.font) # Margin 0 is used for line numbers fontmetrics = QFontMetrics(self.font) self.setMarginsFont(self.font) self.setMarginWidth(0, fontmetrics.width("000") + 6) self.setMarginLineNumbers(0, True) self.setMarginsBackgroundColor(QColor("#E3F0FF")) # 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(QColor("#A5ABBD")) # Set Python lexer # Set style for Python comments (style number 1) to a fixed-width # courier. # lexer = Qsci.QsciLexerMarkdown(self) lexer.setDefaultFont(self.font) self.setLexer(lexer) # self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, 'Courier') """ Customization - AUTOCOMPLETION (Partially usable without a lexer) """ # Set the autocompletions to case INsensitive self.setAutoCompletionCaseSensitivity(False) # Set the autocompletion to not replace the word to the right of the cursor self.setAutoCompletionReplaceWord(False) # Set the autocompletion source to be the words in the # document self.setAutoCompletionSource(Qsci.QsciScintilla.AcsDocument) # Set the autocompletion dialog to appear as soon as 1 character is typed self.setAutoCompletionThreshold(1) # 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, 0) # not too small self.setMinimumSize(300, 100)
def __initScintilla(self): # delete text editor placeholder scintilla = Qsci.QsciScintilla(self) ######################## # setup scintilla # set default font font = QtGui.QFont() font.setFamily('Deja Vu Sans Mono') font.setFixedPitch(True) font.setPointSize(11) # brace matching scintilla.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch) # set lexer lexer = Qsci.QsciLexerCPP() lexer.setDefaultFont(font) lexer.setFont(font) scintilla.setLexer(lexer) scintilla.setLexer(lexer) scintilla.__myLexer = lexer # save reference to retain scope # auto-completion api scintilla.__myApi = Qsci.QsciAPIs(lexer) scintilla.setAutoCompletionThreshold(1) scintilla.setAutoCompletionSource(Qsci.QsciScintilla.AcsAPIs) # remove horizontal scrollbar scintilla.SendScintilla(Qsci.QsciScintilla.SCI_SETHSCROLLBAR, 0) # display default line numbers fm = QtGui.QFontMetrics(font) scintilla.setMarginWidth(0, fm.width("00000")) scintilla.setMarginLineNumbers(0, True) ######################## # insert widget into main vlayout self.ui.vlayout.addWidget(scintilla) self.__scintilla = scintilla
def __init__(self, parent=None): """ Initialize the class by setting up the editor @param parent: parent of the widget """ super(YamlCodeEditor, self).__init__(parent) self.init_symbol_margin() self.lexer_ = Qsci.QsciLexerYAML(self) # Will contain the parsed content self.parsed_content = OrderedDict()
def __init__(self, parent=None, lexer=Qsci.QsciLexerPython(), source=None, autocomplete_source=None): super(Qsci.QsciScintilla, self).__init__(parent) # Set the default font font = make_font('Courier', 10) font.setFixedPitch(True) self.setFont(font) # Indentation self.setIndentationsUseTabs(False) self.setTabWidth(4) self.setAutoIndent(True) # Margins self.setMarginsFont(font) self.setMarginsBackgroundColor(QtGui.QColor('#5d5d5d')) self.setMarginsForegroundColor(QtGui.QColor(QtCore.Qt.yellow)) # Margin 0 is used for line numbers self.setMarginType(0, Qsci.QsciScintilla.NumberMargin) self.setMarginWidth(0, '00000') self.setMarginLineNumbers(0, True) # Clickable margin 1 for showing markers self.setMarginType(1, Qsci.QsciScintilla.SymbolMargin) self.setMarginWidth(1, 20) self.setMarginSensitivity(1, True) self.marginClicked.connect(self.on_margin_clicked) self.markerDefine(Qsci.QsciScintilla.RightArrow, SynEditor.ARROW_MARKER_NUM) self.setMarkerBackgroundColor(QtGui.QColor(QtCore.Qt.magenta), SynEditor.ARROW_MARKER_NUM) # Brace matching: enable for a brace immediately before or after # the current position self.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch) # Current line visible with special background color self.setCaretLineVisible(True) self.setCaretLineBackgroundColor(QtGui.QColor("#f2f2f2")) ## Python lexer self.lexer = lexer # Set style for Python comments (style number 1) to a fixed-width font self.lexer.setDefaultFont(font) self.setLexer(self.lexer) # set font self.SendScintilla(Qsci.QsciScintilla.SCI_STYLESETFONT, 1, bytearray(str.encode(font.family()))) # tab guides self.setIndentationGuides(True) ## `list`|`None` autocompletion source self.autocomplete_source = autocomplete_source self._config_autocomplete() # set source if source: self.setText(source)
def __init__(self, lexer=Qsci.QsciLexerPython(), source=None, autocomplete_source=None, minsize=(600, 400), icon='file.png', title=':: Code Editor ::'): super().__init__() ## `QtWidgets.QVBoxLayout` main window layout self.layout_main = QtWidgets.QVBoxLayout() self.add_elements(lexer, source, autocomplete_source) self.setLayout(self.layout_main) # set minimum widget size if minsize: self.setMinimumSize(*minsize) self.setWindowIcon(QtGui.QIcon(f"{ICONFOLDER}/{icon}")) self.setWindowTitle(title)
def set_autocompletion(self, items): """ Allow the strings contained in items to be autocompleted after two characters @param items: List of strings containing the words to propose for autocompletion """ self.setAutoCompletionSource(Qsci.QsciScintilla.AcsAPIs) self.setAutoCompletionThreshold(2) self.api = Qsci.QsciAPIs(self.lexer_) for item in items: self.api.add(item) self.api.prepare()
def setupEditor(self): #Font self.font = QtGui.QFont() self.font.setFamily('Inconsolata') self.font.setPointSize(12) self.ui.textEdit.setFont(self.font) self.ui.textEdit.setMarginsFont(self.font) #Syntax self.lexer = Qsci.QsciLexerPython() self.lexer.setFont(self.font) self.lexer.setDefaultFont(self.font) #Autocomplete api = Qsci.QsciAPIs(self.lexer) keys = dir(builtins) + keyword.kwlist [api.add(key) for key in keys] api.prepare() self.ui.textEdit.setLexer(self.lexer) self.ui.textEdit.setAutoCompletionThreshold(1) self.ui.textEdit.setAutoCompletionSource(Qsci.QsciScintilla.AcsAll) #Indent self.ui.textEdit.setIndentationWidth(4) self.ui.textEdit.setTabWidth(4) self.ui.textEdit.setIndentationsUseTabs(False) self.ui.textEdit.setAutoIndent(True) #Current line self.ui.textEdit.SendScintilla(Qsci.QsciScintilla.SCI_SETINDICATORCURRENT, 0, 0) self.ui.textEdit.setCaretLineVisible(True) self.ui.textEdit.setCaretLineBackgroundColor(QtGui.QColor("#f0f0ff")) #Margin self.ui.textEdit.setMarginWidth(0, 15) self.ui.textEdit.setMarginWidth(1, 15) self.ui.textEdit.setMarginLineNumbers(0, False) self.ui.textEdit.setMarginLineNumbers(1, True) self.ui.textEdit.setFolding(Qsci.QsciScintilla.BoxedTreeFoldStyle)
def _setLexer(self): lexer = _Qsci.QsciLexerPython() lexer.setDefaultFont(_QtGui.QFont('Courier', 10)) # Set the comment options lexer.comment_string = "#" # Set the lexer for the current scintilla document lexer.setParent(self) self.setLexer(lexer) for style in self.styles: paper = _QtGui.QColor(getattr(PythonColor, style)) lexer.setPaper(paper, self.styles[style]) self.setLexerFont(lexer, style, getattr(PythonFont, style)) # self.setMatchedBraceBackgroundColor(settings.Editor.brace_color) self.SendScintilla(_Qsci.QsciScintillaBase.SCI_STYLESETFONT, 1, b'Courier') self.setFolding(_Qsci.QsciScintilla.PlainFoldStyle)
def __init__(self, parent=None): super(MyQScintilla, self).__init__(parent) lexer = Qsci.QsciLexerPython() self.setLexer(lexer) self.setWhitespaceVisibility(Qsci.QsciScintilla.WsVisible) self.setMarginLineNumbers(1, True) self.setMarginWidth(1, 25) self.setReadOnly(False) self.setIndentationGuides(True) self.setIndentationWidth(4) self.setIndentationsUseTabs(False) self.setWrapMode(Qsci.QsciScintilla.WrapWord) self.setUtf8(True) self.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch) self.setCaretLineVisible(True) # highlight current line self.setCaretLineBackgroundColor(QColor("#e5e5e5"))
def set_autocompletions(self, options): """ Set the autocompletion options for when the autocompletion mode is in 'all' or 'apis'. """ # Delete the old if one exists if self.qsci_api: # Please note that it is not possible to add or remove entries # once you’ve “prepared” so we have to destroy and create # a new provider every time. self.qsci_api.deleteLater() self.qsci_api = None # Add the new options api = self.qsci_api = Qsci.QsciAPIs(self.widget.lexer()) for option in options: api.add(option) api.prepare()