18
18
# indicator-stickynotes. If not, see <http://www.gnu.org/licenses/>.
20
20
from stickynotes.backend import Note, NoteSet
21
from stickynotes.gui import *
22
import stickynotes.info
23
from stickynotes.info import MO_DIR, LOCALE_DOMAIN
21
from stickynotes.gui import StickyNote
25
22
from gi.repository import Gtk, Gdk
26
23
from gi.repository import AppIndicator3 as appindicator
31
from locale import gettext as _
32
from functools import wraps
33
from shutil import copyfile, SameFileError
36
"""Wrapper for functions that require a save after execution"""
38
def _wrapper(self, *args, **kwargs):
39
ret = f(self, *args, **kwargs)
44
25
class IndicatorStickyNotes:
45
def __init__(self, args = None):
47
# use development data file if requested
48
isdev = args and args.d
49
self.data_file = stickynotes.info.DEBUG_SETTINGS_FILE if isdev \
50
else stickynotes.info.SETTINGS_FILE
51
27
# Initialize NoteSet
52
self.nset = NoteSet(StickyNote, self.data_file, self)
55
except FileNotFoundError:
56
self.nset.load_fresh()
57
except Exception as e:
58
err = _("Error reading data file. Do you want to "
59
"backup the current data?")
60
winError = Gtk.MessageDialog(None, None, Gtk.MessageType.ERROR,
61
Gtk.ButtonsType.NONE, err)
62
winError.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,
63
_("Backup"), Gtk.ResponseType.ACCEPT)
66
if resp == Gtk.ResponseType.ACCEPT:
67
self.backup_datafile()
69
self.nset.load_fresh()
71
# If all notes were visible previously, show them now
72
if self.nset.properties.get("all_visible", True):
28
self.nset = NoteSet(StickyNote)
74
31
# Create App Indicator
75
32
self.ind = appindicator.Indicator.new(
76
33
"Sticky Notes", "indicator-stickynotes",
77
34
appindicator.IndicatorCategory.APPLICATION_STATUS)
78
# Delete/modify the following file when distributing as a package
79
self.ind.set_icon_theme_path(os.path.abspath(os.path.join(
80
os.path.dirname(__file__), 'Icons')))
81
self.ind.set_icon("indicator-stickynotes")
82
35
self.ind.set_status(appindicator.IndicatorStatus.ACTIVE)
83
self.ind.set_title(_("Sticky Notes"))
36
self.ind.set_title("Sticky Notes")
37
#self.ind.set_attention_icon("pynagram")
85
39
self.menu = Gtk.Menu()
86
self.mNewNote = Gtk.MenuItem(_("New Note"))
40
self.mNewNote = Gtk.MenuItem("New Note")
87
41
self.menu.append(self.mNewNote)
88
42
self.mNewNote.connect("activate", self.new_note, None)
89
43
self.mNewNote.show()
120
74
self.menu.append(s)
123
self.mAbout = Gtk.MenuItem(_("About"))
124
self.menu.append(self.mAbout)
125
self.mAbout.connect("activate", self.show_about, None)
128
self.mSettings = Gtk.MenuItem(_("Settings"))
129
self.menu.append(self.mSettings)
130
self.mSettings.connect("activate", self.show_settings, None)
131
self.mSettings.show()
133
s = Gtk.SeparatorMenuItem.new()
137
self.mQuit = Gtk.MenuItem(_("Quit"))
77
self.mQuit = Gtk.MenuItem("Quit")
138
78
self.menu.append(self.mQuit)
139
79
self.mQuit.connect("activate", Gtk.main_quit, None)
141
81
# Connect Indicator to menu
142
82
self.ind.set_menu(self.menu)
144
# Define secondary action (middle click)
145
self.connect_secondary_activate()
147
def backup_datafile(self):
148
backupfile = show_export_file_chooser()
151
copyfile(os.path.expanduser(self.data_file), backupfile)
152
except SameFileError:
153
err = _("Please choose a different "
154
"destination for the backup file.")
155
winError = Gtk.MessageDialog(None, None,
156
Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, err)
159
self.backup_datafile()
161
84
def new_note(self, *args):
164
87
def showall(self, *args):
165
88
self.nset.showall(*args)
166
self.connect_secondary_activate()
168
90
def hideall(self, *args):
169
91
self.nset.hideall()
170
self.connect_secondary_activate()
172
def connect_secondary_activate(self):
173
"""Define action of secondary action (middle click) depending
174
on visibility state of notes."""
175
if self.nset.properties["all_visible"] == True:
176
self.ind.set_secondary_activate_target(self.mHideAll)
178
self.ind.set_secondary_activate_target(self.mShowAll)
182
93
def lockall(self, *args):
183
94
for note in self.nset.notes:
184
note.set_locked_state(True)
95
note.gui.set_locked_state(True)
187
97
def unlockall(self, *args):
188
98
for note in self.nset.notes:
189
note.set_locked_state(False)
191
def show_about(self, *args):
194
def show_settings(self, *args):
195
wSettings = SettingsDialog(self.nset)
99
note.gui.set_locked_state(False)
203
locale.setlocale(locale.LC_ALL, '')
205
locale.setlocale(locale.LC_ALL, 'C')
206
# If we're running from /usr, then .mo files are not in MO_DIR.
207
if os.path.abspath(__file__)[:4] == '/usr':
208
# Fallback to default
211
locale_dir = os.path.join(os.path.dirname(__file__), MO_DIR)
212
locale.bindtextdomain(LOCALE_DOMAIN, locale_dir)
213
locale.textdomain(LOCALE_DOMAIN)
215
parser = argparse.ArgumentParser(description=_("Sticky Notes"))
216
parser.add_argument("-d", action='store_true', help="use the development"
218
args = parser.parse_args()
220
indicator = IndicatorStickyNotes(args)
221
# Load global css for the first time.
106
indicator = IndicatorStickyNotes()