GLXCurses.Label module

class GLXCurses.Label.Label[source]

Bases: GLXCurses.Misc.Misc, GLXCurses.libs.Movable.Movable

angle

The angle that the baseline of the label makes with the horizontal, in degrees, measured counterclockwise. An angle of 90 reads from from bottom to top, an angle of 270, from top to bottom.

Ignored if the label is selectable.

Allowed values: [0,360]

Returns:angle that the baseline of the label
Return type:int
attributes

A list of style attributes to apply to the text of the label.

Returns:A list of style attributes
Return type:list
cursor_position

The current position of the insertion cursor in chars.

Returns:The cursor_position property value
Return type:int
label

The contents of the label.

If the string contains TXT MarkDown, you will have to set the use_markdown property to True in order for the label to display the MarkDown attributes.

See also set_markdown() for a convenience function that sets both this property and the use_markdown property at the same time.

If the string contains underlines acting as mnemonics, you will have to set the use_underline property to True in order for the label to display them.

Returns:The content of the label
Return type:str
lines

The number of lines to which an ellipsized, wrapping label should be limited. This property has no effect if the label is not wrapping or ellipsized.

Set this property to -1 if you don’t want to limit the number of lines.

Returns:The number of lines to which an ellipsized
Return type:int
max_width_chars

The desired maximum width of the label, in characters.

If this property is set to -1, the width will be calculated automatically.

See the section on text layout for details of how width_chars and max_width_chars determine the width of ellipsized and wrapped labels.

Returns:Maximum width of the label, in characters
Return type:int
mnemonic_keyval

The mnemonic accelerator key for this label.

Default value: 16777215

mnemonic_widget

The GLXCurses.Widget to be activated when the label’s mnemonic key is pressed.

Returns:The GLXCurses.Widget to be activated or None if not set

:rtype GLXCurses.Widget or None

pattern

A string with _ characters in positions correspond to characters in the text to underline.

Returns:characters in the text use for underline
Return type:str
selectable

Whether the GLXCurses.Label text can be selected with the mouse.

Returns:True if GLXCurses.Label text can be selected
Return type:bool
selection_bound

The position of the opposite end of the selection from the cursor in chars.

Returns:The position in chars
Return type:int
single_line_mode

Whether the label is in single line mode. In single line mode, the height of the label does not depend on the actual text, it is always set to ascent + descent of the font.

This can be an advantage in situations where resizing the label because of text changes would be distracting, e.g. in a GLXCurses.StatusBar or GLXCurses.MessageBar.

Default value: False

Returns:True if label is in single line mode
Return type:bool

Set this property to True to make the label track which links have been visited.

It will then apply the GLXC.STATE_FLAG_VISITED when rendering this link, in addition to GLXC.STATE_FLAG_LINK.

Default value: True

Returns:True if label track which links have been visited
Return type:bool
use_markdown

The text of the label includes TXT MarkDown.

Default value: False

Returns:True if MarkDown is used
Return type:bool
use_underline

If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key.

Default value: False

Returns:True if underline is display on text when use a mnemonic accelerator key
Return type:bool
width_chars

The desired width of the label, in characters. If this property is set to -1, the width will be calculated automatically.

See the section on text layout for details of how width_chars and max_width_chars determine the width of ellipsized and wrapped labels.

Returns:The desired width of the label, in characters.
Return type:int
wrap

If set, wrap lines if the text becomes too wide.

Returns:True if wrap is in use
Return type:bool
wrap_mode

If line wrapping is on (see the wrap property) this controls how the line wrapping is done.

The default is GLXC.WRAP_WORD, which means wrap on word boundaries.

Returns:How the line wrapping is done
Return type:GLXCurses.GLXC.WrapMode
new(string=None)[source]

Creates a new label with the given text inside it.

You can pass None to get an empty GLXCurses.Label.

Parameters:string (str or None) – The text of the GLXCurses.Label.
Returns:The new GLXCurses.Label it self
Return type:GLXCurses.Label
set_text(string=None)[source]

Sets the text within the GtkLabel widget. It overwrites any text that was there before.

This function will clear any previously set mnemonic accelerators, and set the use_underline property to False as a side effect.

This function will set the use_markdown property to False as a side effect.

See also: GLXCurses.Label().set_markdown()

Parameters:string (str or None) – The text you want to set
set_attributes(attributes=None)[source]

Sets a GLXC.StateFlags; the attributes in the list are applied to the label text.

The attributes set with this function will be applied and merged with any other attributes previously effected by way of the use_underline or use_markup properties.

While it is not recommended to mix markdown strings with manually set attributes, if you must; know that the attributes will be applied to the label after the markdown string is parsed.

Parameters:attributes (list or None) – a GLXC.StateFlags
set_markdown(string=None)[source]

Parses string which is marked down with the text markdown language, setting the label’s text and attribute list based on the parse results.

This function will set the use_markup property to True as a side effect.

If you set the label contents using the label property you should also ensure that you set the use_markup property accordingly.

See also: GLXCurses.Label().set_text()

Parameters:string (str) – A markdown string (see text markdown format)
set_markdown_with_mnemonic(string)[source]

Parses string which is marked down with the text markdown language, setting the label’s text and attribute list based on the parse results.

If characters in string are preceded by an underscore, they are underlined indicating that they represent a keyboard accelerator called a mnemonic.

The mnemonic key can be used to activate another GLXCurses.Widget, chosen automatically, or explicitly using GLXCurses.Label().set_mnemonic_widget().

Parameters:string (str) – A markdown string (see text markdown format)
set_pattern(pattern=None)[source]

The pattern of underlines you want under the existing text within the GLXCurses.Label widget.

