Skip to main content

A super simple history tracking class / mixin.

Project description

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())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

py_simple_history-0.0.1-py2.py3-none-any.whl (15.8 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page