|
|
|
@ -30,9 +30,14 @@ from TermTk.TTkWidgets.widget import TTkWidget |
|
|
|
|
|
|
|
|
|
|
|
class TTkLabel(TTkWidget): |
|
|
|
class TTkLabel(TTkWidget): |
|
|
|
'''TTkLabel''' |
|
|
|
'''TTkLabel''' |
|
|
|
__slots__ = ('_text','_color','_alignment') |
|
|
|
|
|
|
|
|
|
|
|
classStyle = { |
|
|
|
|
|
|
|
'default': {'color': TTkColor.RST }, |
|
|
|
|
|
|
|
'disabled': {'color': TTkColor.fg('#888888')}, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__slots__ = ('_text', '_alignment') |
|
|
|
def __init__(self, *args, **kwargs): |
|
|
|
def __init__(self, *args, **kwargs): |
|
|
|
self._color = kwargs.get('color', TTkColor.RST ) |
|
|
|
|
|
|
|
text = kwargs.get('text', TTkString() ) |
|
|
|
text = kwargs.get('text', TTkString() ) |
|
|
|
if issubclass(type(text), TTkString): |
|
|
|
if issubclass(type(text), TTkString): |
|
|
|
self._text = text.split('\n') |
|
|
|
self._text = text.split('\n') |
|
|
|
@ -56,13 +61,11 @@ class TTkLabel(TTkWidget): |
|
|
|
|
|
|
|
|
|
|
|
def color(self): |
|
|
|
def color(self): |
|
|
|
'''color''' |
|
|
|
'''color''' |
|
|
|
return self._color |
|
|
|
return self.style()['default']['color'] |
|
|
|
|
|
|
|
|
|
|
|
def setColor(self, color): |
|
|
|
def setColor(self, color): |
|
|
|
'''setColor''' |
|
|
|
'''setColor''' |
|
|
|
if self._color != color: |
|
|
|
self.mergeStyle({'default':{'color':color}}) |
|
|
|
self._color = color |
|
|
|
|
|
|
|
self.update() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def text(self): |
|
|
|
def text(self): |
|
|
|
'''text''' |
|
|
|
'''text''' |
|
|
|
@ -79,11 +82,15 @@ class TTkLabel(TTkWidget): |
|
|
|
self._textUpdated() |
|
|
|
self._textUpdated() |
|
|
|
|
|
|
|
|
|
|
|
def paintEvent(self, canvas): |
|
|
|
def paintEvent(self, canvas): |
|
|
|
forceColor = self.color()!=TTkColor.RST |
|
|
|
style = self.currentStyle() |
|
|
|
|
|
|
|
color = style['color'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
forceColor = color!=TTkColor.RST |
|
|
|
|
|
|
|
|
|
|
|
w = self.width() |
|
|
|
w = self.width() |
|
|
|
for y,text in enumerate(self._text): |
|
|
|
for y,text in enumerate(self._text): |
|
|
|
canvas.drawText(pos=(0,y), text=' '*w, color=self.color(), forceColor=forceColor) |
|
|
|
canvas.drawText(pos=(0,y), text=' '*w, color=color, forceColor=forceColor) |
|
|
|
canvas.drawText(pos=(0,y), text=text, width=w, alignment=self._alignment, color=self.color(), forceColor=forceColor) |
|
|
|
canvas.drawText(pos=(0,y), text=text, width=w, alignment=self._alignment, color=color, forceColor=forceColor) |
|
|
|
|
|
|
|
|
|
|
|
def _textUpdated(self): |
|
|
|
def _textUpdated(self): |
|
|
|
w, h = self.size() |
|
|
|
w, h = self.size() |
|
|
|
@ -93,5 +100,3 @@ class TTkLabel(TTkWidget): |
|
|
|
self.setMinimumSize(textWidth, 1) |
|
|
|
self.setMinimumSize(textWidth, 1) |
|
|
|
self.update() |
|
|
|
self.update() |
|
|
|
|
|
|
|
|
|
|
|
def colorUpdated(self, color): |
|
|
|
|
|
|
|
self.update() |
|
|
|
|
|
|
|
|