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
|