~umang/indicator-stickynotes/trunk

« back to all changes in this revision

Viewing changes to sticky.py

  • Committer: Umang Varma
  • Date: 2012-06-24 20:43:03 UTC
  • Revision ID: git-v1:7154d9e47e06f4ca05d7f5a2acdd48d6d6efb3a7
Added .desktop and setup.py files.

In addition stick.py was moved to indicator-stickynotes.py so that it looks more
like its final installed name.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python3
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/>.
19
 
 
20
 
from stickynotes.backend import Note, NoteSet
21
 
from stickynotes.gui import StickyNote
22
 
from gi.repository import Gtk, Gdk
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", "indicator-stickynotes",
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
 
 
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
 
 
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
 
 
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
 
 
101
 
    def save(self):
102
 
        self.nset.save()
103
 
 
104
 
 
105
 
def main():
106
 
    indicator = IndicatorStickyNotes()
107
 
    Gtk.main()
108
 
    indicator.save()
109
 
 
110
 
if __name__ == "__main__":
111
 
    main()