Skip to content

AndrewSpangler/py_simple_history

Repository files navigation

py_simple_history 0.0.1

A super basic python History Tracking object



About^

In this instance "History" means the state of an object at any given time. This module aims to provide a simple interface for tracking and moving through histories.

Installation^

Available on pip - pip install py_simple_history

Usage^

history_mixin^

Abstract mixin to add simple history-tracking to an object.

class history_mixin(object):
	def __init__(self, start_data):
		...
	def add_history(self, data):
		"""Add a history point. Clears any undone data history points."""
	def clear_history(self, data=None):
		"""Clears history. Sets a new history point, if no data specified uses the current data point."""
	def redo(self):
		"""Redoes history one step if possible."""
	def undo(self):
		"""Undoes history one step if possible."""

Example^

from py_simple_history import history_mixin

class demo_object(history_mixin):
    def __init__(self, initial_data):
        history_mixin.__init__(self, initial_data)
        self.load(self.data:=initial_data)
        ...

    def on_update(self, new_data):
        self.add_history(new_data)
        self.load(data)

    def load(self, data):
        self.data = data

    def step_back(self):
        self.load(self.undo())

    def step_forward(self):
        self.load(self.redo())

About

A super simple history tracking class / mixin.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages