Skip to content

Instantly share code, notes, and snippets.

@Sean-Bradley
Last active April 12, 2019 12:35
Show Gist options
  • Save Sean-Bradley/17e23916488d049e523bedcfd86616e4 to your computer and use it in GitHub Desktop.
Save Sean-Bradley/17e23916488d049e523bedcfd86616e4 to your computer and use it in GitHub Desktop.
def execute(self, command_name, *args):
"""Execute a pre defined command and log in history"""
if command_name in self._commands.keys():
self._history_position += 1
self._commands[command_name].execute(args)
if len(self._history) == self._history_position:
# This is a new event in hisory
self._history.append((time.time(), command_name, args))
else:
# This occurs if there was one of more UNDOs and then a new
# execute command happened. In case of UNDO, the history_position
# changes, and executing new commands purges any history after
# the current position"""
self._history = self._history[:self._history_position+1]
self._history[self._history_position] = {
time.time(): [command_name, args]
}
else:
print(f"Command [{command_name}] not recognised")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment