File: label.py

package info (click to toggle)
python-vispy 0.6.6-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 21,240 kB
  • sloc: python: 57,407; javascript: 6,810; makefile: 63; sh: 5
file content (49 lines) | stat: -rw-r--r-- 1,335 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright (c) Vispy Development Team. All Rights Reserved.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
# -----------------------------------------------------------------------------

from .widget import Widget
from ...visuals import TextVisual


class Label(Widget):
    """Label widget

    Parameters
    ----------
    text : str
        The label.
    rotation : float
        The rotation of the label.
    **kwargs : dict
        Keyword arguments to pass to TextVisual.
    """
    def __init__(self, text, rotation=0., **kwargs):
        self._text_visual = TextVisual(text=text, rotation=rotation, **kwargs)
        self.rotation = rotation
        Widget.__init__(self)
        self.add_subvisual(self._text_visual)
        self._set_pos()
        
    def on_resize(self, event):
        """Resize event handler

        Parameters
        ----------
        event : instance of Event
            The event.
        """
        self._set_pos()
        
    def _set_pos(self):
        self._text_visual.pos = self.rect.center
        
    @property
    def text(self):
        return self._text_visual.text
    
    @text.setter
    def text(self, t):
        self._text_visual.text = t