标签: qscintilla

How can I make QScintilla auto-indent like SublimeText?

Consider the below mcve:

import sys
import textwrap

from PyQt5.Qsci import QsciScintilla
from PyQt5.Qt import *


if __name__ == '__main__':

    app = QApplication(sys.argv)
    view = QsciScintilla()

    view.SendScintilla(view.SCI_SETMULTIPLESELECTION, True)
    view.SendScintilla(view.SCI_SETMULTIPASTE, 1)
    view.SendScintilla(view.SCI_SETADDITIONALSELECTIONTYPING, True)

    view.setAutoIndent(True)
    view.setTabWidth(4)
    view.setIndentationGuides(True)
    view.setIndentationsUseTabs(False)
    view.setBackspaceUnindents(True)

    view.setText(textwrap.dedent("""\
        def foo(a,b):
            print('hello')
    """))

    view.show()
    app.exec_()
Run Code Online (Sandbox Code Playgroud)

The behaviour of the auto-indent of the above snippet is really bad when comparing it with editors such as SublimeText or CodeMirror. First let's see how nice will behave the autoindent feature in SublimeText with …

c++ python qscintilla sublimetext pyqt5

19
推荐指数
1
解决办法
350
查看次数

如何在QScintilla中实现基于缩进的代码折叠?

这里的最终目标是在QScintilla中实现基于缩进的代码折叠,类似于SublimeText3所做的方式。

首先,这是一个使用QScintilla机制手动提供折叠的小例子:

import sys

from PyQt5.Qsci import QsciScintilla
from PyQt5.Qt import *

