~umang/indicator-stickynotes/trunk

1 by Umang Varma
Initial commit. Somewhat working sticky notes.
1
#!/usr/bin/python3
16 by Umang Varma
Licensed under GPLv3
2
# 
3
# Copyright © 2012 Umang Varma <umang.me@gmail.com>
4
# 
5
# This file is part of indicator-stickynotes.
6
# 
7
# indicator-stickynotes is free software: you can redistribute it and/or
8
# modify it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or (at your
10
# option) any later version.
11
# 
12
# indicator-stickynotes is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15
# more details.
16
# 
17
# You should have received a copy of the GNU General Public License along with
18
# indicator-stickynotes.  If not, see <http://www.gnu.org/licenses/>.
1 by Umang Varma
Initial commit. Somewhat working sticky notes.
19
20
from backend import Note, NoteSet
21
from gui import StickyNote
22
from gi.repository import Gtk, Gdk
2 by Umang Varma
Implemented indicator.
23
from gi.repository import AppIndicator3 as appindicator
24
25
class IndicatorStickyNotes:
26
    def __init__(self):
27
        # Initialize NoteSet
28
        self.nset = NoteSet(StickyNote)
29
        self.nset.open()
30
        self.nset.showall()
31
        # Create App Indicator
32
        self.ind = appindicator.Indicator.new(
33
                "Sticky Notes", "accessories-text-editor",
34
                appindicator.IndicatorCategory.APPLICATION_STATUS)
35
        self.ind.set_status(appindicator.IndicatorStatus.ACTIVE)
36
        self.ind.set_title("Sticky Notes")
37
        #self.ind.set_attention_icon("pynagram")
38
        # Create Menu
39
        self.menu = Gtk.Menu()
40
        self.mNewNote = Gtk.MenuItem("New Note")
41
        self.menu.append(self.mNewNote)
42
        self.mNewNote.connect("activate", self.new_note, None)
43
        self.mNewNote.show()
44
45
        s = Gtk.SeparatorMenuItem.new()
46
        self.menu.append(s)
47
        s.show()
48
49
        self.mShowAll = Gtk.MenuItem("Show All")
50
        self.menu.append(self.mShowAll)
51
        self.mShowAll.connect("activate", self.showall, None)
52
        self.mShowAll.show()
53
54
        self.mHideAll = Gtk.MenuItem("Hide All")
55
        self.menu.append(self.mHideAll)
56
        self.mHideAll.connect("activate", self.hideall, None)
57
        self.mHideAll.show()
58
59
        s = Gtk.SeparatorMenuItem.new()
60
        self.menu.append(s)
61
        s.show()
62
13 by Umang Varma
Added Lock all/Unlock all menu item
63
        self.mLockAll = Gtk.MenuItem("Lock All")
64
        self.menu.append(self.mLockAll)
65
        self.mLockAll.connect("activate", self.lockall, None)
66
        self.mLockAll.show()
67
68
        self.mUnlockAll = Gtk.MenuItem("Unlock All")
69
        self.menu.append(self.mUnlockAll)
70
        self.mUnlockAll.connect("activate", self.unlockall, None)
71
        self.mUnlockAll.show()
72
73
        s = Gtk.SeparatorMenuItem.new()
74
        self.menu.append(s)
75
        s.show()
76
2 by Umang Varma
Implemented indicator.
77
        self.mQuit = Gtk.MenuItem("Quit")
78
        self.menu.append(self.mQuit)
79
        self.mQuit.connect("activate", Gtk.main_quit, None)
80
        self.mQuit.show()
81
        # Connect Indicator to menu
82
        self.ind.set_menu(self.menu)
83
84
    def new_note(self, *args):
85
        self.nset.new()
86
87
    def showall(self, *args):
88
        self.nset.showall(*args)
89
90
    def hideall(self, *args):
91
        self.nset.hideall()
92
13 by Umang Varma
Added Lock all/Unlock all menu item
93
    def lockall(self, *args):
94
        for note in self.nset.notes:
95
            note.gui.set_locked_state(True)
96
        
97
    def unlockall(self, *args):
98
        for note in self.nset.notes:
99
            note.gui.set_locked_state(False)
100
2 by Umang Varma
Implemented indicator.
101
    def save(self):
102
        self.nset.save()
103
1 by Umang Varma
Initial commit. Somewhat working sticky notes.
104
105
def main():
2 by Umang Varma
Implemented indicator.
106
    indicator = IndicatorStickyNotes()
1 by Umang Varma
Initial commit. Somewhat working sticky notes.
107
    Gtk.main()
2 by Umang Varma
Implemented indicator.
108
    indicator.save()
1 by Umang Varma
Initial commit. Somewhat working sticky notes.
109
110
if __name__ == "__main__":
111
    main()