A customizable loading tool
Project description
enimation Package
enimation is a Python package that provides customizable loading animations for your console applications. It allows developers to easily integrate various loading indicators into their programs to enhance user experience.
Installation
You can install the enimation package using pip:
pip install enimation
Overview
The enimation package offers predefined animations and allows you to create custom animations. You can use these animations to indicate loading processes, improving the interactivity of your console applications.
enimation Features
-
Predefined Animations
The package comes with multiple built-in loading animations:- Rotating Spinner
- Dots Progress
- Bouncing Ball
- Wave Animation
- Loading Bar with Percentage
- Blinking Arrows
- Scrolling Dashes
- Growing Dots
- Heartbeat Animation
- Typing Effect
-
Customizable Animations
- Create your own custom loading animations by defining your own functions.
- Custom animations can include dynamic loading text and other effects.
- Easily integrate custom animations using the
CustomLoading
class.
-
Stop Mechanism
- All animations include a
stop_event
that ensures graceful termination when loading is complete. - No need to manually interrupt animations — they stop automatically when the task ends.
- All animations include a
-
Text Customization
- You can customize the loading text for both predefined and custom animations. By default, the text is set to "Loading", but this can be changed to any string the user desires.
-
Animation Timing Control
- Control the speed of animations by adjusting the sleep intervals inside the animation logic.
-
Lightweight and Easy to Integrate
- The package is lightweight and can be easily integrated into any Python project. It's designed to work seamlessly without needing complex setup.
-
Console Output Control
- The animations utilize
sys.stdout.write()
andsys.stdout.flush()
for smooth, non-newline output in the console.
- The animations utilize
-
Versatile Use Cases
- Perfect for CLI applications, long-running tasks, or any situation where you need to provide a visual loading indicator to the user.
Usage
Basic Usage decorator
Here's how to use the predefined animations in your Python project:
- Import the Loading Decorator and Animation Functions:
from enimation import loading
from enimation.motions import rotating_spinner
- Create Your Function with a Loading Animation:
Use the @loading
decorator to wrap your function, specifying the desired animation:
@loading(custom=rotating_spinner)
def main():
# Simulate a long-running task
time.sleep(5)
print("\nProcess complete!")
- Run Your Program:
Call the main function to see the loading animation in action:
if __name__ == "__main__":
main()
Advanced Usage decorator
For more advanced usage, you can customize the displayed text for each animation:
- Using Custom Text:
To use custom text in your animation, modify the animation function call as follows:
@loading(custom=lambda stop_event: rotating_spinner(stop_event, text="Processing..."))
def main():
# Simulate a long-running task
time.sleep(5)
print("\nProcess complete!")
Basic Usage Example
To use a predefined animation, follow this example:
from enimation.loading import CustomLoading
import time
def main():
# Create an instance of CustomLoading with a predefined animation
loader = CustomLoading(custom='rotating_spinner')
loader.start() # Start the loading animation
time.sleep(5) # Simulate a long-running task
loader.stop() # Stop the loading animation
print("\nTask complete!") # Task completion message
if __name__ == "__main__":
main()
Creating Custom Animations
To create your own custom animation for the enimation package, follow these steps:
Steps to Create a Custom Animation
- Define a Function: Your custom animation should be defined as a function that accepts a stop_event parameter, which allows the animation to be stopped gracefully. You can also include an optional text parameter to customize the loading text.
def custom_animation(stop_event, text="Loading"):
# Animation logic goes here
- Implement the Animation Logic: Inside your function, implement the logic for your animation using loops to update the console output.
Example of a custom bouncing ball animation:
import sys
import time
def custom_bouncing_ball(stop_event, text="Loading"):
ball = ['.', 'o', 'O', 'o', '.']
while not stop_event.is_set():
for frame in ball:
sys.stdout.write(f'\r{text} {frame}')
sys.stdout.flush()
time.sleep(0.3) # Adjust the speed of the animation
- Using the Custom Animation: To use your custom animation with the enimation loading mechanism, create an instance of CustomLoading, passing your custom animation function as the custom argument.
from enimation.loading import CustomLoading
import time
def main():
loader = CustomLoading(custom=custom_bouncing_ball)
loader.start() # Start the loading animation
time.sleep(5) # Simulate a long-running task
loader.stop() # Stop the loading animation
print("\nTask complete!") # Task completion message
if __name__ == "__main__":
main()
Required Components for Custom Animation
To ensure your custom animation works seamlessly with the enimation loading system, include the following:
stop_event
Parameter: Use this parameter in your function to check whether the loading should continue.
Console Output: Use sys.stdout.write()
and sys.stdout.flush() to update the console output without adding new lines.
Animation Logic: Implement the logic that defines how the animation behaves (e.g., changing frames, timing, and user-defined text).
Optional text
Parameter: This parameter allows users to customize the loading message displayed alongside the animation.
Example of a Complete Custom Animation Function
Here’s a complete example:
import sys
import time
from enimation.loading import CustomLoading
def custom_wave_animation(stop_event, text="Loading"):
wave = ['~', '~~', '~~~', '~~~~', '~~~', '~~', '~']
while not stop_event.is_set():
for frame in wave:
sys.stdout.write(f'\r{text} {frame}')
sys.stdout.flush()
time.sleep(0.2) # Adjust speed as needed
def main():
loader = CustomLoading(custom=custom_wave_animation)
loader.start()
time.sleep(5) # Simulate a long-running task
loader.stop()
print("\nTask complete!")
if __name__ == "__main__":
main()
Contributing
If you'd like to contribute to enimation, please fork the repository and submit a pull request. We welcome contributions of all kinds, including bug fixes, documentation improvements, and new features.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contact
For any inquiries or suggestions, feel free to reach out to:
hasan: hasanfq818@gmail.com
GitHub: here
enimation
An animation function for python to higly customize you code with bueatyfull animation
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file enimation-0.1.5.tar.gz
.
File metadata
- Download URL: enimation-0.1.5.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd89198a223260ef81b60d0ecc34ddbb48a7a29fba3ca7d6d15ce1bcd9cc145b |
|
MD5 | 92413cebe12a511fcf4cd7f5cbc38d36 |
|
BLAKE2b-256 | 1f25e764428f1c1b00bbc25dd9a60ad1497b4489ad972291049dd85f529850bd |
File details
Details for the file enimation-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: enimation-0.1.5-py3-none-any.whl
- Upload date:
- Size: 17.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb58c03a227b17b637e70fe927f125d1ff37f26b0f58d9188e049557ae529c3c |
|
MD5 | 686ec843dd041361a443e25b43f43b64 |
|
BLAKE2b-256 | 77eda0a5fbd86043d38d357d8b9fa9738d63dc81288f5c0eb849c9d8fb6018c7 |