Saturday, 20 April 2019

How to use custom folding icons in QScintilla?

Consider this snippet:

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, "        print('is branch2')"),
        (-1, ""),
        (-1, ""),
        (-1, ""),
        (-1, "print('end')"),

    ]

    view.setText("\n".join([b for a, b in lines]))
    MASK = QsciScintilla.SC_FOLDLEVELNUMBERMASK

    for i, tpl in enumerate(lines):
        level, line = tpl
        if level >= 0:
            view.SendScintilla(view.SCI_SETFOLDLEVEL, i, level | QsciScintilla.SC_FOLDLEVELHEADERFLAG)
        else:
            view.SendScintilla(view.SCI_SETFOLDLEVEL, i, 0)

    view.show()
    app.exec_()

I'd like to figure out whether it's possible to change the folding icon to a custom icon different than the ones offered by QScintilla, specifically I'd like to have a down arrow similar to Sublime's:

enter image description here

By looking at the QSciScintilla foldstyle you can see there isn't anything that remains similar.

In fact, not only that, I was also wondering if it'd be possible to achieve this nice subtle effect of fading away the folding icon when the mouse position enters/leaves the margin area, take a look:

enter image description here

Which it's a really nice feature, that way while you're coding you won't get distracted by the "always visible" folding icons.

In this thread it seems there is something called SC_MARK_ARROWDOWN but not sure if that could be used as a folding icon... in any case, i'd still prefer my custom picture as I'll be using a monokai theme and I'd like the icon to look as elegant as Sublime's.

Below you'll find 2 12x12 pngs I've created to represent the dark & light arrowdowns.

enter image description here enter image description here



from How to use custom folding icons in QScintilla?

No comments:

Post a Comment