-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmixins.py
73 lines (59 loc) · 1.86 KB
/
mixins.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# vault.py
from rich.align import Align
from rich.box import HEAVY
from rich.console import RenderableType
from rich.panel import Panel
from rich.style import Style
from rich.text import Text
from textual.reactive import Reactive
from settings import GREEN, YELLOW
class ButtonMixin:
clicked: Reactive[RenderableType] = Reactive(False)
mouse_over: Reactive[RenderableType] = Reactive(False)
height = None
def render(self) -> Panel:
renderable = Align.center(
Text(
self.on_click_label if self.clicked else self.label,
),
style=YELLOW if self.mouse_over else GREEN,
vertical='middle'
)
return Panel(
renderable,
title=self.title,
title_align='left',
height=self.height,
border_style=Style(
color=YELLOW if self.mouse_over else GREEN
),
box=HEAVY
)
def on_click(self) -> None:
self.clicked = True
def on_enter(self) -> None:
self.mouse_over = True
def on_leave(self) -> None:
self.mouse_over = False
self.clicked = False
class InputTextMixin(ButtonMixin):
label: Reactive[RenderableType] = Reactive('')
clicked: Reactive[RenderableType] = Reactive(False)
mouse_over: Reactive[RenderableType] = Reactive(False)
height = None
def render(self) -> RenderableType:
renderable = Align.center(
Text(self.label),
style=YELLOW if self.clicked else GREEN,
vertical='middle'
)
return Panel(
renderable,
title=self.title if self.clicked else '',
title_align='left',
height=self.height,
border_style=Style(
color=YELLOW if self.mouse_over else GREEN
),
box=HEAVY
)