Margins

Margin style

In the Scintilla editor you can set 5 margins, numbered 0 to 4. left to right. Each margin has its own properties, like type, width etc...

When clicked each margin emits the margin-click signal, you can assign it a signal handler to, for example, select the whole line or to implement folding.

Using a margin number outside the valid range has no effect. By default, margin 0 is set to display line numbers, but is given a width of 0, so it is hidden. Margin 1 is set to display non-folding symbols and is given a width of 16 pixels, so it is visible. Margin 2 is set to display the folding symbols, but is given a width of 0, so it is hidden. Of course, you can set the margins to be whatever you wish.

gtkscintilla.Scintilla.set_margin(margin_id[, marginspec = None | **kwargs])

This sets the margin settings, with margin_id you specify the margin numbered 0 to 4, you can set the margin properties using a gtkscintilla.style.MarginStyle instance or using keyword arguments.

Available properties (keyword arguments):

Parameters:
  • type – You can use the predefined constants SC_MARGIN_SYMBOL (0) and SC_MARGIN_NUMBER (1) to set a margin as either a line number or a symbol margin. A margin with application defined text may use SC_MARGIN_TEXT (4) or SC_MARGIN_RTEXT (5) to right justify the text. By convention, margin 0 is used for line numbers and the next two are used for symbols. You can also use the constants SC_MARGIN_BACK (2) and SC_MARGIN_FORE (3) for symbol margins that set their background colour to match the default background and foreground colours.
  • width – These routines set and get the width of a margin in pixels. A margin with zero width is invisible. By default, Scintilla sets margin 1 for symbols with a width of 16 pixels, so this is a reasonable guess if you are not sure what would be appropriate. Line number margins widths should take into account the number of lines in the document and the line number style.
  • sensitive – Each of the five margins can be set sensitive or insensitive to mouse clicks. A click in a sensitive margin sends a margin-click notification to the container. Margins that are not sensitive act as selection margins which make it easy to select ranges of lines. By default, all margins are insensitive.
  • mask – For a symbol margin you can set to display a selection of symbols, and to hide others, like a mask. To set a non-folding margin use ~SC_MASK_FOLDERS. to set a folding margin use SC_MASK_FOLDERS (This is the default set by Scintilla). ~SC_MASK_FOLDERS is 0x1FFFFFF in hexadecimal or 33554431 decimal. Of course, you may need to display all 32 symbols in a margin, in which case use -1.
gtkscintilla.Scintilla.get_margin(margin_id)
This method returns an instance of gtkscintilla.style.MarginStyle that contains all the properties of the margin identified by margin_id as attributes.
class gtkscintilla.style.MarginStyle(**kwargs)

This class has type, width, sensitive, mask attributes. The constructor is like gtkscintilla.Scintilla.set_margin() without the margin_id parameter

You can retrieve infos about the attributes simply ... retrieving it:

>>> a = MarginStyle(width=16)
>>> a.width
16

Margin text and global settings

gtkscintilla.Scintilla.set_margin_left(pixels)
gtkscintilla.Scintilla.set_margin_left()
gtkscintilla.Scintilla.set_margin_right(pixels)
gtkscintilla.Scintilla.set_margin_right()
These messages set and get the width of the blank margin on both sides of the text in pixels. The default is to one pixel on each side.
gtkscintilla.Scintilla.set_fold_margin_colour(colour)
These method allow changing the colour of the fold margin and fold margin highlight.
gtkscintilla.Scintilla.margin_set_text(line, text)
gtkscintilla.Scintilla.margin_get_text(line)

This sets the text displayed in the margin text. Before using these methods you have to prepare the margin to contain the text:

>>> s = Scintilla()
>>> s.set_margin(0, type=SC_MARGIN_TEXT, width = 40)

Then you can set the text on the margin at the specified line.

gtkscintilla.Scintilla.margin_set_style(line, style)
gtkscintilla.Scintilla.margin_get_style(line)
This set/get the style id associated with the text at the line line
gtkscintilla.Scintilla.margin_set_styled_text(line, st_text)
gtkscintilla.Scintilla.margin_get_styled_text(line)
These methods are similar to the gtkscintilla.Scintilla.margin_set_text() / get_text methods. It takes an instance of gtkscintilla.StyledText
gtkscintilla.Scintilla.margin_text_clear_all()
Remove the margin text from all lines.
gtkscintilla.Scintilla.margin_set_style_offset(style)
gtkscintilla.Scintilla.margin_get_style_offset()
Margin styles may be completely separated from standard text styles by setting a style offset. For example, margin_set_style() or margin_set_styles() has the offset added before looking up the style.

Table Of Contents

Previous topic

Selection and Information

Next topic

Annotations

This Page