-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextloader.py
89 lines (67 loc) · 2.66 KB
/
textloader.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
__version__ = "0.1.1"
__author__ = "Suazo-kun ([email protected])"
from threading import Thread
from time import sleep
from sys import platform
class BaseTextLoader:
_animation: list = []
_current_animation: int = -1
_thread: Thread = None
_animation_delay: float = 0.1
_stop_animation: bool = False
@property
def number_of_characters(self) -> int:
return len(self._animation)
@property
def current_animation(self) -> int:
return self._current_animation if self._current_animation >= 0 else 0
@property
def current_character(self) -> str:
return self._animation[self.current_animation]
@property
def animation_delay(self):
return self._animation_delay
@animation_delay.setter
def animation_delay(self, delay: float):
if type(delay) != float:
raise ValueError("delay is not float.")
else:
self._animation_delay = delay
def NextAnimation(self) -> str:
if self._thread == Thread and self._thread.is_alive():
return ""
return self._next_animation()
def PrintAsyncAnimation(self):
if (self._thread is None) or (not self._thread.is_alive()):
self._thread = Thread(
target=self._print_async_animation, daemon=True)
self._thread.start()
def StopAsyncAnimation(self):
if (type(self._thread) == Thread) and (self._thread.is_alive()):
self._stop_animation = True
self._thread.join()
self._stop_animation = False
def _next_animation(self):
if len(self._animation) == 0:
return ""
elif self._current_animation == len(self._animation)-1:
self._current_animation = 0
return self._animation[self._current_animation]
else:
self._current_animation += 1
return self._animation[self._current_animation]
def _print_async_animation(self):
while not self._stop_animation:
print('\r'+self._next_animation(), end="")
sleep(self._animation_delay)
print()
class CirculatePointsLoader(BaseTextLoader):
_animation = ['⠾', '⠽', '⠻', '⠟', '⠯', '⠷']
class DownPointsLoader(BaseTextLoader):
_animation = [
'⠁', '⠂', '⠄', '⡀', '⡈', '⡐', '⡠', '⣀', '⣁', '⣂', '⣄', '⣌', '⣔', '⣤',
'⣥', '⣦', '⣮', '⣶', '⣷', '⣿', '⣿', '⣿']
class SetPointsLoader(BaseTextLoader):
_animation = ['⡀', '⡠', '⡢', '⡪', '⡫', '⡻', '⡿', '⣿', '⣿', '⣿']
class RotatePointsLoader(BaseTextLoader):
_animation = ['⣀', '⡄', '⠆', '⠃', '⠉', '⠘', '⠰', '⢠']