1
from datetime import datetime
4
from os.path import expanduser
6
SETTINGS_FILE = "stickynotesrc"
9
def __init__(self, content=None, gui_class=None, noteset=None):
10
content = content or {}
11
self.uuid = content.get('uuid')
12
self.body = content.get('body','')
13
self.properties = content.get("properties", {})
14
last_modified = content.get('last_modified')
16
self.last_modified = datetime.strptime(last_modified,
19
self.last_modified = datetime.now()
20
self.gui_class = gui_class
22
self.noteset = noteset
25
self.gui.update_note()
27
self.uuid = str(uuid.uuid4())
28
return {"uuid":self.uuid, "body":self.body,
29
"last_modified":self.last_modified.strftime(
30
"%Y-%m-%dT%H:%M:%S"), "properties":self.gui.properties()}
32
def update(self,body=None):
35
self.last_modified = datetime.now()
38
self.noteset.notes.remove(self)
44
self.gui = self.gui_class(note=self)
52
def __init__(self, gui_class):
54
self.gui_class = gui_class
56
def _loads_updater(self, dnoteset):
57
"""Parses old versions of the Notes structure and updates them"""
60
def loads(self, snoteset):
61
"""Loads notes into their respective objects"""
62
notes = self._loads_updater(json.loads(snoteset))
63
self.notes = [Note(note, gui_class=self.gui_class, noteset=self)
64
for note in notes.get("notes",[])]
67
return json.dumps({"notes":[x.extract() for x in self.notes]})
69
def save(self, path=''):
70
with open(path or expanduser("~/.{0}".format(SETTINGS_FILE)),
71
mode='w', encoding='utf-8') as fsock:
72
fsock.write(self.dumps())
74
def open(self, path=''):
75
with open(path or expanduser("~/.{0}".format(SETTINGS_FILE)),
76
encoding='utf-8') as fsock:
77
self.loads(fsock.read())
80
"""Creates a new note and adds it to the note set"""
81
note = Note(gui_class=self.gui_class, noteset=self)
82
self.notes.append(note)
87
for note in self.notes:
91
for note in self.notes:
95
def __init__(self, *args, **kwargs):
102
def update_note(self):
104
def properties(self):