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
23
SETTINGS_FILE = "stickynotesrc"
26
def __init__(self, content=None, gui_class=None, noteset=None):
27
content = content or {}
28
self.uuid = content.get('uuid')
29
self.body = content.get('body','')
30
self.properties = content.get("properties", {})
31
last_modified = content.get('last_modified')
33
self.last_modified = datetime.strptime(last_modified,
36
self.last_modified = datetime.now()
37
self.gui_class = gui_class
39
self.noteset = noteset
42
self.gui.update_note()
44
self.uuid = str(uuid.uuid4())
45
self.properties = self.gui.properties()
46
return {"uuid":self.uuid, "body":self.body,
47
"last_modified":self.last_modified.strftime(
48
"%Y-%m-%dT%H:%M:%S"), "properties":self.properties}
50
def update(self,body=None):
53
self.last_modified = datetime.now()
56
self.noteset.notes.remove(self)
60
def show(self, *args):
62
self.gui = self.gui_class(note=self)
70
def __init__(self, gui_class):
72
self.gui_class = gui_class
74
def _loads_updater(self, dnoteset):
75
"""Parses old versions of the Notes structure and updates them"""
78
def loads(self, snoteset):
79
"""Loads notes into their respective objects"""
80
notes = self._loads_updater(json.loads(snoteset))
81
self.notes = [Note(note, gui_class=self.gui_class, noteset=self)
82
for note in notes.get("notes",[])]
85
return json.dumps({"notes":[x.extract() for x in self.notes]})
87
def save(self, path=''):
89
with open(path or expanduser("~/.{0}".format(SETTINGS_FILE)),
90
mode='w', encoding='utf-8') as fsock:
93
def open(self, path=''):
94
with open(path or expanduser("~/.{0}".format(SETTINGS_FILE)),
95
encoding='utf-8') as fsock:
96
self.loads(fsock.read())
99
"""Creates a new note and adds it to the note set"""
100
note = Note(gui_class=self.gui_class, noteset=self)
101
self.notes.append(note)
105
def showall(self, *args):
106
for note in self.notes:
109
def hideall(self, *args):
111
for note in self.notes:
115
def __init__(self, *args, **kwargs):
122
def update_note(self):
124
def properties(self):