Metadata-Version: 2.4
Name: loom-animation
Version: 1.0
Summary: A powerful, framework - agnostic animation engine for Python and Qt.
Author-email: chips047 <chips.furs@gmail.com>
Project-URL: Homepage, https://github.com/chips047/Loom-Engine
Project-URL: Bug Tracker, https://github.com/chips047/Loom-Engine/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: User Interfaces
Classifier: Topic :: Multimedia :: Graphics
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: loguru>=0.7.0

# Loom Engine

**A powerful, flexible, and framework - agnostic animation engine for Python.**

This package allows you to animate any numeric values, vectors (Point, Size, Rect), colors, and custom data structures.

**Works with:**
- PyQt5
- PyQt6
- PySide2
- PySide6
- Pure Python

### Features

- Versatile - animate numbers, geometry, colors, or your own data structures.\
- Independent - works seamlessly in both console scripts and complex graphical user interfaces.\
- Smooth - built - in support for smoothing and soft limits.\
- Multiple Modes - timeline animations, step animations, curve keyframes, and dynamic targeting.\
- Rich Easing Library - over 30 built - in easing functions (Bounce, Elastic, Expo, etc.).

### Installation

`pip install loom-engine`

**Quick Start (Pure Python)**

```import time
from loom_engine import AnimationEngine, Easing

# 1. Create the engine explicitly (without UI binding)
engine = AnimationEngine(backend_name = "pure", frames_per_second = 60)
engine.start()

# 2. Tell the engine it is actively being used (prevents it from pausing)
engine.acquire()

# 3. Bind a property
# owner - any object, name - unique property identifier

class VeryCoolObject:
    def __init__(self):
        self.opacity = 0.0

my_object = VeryCoolObject()
alpha_anim = engine.bind(
    owner      = my_object,
    name       = "opacity",
    base_value = 0.0,
    on_change  = lambda val: print(f"Opacity changed: {val:.2f}")
)

# 4. Start an animation to a target value
alpha_anim.set_target(
    value           = 1.0,
    duration_ms     = 1000,
    easing_function = Easing.ease_out_cubic
)

time.sleep(1.2)

engine.release()
engine.clear()
```

Qt Integration

When working with Qt, the engine will automatically find the active Qt backend and utilize QTimer and Qt data structures (QPoint, QRect, QColor).

```from PyQt6.QtWidgets import QWidget, QApplication
from loom_engine import AnimationEngine, Easing

app = QApplication([])

# The engine automatically detects the Qt backend
engine = AnimationEngine()
engine.start()

class AnimatedWidget(QWidget):
    def __init__(self):
        super().__init__()
        
        self.base_geometry = self.geometry()
        
        # Register the widget as an active animation user
        engine.acquire()
        
        # Bind the widget's geometry to the animation track
        self.geometry_anim = engine.bind(
            owner      = self,
            name       = "geometry",
            base_value = self.base_geometry,
            on_change  = self.setGeometry
        )

    def showEvent(self, a0):
        # Update the base geometry on show
        self.base_geometry = self.geometry()
    
    def enterEvent(self, event):
        # Animate on mouse hover using the BASE geometry, not the current one
        target_rect = self.base_geometry.adjusted(-10, -10, 10, 10)
        self.geometry_anim.set_target(target_rect, 300, Easing.ease_out_back)
        
    def leaveEvent(self, event):
        # Return exactly to the original BASE state
        self.geometry_anim.set_target(self.base_geometry, 300, Easing.ease_in_out_cubic)

    def closeEvent(self, event):
        # Memory cleanup on close
        engine.unbind_owner(self)
        engine.release()

window = AnimatedWidget()
window.show()
app.exec()
```

### Optimal Usage Strategies

1. Resource Management (Acquire / Release)

The engine consumes CPU resources by continuously calling updates at the specified framerate. Always use the engine.acquire() and engine.release() methods.

If you have a widget using animations, call acquire() upon its creation and release() upon its destruction.

If the active user counter drops to zero, the engine automatically stops its internal timers to save battery and CPU.

2. Event Binding (on_change)

Utilize the on_change parameter in the engine.bind method. This eliminates the need to write heavy polling loops. The callback function will only be triggered if the value actually changes.

3. Memory Cleanup (Preventing Leaks)

Use engine.unbind_owner(owner) when an object is no longer needed. While the engine uses a WeakKeyDictionary to help avoid memory leaks, explicit cleanup is always more reliable, especially when working with complex UI frameworks like Qt.

4. Mix Modes

You can layer multiple animations on top of each other.

REPLACE (Default) - the new animation entirely replaces the previous state.

ADD - values are added together. Excellent for "shake" effects (like camera shake), where the base value might change smoothly while a rapid vibration is applied on top.

MULTIPLY - ideal for scaling effects, color filtering, or opacity overlays.