For example if the current text of the label says “FooBarBaz” passing a pattern of “___ ___” will underline “Foo” and “Baz” but not “Bar”.

Parameters:pattern (str or None) – The pattern as described above.
set_justify(jtype=None)[source]

Sets the alignment of the lines in the text of the label relative to each other.

GLXCurses.GLXC.JUSTIFY_LEFT is the default value when the widget is first created with GLXCurses.Label().new()

If you instead want to set the alignment of the label as a whole, use GLXCurses.Widget().set_halign() instead.

GLXCurses.Label().set_justify() has no effect on labels containing only a single line.

Parameters:jtype (str or None) – a GLXCurses.GLXC.Justification
set_xalign(xalign=None)[source]

Sets the xalign property for label .

Parameters:xalign (float or None) – the new xalign value, between 0 and 1
set_yalign(yalign=None)[source]

Sets the yalign property for label .

Parameters:yalign (float or None) – the new yalign value, between 0 and 1
set_width_chars(n_chars=None)[source]

Sets the desired width in characters of label to n_chars .

Parameters:n_chars (int or None) – the new desired width, in characters.
set_max_width_chars(n_chars)[source]

Sets the desired maximum width in characters of label to n_chars .

Parameters:n_chars (int or None) – the new desired maximum width, in characters.
set_line_wrap(wrap=None)[source]

Toggles line wrapping within the GtkLabel widget. True makes it break lines if text exceeds the widget’s size. False lets the text get cut off by the edge of the widget if it exceeds the widget size.

Note that setting line wrapping to TRUE does not make the label wrap at its parent container’s width, because GLXCurses widgets conceptually can’t make their requisition depend on the parent container’s size. For a label that wraps at a specific position, set the label’s width using GLXCurses.Widget().set_size_request()

Parameters:wrap (bool or None) – True if wrap is enable
set_line_wrap_mode(wrap_mode=None)[source]

If line wrapping is on (see GLXCurses.Label().set_line_wrap()) this controls how the line wrapping is done. The default is GLXCurses.GLXC.WRAP_WORD which means wrap on word boundaries.

Parameters:wrap_mode (str or None) – the line wrapping mode
set_lines(lines=None)[source]

Sets the number of lines to which an ellipsized, wrapping label should be limited. This has no effect if the label is not wrapping or ellipsized.

Set this to -1 if you don’t want to limit the number of lines.

Parameters:lines (int or None) – the desired number of lines, or -1
get_mnemonic_keyval()[source]

If the label has been set so that it has an mnemonic key this function returns the keyval used for the mnemonic accelerator.

If there is no mnemonic set up it returns None.

Returns:ord() keyval usable for accelerators, or None
Return type:int or None
get_selectable()[source]

Gets the value set by GLXCurses.Label().set_selectable().

Returns:True if the user can copy text from the label
get_text()[source]

Fetches the text from a label widget, as displayed on the screen.

This does not include any embedded underlines indicating mnemonics or markdown.

(See GLXCurses.Label().get_label())

Returns:the text in the label widget. This is the internal string used by the label, and must not be modified.
Return type:str or None
new_with_mnemonic(string=None)[source]

Creates a new GtkLabel, containing the text in str .

If characters in str are preceded by an underscore, they are underlined. If you need a literal underscore character in a label, use ‘__’ (two underscores). The first underlined character represents a keyboard accelerator called a mnemonic. The mnemonic key can be used to activate another widget, chosen automatically, or explicitly using gtk_label_set_mnemonic_widget().

If GLXCurses.Label().set_mnemonic_widget() is not called, then the first activatable ancestor of the GLXCurses.Label will be chosen as the mnemonic widget. For instance, if the label is inside a button or menu item, the button or menu item will automatically become the mnemonic widget and be activated by the mnemonic.

Parameters:string (str or None) – The text of the label, with an underscore in front of the mnemonic character.
select_region(start_offset=None, end_offset=None)[source]

Selects a range of characters in the label, if the label is selectable. See GLXCurses.Label().set_selectable().

If the label is not selectable, this function has no effect. If start_offset or end_offset are -1, then the end of the label will be substituted.

Parameters:
  • start_offset (int) – start offset (in characters not bytes)
  • end_offset (int) – end offset (in characters not bytes)
Raises:

TypeError – when

set_use_underline(setting)[source]
get_use_underline()[source]
set_mnemonic_widget(widget)[source]
get_mnemonic_widget()[source]
set_selectable(setting=None)[source]

Selectable labels allow the user to select text from the label, for copy-and-paste.

Parameters:setting (bool or None) – True to allow selecting text in the label
set_text_with_mnemonic(string)[source]

Sets the label’s text from the string str . If characters in str are preceded by an underscore, they are underlined indicating that they represent a keyboard accelerator called a mnemonic.

The mnemonic key can be used to activate another widget, chosen automatically, or explicitly using GLXCurses.Label().set_mnemonic_widget().

Parameters:string (str) – a string
draw_widget_in_area()[source]

Be here for be overwrite by every widget

update_preferred_sizes()[source]
get_justify()[source]

Returns the justification of the label.

See also

Label.set_justify() for set the justification.

Returns:the justification
Return type:GLXCurses.GLXC.Justification
get_line_wrap()[source]

The get_line_wrap() method returns the value of the “wrap” property.

If “wrap” is True the lines in the label are automatically wrapped. See set_line_wrap().

Returns:True if wrap is enable
Return type:bool
get_width_chars()[source]

The get_width_chars() method returns the value of the width-chars

property that specifies the desired width of the label in characters.

Returns:width of the label in characters
Return type:int
set_single_line_mode(single_line_mode)[source]
get_single_line_mode()[source]
get_max_width_chars()[source]
get_line_wrap_mode()[source]