if __name__ == '__main__':
    app = QApplication(sys.argv)
    view = QsciScintilla()

    # http://www.scintilla.org/ScintillaDoc.html#Folding
    view.setFolding(QsciScintilla.BoxedTreeFoldStyle)

    lines = [
        (0, "def foo():"),
        (1, "    x = 10"),
        (1, "    y = 20"),
        (1, "    return x+y"),
        (-1, ""),
        (0, "def bar(x):"),
        (1, "    if x > 0:"),
        (2, "        print('this is')"),
        (2, "        print('branch1')"),
        (1, "    else:"),
        (2, "        print('and this')"),
        (2, "        print('is branch2')"),
        (-1, ""),
        (-1, ""),
        (-1, ""), …
Run Code Online (Sandbox Code Playgroud)

python pyqt qscintilla sublimetext3

18
推荐指数
1
解决办法
546
查看次数

如何向QsciLexerCustom子类添加折叠?

请考虑以下代码段:

import sys
import textwrap
import re

from PyQt5.Qt import *  # noqa

from PyQt5.Qsci import QsciScintilla
from PyQt5.Qsci import QsciLexerCustom

from lark import Lark, inline_args, Transformer


class LexerJson(QsciLexerCustom):

    def __init__(self, parent=None):
        super().__init__(parent)
        self.create_grammar()
        self.create_styles()

    def create_styles(self):
        deeppink = QColor(249, 38, 114)
        khaki = QColor(230, 219, 116)
        mediumpurple = QColor(174, 129, 255)
        mediumturquoise = QColor(81, 217, 205)
        yellowgreen = QColor(166, 226, 46)
        lightcyan = QColor(213, 248, 232)
        darkslategrey = QColor(39, 40, 34)

        styles = {
            0: mediumturquoise,
            1: mediumpurple,
            2: …
Run Code Online (Sandbox Code Playgroud)

python pyqt qscintilla pyqt5 lark-parser

14
推荐指数
1
解决办法
419
查看次数

QScintilla中的色素

考虑这个mcve:

import math
import sys
import textwrap
import time
from pathlib import Path
from collections import defaultdict

from PyQt5.Qsci import QsciLexerCustom, QsciScintilla
from PyQt5.Qt import *

from pygments import lexers, styles, highlight, formatters
from pygments.lexer import Error, RegexLexer, Text, _TokenType
from pygments.style import Style


EXTRA_STYLES = {
    "monokai": {
        "background": "#272822",
        "caret": "#F8F8F0",
        "foreground": "#F8F8F2",
        "invisibles": "#F8F8F259",
        "lineHighlight": "#3E3D32",
        "selection": "#49483E",
        "findHighlight": "#FFE792",
        "findHighlightForeground": "#000000",
        "selectionBorder": "#222218",
        "activeGuide": "#9D550FB0",
        "misspelling": "#F92672",
        "bracketsForeground": "#F8F8F2A5",
        "bracketsOptions": "underline",
        "bracketContentsForeground": "#F8F8F2A5",
        "bracketContentsOptions": "underline",
        "tagsOptions": …
Run Code Online (Sandbox Code Playgroud)

python scintilla pygments qscintilla pyqt5

12
推荐指数
1
解决办法
1920
查看次数

ImportError:运行ninja-ide时没有名为Qsci的模块

我正在尝试安装和运行ninja-ide http://ninja-ide.org/home/

但是,当我尝试运行ninja-ide时,我遇到了这个错误

ImportError: No module named Qsci
Run Code Online (Sandbox Code Playgroud)

我一直试图安装ninja-ide整夜.

我尝试了从源代码安装的所有内容,使用各种博客中提到的apt-get依赖项进行安装.

我安装了一切.SIP,PyQt4,Qscintilla,各种依赖.

我在做的Python的安装文件夹的符号链接/usr/local/include/python2.7的蟒蛇被安装在/usr/include/python2.7.

我甚至将Qsci文件夹复制/usr/include/qt4/usr/lib/python2.7/dist-packages/PyQt4/usr/local/lib/python2.7/dist-packages/PyQt4.

我现在厌倦了安装一切.我仍然无法弄清楚为什么它给了我

ImportError: No module named Qsci
Run Code Online (Sandbox Code Playgroud)

我整晚都在搜索Google和Stack Overflow.

python qscintilla

8
推荐指数
1
解决办法
3809
查看次数

PyQt5 中基于 QScintilla 的文本编辑器,具有可点击的函数和变量

我正在尝试使用 PyQt5 中的基本语法突出显示、代码完成和可点击的函数和变量来制作一个简单的文本编辑器。我最大的希望是使用 PyQt5 的 QScintilla 端口

我在 Eli Bendersky 网站 ( http://eli.thegreenplace.net/2011/04/01/sample-using-qscintilla-with-pyqt )上找到了以下基于 QScintilla 的文本编辑器示例,Victor S. 已将其改编为 PyQt5 )。我认为这个例子是一个很好的起点:

#-------------------------------------------------------------------------
# qsci_simple_pythoneditor.pyw
#
# QScintilla sample with PyQt
#
# Eli Bendersky (eliben@gmail.com)
# This code is in the public domain
#-------------------------------------------------------------------------
import sys

import sip
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.Qsci import QsciScintilla, QsciLexerPython


class SimplePythonEditor(QsciScintilla):
    ARROW_MARKER_NUM = 8

    def __init__(self, parent=None):
        super(SimplePythonEditor, self).__init__(parent)

        # Set the default …
Run Code Online (Sandbox Code Playgroud)

python pyqt python-3.x qscintilla pyqt5

8
推荐指数
1
解决办法
4022
查看次数

PySide中的QScintilla

我喜欢PySide,并且已经使用了一段时间,但是在我正在进行的程序中,我需要一个高级代码编辑器.

我找到了QScintilla,但那是PyQt.这是否与PySide兼容,如果是这样,我将如何使用它?
我也看了PySide-QScintilla,但这一切是一对夫妇的.h文件和一个__init.py____init__.py甚至没有涉及到任何.h文件!有人用过吗?你如何将它包含在一个程序中?
我也看到了qutepart,但它似乎对于我需要的东西来说太基本了.

我会接受QScintilla以外的解决方案,但他们必须:

  • 错误突出显示
  • 语法突出显示
  • 代码建议(输入时的下拉菜单)
  • 行号
  • 自定义颜色
  • 必须至少是GPL(LGPL会很好)

任何其他功能都很棒.

python editor pyside qscintilla

6
推荐指数
1
解决办法
1602
查看次数

如何实现在QScintilla中使用多个选项的注释功能?

我正在尝试在QScintilla中实现一个可以进行多项选择的切换注释功能.不幸的是我不知道该怎么做,到目前为止我已经提出了这个代码:

import sys
import re
import math

from PyQt5.Qt import *  # noqa

from PyQt5.Qsci import QsciScintilla
from PyQt5 import Qsci
from PyQt5.Qsci import QsciLexerCPP


class Commenter():

    def __init__(self, sci, comment_str):
        self.sci = sci
        self.comment_str = comment_str

    def is_commented_line(self, line):
        return line.strip().startswith(self.comment_str)

    def toggle_comment_block(self):
        sci = self.sci

        line, index = sci.getCursorPosition()

        if sci.hasSelectedText() and self.is_commented_line(sci.text(sci.getSelection()[0])):
            self.uncomment_line_or_selection()
        elif not self.is_commented_line(sci.text(line)):
            self.comment_line_or_selection()
        else:
            start_line = line
            while start_line > 0 and self.is_commented_line(sci.text(start_line - 1)):
                start_line -= 1

            end_line = line
            lines = …
Run Code Online (Sandbox Code Playgroud)

python pyqt scintilla qscintilla pyqt5

6
推荐指数
2
解决办法
491
查看次数

如何在QScintilla中使用自定义折叠图标?

请考虑以下代码段:

import sys

from PyQt5.Qsci import QsciScintilla
from PyQt5.Qt import *

if __name__ == '__main__':
    app = QApplication(sys.argv)
    view = QsciScintilla()

    # http://www.scintilla.org/ScintillaDoc.html#Folding
    view.setFolding(QsciScintilla.BoxedTreeFoldStyle)
    # view.setFolding(QsciScintilla.BoxedFoldStyle)
    # view.setFolding(QsciScintilla.CircledFoldStyle)
    # view.setFolding(QsciScintilla.CircledTreeFoldStyle)
    # view.setFolding(QsciScintilla.NoFoldStyle)
    # view.setFolding(QsciScintilla.PlainFoldStyle)

    lines = [
        (0, "def foo():"),
        (1, "    x = 10"),
        (1, "    y = 20"),
        (1, "    return x+y"),
        (-1, ""),
        (0, "def bar(x):"),
        (1, "    if x > 0:"),
        (2, "        print('this is')"),
        (2, "        print('branch1')"),
        (1, "    else:"),
        (2, "        print('and this')"),
        (2, …
Run Code Online (Sandbox Code Playgroud)

python scintilla qscintilla pyqt5

6
推荐指数
1
解决办法
290
查看次数

如何在QScintilla中实现SublimeText逐级功能

我正在尝试fold_by_level在QScintilla组件上实现SublimeText3功能,但我不知道如何做到这一点,到目前为止我已经提出了这个代码:

import sys
import re
import math

from PyQt5.Qt import *  # noqa

from PyQt5.Qsci import QsciScintilla
from PyQt5 import Qsci
from PyQt5.Qsci import QsciLexerCPP


class Foo(QsciScintilla):

    def __init__(self, parent=None):
        super().__init__(parent)

        # http://www.scintilla.org/ScintillaDoc.html#Folding
        self.setFolding(QsciScintilla.BoxedTreeFoldStyle)

        # Indentation
        self.setIndentationsUseTabs(False)
        self.setIndentationWidth(4)
        self.setBackspaceUnindents(True)
        self.setIndentationGuides(True)

        # Set the default font
        self.font = QFont()
        self.font.setFamily('Consolas')
        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("#cccccc"))

        # Indentation
        self.setIndentationsUseTabs(False)
        self.setIndentationWidth(4)
        self.setBackspaceUnindents(True)

        lexer …
Run Code Online (Sandbox Code Playgroud)

python pyqt scintilla folding qscintilla

5
推荐指数
1
解决办法
263
查看次数