Small Python module to display loading animations in the console/terminal.
from time import sleep
from textloader import CirculatePointsLoader
if __name__ == "__main__":
temp = CirculatePointsLoader()
temp.PrintAsyncAnimation()
sleep(temp.number_of_characters * temp.animation_delay * 5)
temp.StopAsyncAnimation()
It is the base class from which all other classes in the code inherit. This class contains all the fundamental methods and properties, the classes that inherit to this super class only modify the property _animation, which is a list that contains all the characters that will be printed. Its _animation property is empty, so using this class directly will not show any noticeable result, unlike the following classes:
Its animation consists of dots that simulate an external rotation.
_animation = ['⠾', '⠽', '⠻', '⠟', '⠯', '⠷']
Its animation consists of dots that simulate falling to complete a 2x3 rectangle.
_animation = [
'⠁', '⠂', '⠄', '⡀', '⡈', '⡐', '⡠', '⣀', '⣁', '⣂', '⣄', '⣌', '⣔', '⣤',
'⣥', '⣦', '⣮', '⣶', '⣷', '⣿', '⣿', '⣿']
Its animation consists of setting several points every so often until a 2x3 rectangle is completed.
_animation = ['⡀', '⡠', '⡢', '⡪', '⡫', '⡻', '⡿', '⣿', '⣿', '⣿']
Its animation consists of dots that simulate an internal rotation.
_animation = ['⣀', '⡄', '⠆', '⠃', '⠉', '⠘', '⠰', '⢠']
An integer that returns the number of characters in the animation.
from textloader import *
rtl = RotatePointsLoader()
print(rtl.number_of_characters)
# Output: 8
An integer that returns the position of the last returned or printed character.
from textloader import *
rtl = RotatePointsLoader()
print(rtl.current_animation)
print(rtl.NextAnimation())
print(rtl.NextAnimation())
print(rtl.current_animation)
# Output:
# 0
# ⣀
# ⡄
# 1
A string that returns the last returned or printed character.
from textloader import *
rtl = RotatePointsLoader()
print(rtl.current_character)
rtl.NextAnimation()
rtl.NextAnimation()
print(rtl.current_character)
# Output:
# ⣀
# ⡄
A float that determines the time to wait before proceeding to the next character. Internally, it is used when PrintAsyncAnimation is active. The default value is 0.1.
from textloader import *
rtl = RotatePointsLoader()
print(rtl.animation_delay)
rtl.animation_delay = 0.5
print(rtl.animation_delay)
# Output:
# 0.1
# 0.5
Return the following character. In case the last character has already been returned, this method will consequently restart the count and return the first character.
from textloader import *
rtl = RotatePointsLoader()
print(rtl.NextAnimation())
print(rtl.NextAnimation())
# Output:
# ⣀
# ⡄
Starts a thread in which the animation will be printed until the StopAsyncAnimation method is called or until the program terminates. NOTE: The method is executed in a daemon thread to avoid deadlocks when terminating the program without having previously called StopAsyncAnimation.
from textloader import *
from time import sleep
rtl = RotatePointsLoader()
rtl.PrintAsyncAnimation()
sum_result = 0
for i in range(1, 6):
sleep(0.5)
sum_result += i
rtl.StopAsyncAnimation()
print(sum_result)
# Output:
# (animation)
# 15
Stops the call made to PrintAsyncAnimation.
from textloader import *
from time import sleep
rtl = RotatePointsLoader()
rtl.PrintAsyncAnimation()
sum_result = 0
for i in range(1, 6):
sleep(0.5)
sum_result += i
rtl.StopAsyncAnimation()
print(sum_result)
# Output:
# (animation)
# 15