Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Append a deepcopy solution in Clear category for Text Editor by rodka81
from copy import deepcopy
class Text:
def __init__(self, text="", font=None):
self._text = text
self._font = font
def write(self, text):
self._text += text
def set_font(self, font):
self._font = font
@property
def text(self):
return self._text
@property
def font(self):
return self._font
def restore(self, other):
self._text = other._text
self._font = other._font
def show(self):
if self._font:
return f"[{self.font}]{self.text}[{self.font}]"
return self.text
def __repr__(self):
return self.show()
class SavedText:
def __init__(self):
self._states = []
def save_text(self, text):
self._states.append(deepcopy(text))
def get_version(self, n):
return self._states[n]
April 4, 2019
Comments: