Style definition

The styles are registered by id, usually they are used by lexers, but also there are some predefined ids that you can set to modify the appearence of the text.

There are 256 lexer styles that you can set (0-255), I suggest you to use the highest numbers because low numbers are usually used by lexers.

The default styles ids starts from 32 and control standard text behaviour and appeareance:

Attribute Id Description
default 32
This style defines the attributes that all styles receive when the
method gtkscintilla.Scintilla.style_clear_all() is used.
linenumber 33 This style sets the attributes of the text used to display line numbers in a line number margin.
bracelight 34 This style sets the attributes used when highlighting braces with the gtkscintilla.Scintilla.brace_hightlight() and when highlighting thecorresponding indentation set_highlight_guide.
bracebad 35 This style sets the display attributes used when marking an unmatched brace with the gtkscintilla.Scintilla.brace_badlight() method.
controlchar 36 This style sets the font used when drawing control characters. Only the font, size, bold, italics, and character set attributes are used and not the colour attributes.
indentguide 37 This style sets the foreground and background colours used when drawing the indentation guides.
calltip 38 Call tips normally use the font attributes defined by default. Use of gtkscintilla.Scintilla.calltip_use_style() causes call tips to use this style instead. Only the font face name, font size, foreground and background colours and character set attributes are used.
lastpredefined 39 To make it easier for client code to discover the range of styles that are predefined, this is set to the style number of the last predefined style. This is currently set to 39 and the last style with an identifier is 38, which reserves space for one future predefined style.

For each style you can set the font name, size and use of bold, italic and underline, foreground and background colour and the character set. You can also choose to hide text with a given style, display all characters as upper or lower case and fill from the last character on a line to the end of the line (for embedded languages). There is also an experimental attribute to make text read-only.

gtkscintilla.Scintilla.set_style(id[, stylesp | **attrs])

This methods assigns to the id the text style specified or by a stylesp TextStyle instance, or by simple kwargs. It’s simpler with an example:

>>> s = Scintilla()
>>> ts = TextStyle(color = "blue", font = "!Bitstream Vera")
>>> s.set_style(2, ts)
>>> s.set_style(1, color = "#000fff", italics=True)

They’re equivalent. The get_style returns a TextStyle instance.

Here the complete specification of text styles:

  • color – The text’s foreground color. Takes a color specification, it could be a string like “blue”, or a code like #000000, or a gtk.gdk.Color instance, or an rgb tuple like (0,12,255), use your fantasy!
  • font – Use a pango font name preceded by a “!”, like “!Bitstream Vera”.
  • bold – True or False
  • italics – True or False
  • size – The size of the text in points.
  • background – The text background, see color for details on color specification.
  • eolfilled – True or False, the end of line is filled with the background color?
  • case – You can set one of this three constants: SC_CASE_UPPER , SC_CASE_LOWER, SC_CASE_MIXED
  • visible – The text is visible? True or False
  • underline – Underlined or not? True or False
  • changeable – True or False
  • hotspot – True or False. This is used to mark ranges of text that can detect mouse clicks. The cursor changes to a hand over hotspots, and the foreground, and background colours may change and an underline appear to indicate that these areas are sensitive to clicking. This may be used to allow hyperlinks to other documents
  • charset – You can set a style to use a different character set than the default. The places where such characters sets are likely to be useful are comments and literal strings. ValuesSC_CHARSET_ANSI, SC_CHARSET_CYRILLIC (code page 1251), SC_CHARSET_EASTEUROPE, SC_CHARSET_GB2312, SC_CHARSET_HANGUL, SC_CHARSET_RUSSIAN (KOI8-R), SC_CHARSET_SHIFTJIS, and SC_CHARSET_8859_15.

Applying Styles - Styling

gtkscintilla.Scintilla.apply_style(style_num, start, end)

Apply the style registered with number style_num in the range start, end. Remember that to reset the style to default... you have to apply the style default with id = 32.

Table Of Contents

Previous topic

Scrolling and automatic scrolling

Next topic

Caret, selection, and hotspot styles

This Page