1
# Copyright © 2012 Umang Varma <umang.me@gmail.com>
3
# This file is part of indicator-stickynotes.
5
# indicator-stickynotes is free software: you can redistribute it and/or
6
# modify it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation, either version 3 of the License, or (at your
8
# option) any later version.
10
# indicator-stickynotes is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15
# You should have received a copy of the GNU General Public License along with
16
# indicator-stickynotes. If not, see <http://www.gnu.org/licenses/>.
18
from datetime import datetime
21
from os.path import expanduser
22
from stickynotes.info import SETTINGS_FILE
25
def __init__(self, content=None, gui_class=None, noteset=None):
26
content = content or {}
27
self.uuid = content.get('uuid')
28
self.body = content.get('body','')
29
self.properties = content.get("properties", {})
30
last_modified = content.get('last_modified')
32
self.last_modified = datetime.strptime(last_modified,
35
self.last_modified = datetime.now()
36
self.gui_class = gui_class
38
self.noteset = noteset
41
self.gui.update_note()
43
self.uuid = str(uuid.uuid4())
44
self.properties = self.gui.properties()
45
return {"uuid":self.uuid, "body":self.body,
46
"last_modified":self.last_modified.strftime(
47
"%Y-%m-%dT%H:%M:%S"), "properties":self.properties}
49
def update(self,body=None):
52
self.last_modified = datetime.now()
55
self.noteset.notes.remove(self)
59
def show(self, *args):
61
self.gui = self.gui_class(note=self)
69
def __init__(self, gui_class):
71
self.gui_class = gui_class
73
def _loads_updater(self, dnoteset):
74
"""Parses old versions of the Notes structure and updates them"""
77
def loads(self, snoteset):
78
"""Loads notes into their respective objects"""
79
notes = self._loads_updater(json.loads(snoteset))
80
self.notes = [Note(note, gui_class=self.gui_class, noteset=self)
81
for note in notes.get("notes",[])]
84
return json.dumps({"notes":[x.extract() for x in self.notes]})
86
def save(self, path=''):
88
with open(path or expanduser(SETTINGS_FILE),
89
mode='w', encoding='utf-8') as fsock:
92
def open(self, path=''):
94
with open(path or expanduser(SETTINGS_FILE),
95
encoding='utf-8') as fsock:
96
self.loads(fsock.read())
102
"""Creates a new note and adds it to the note set"""
103
note = Note(gui_class=self.gui_class, noteset=self)
104
self.notes.append(note)
108
def showall(self, *args):
109
for note in self.notes:
112
def hideall(self, *args):
114
for note in self.notes:
118
def __init__(self, *args, **kwargs):
125
def update_note(self):
127
def properties(self):