File: rhinote.py

package info (click to toggle)
rhinote 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 188 kB
  • sloc: python: 181; makefile: 39
file content (140 lines) | stat: -rw-r--r-- 4,915 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python
# Filename : rhinote.py

# Rhinote version 0.7.4  A simple "sticky notes" application; Linux version.

# Copyright 2006, 2010 by Marv Boyes - greyspace@tuxfamily.org
# http://rhinote.tuxfamily.org
# Please see the file COPYING for license details.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St., Fifth Floor, Boston, MA  02110-1301 USA

from Tkinter import *
import tkFileDialog, tkMessageBox
import os
from os import system

# the root window:
def Rhinote():
    r = Tk()
    r.option_add('*font', '{Helvetica} 11')
    t = TextWidget(r, bg = '#f9f3a9', wrap = 'word', undo = True)
    t.focus_set()
    t.pack(fill = 'both', expand = 1)
    r.geometry('220x235')
    r.title('Rhinote')
    r.mainloop()

# the text widget, and all of its functions:
class TextWidget(Text):

    def save_file(self, whatever = None):
        if (self.filename == ''):
            self.save_file_as()
            self.master.title('Rhinote %s' % self.filename)
        else:
            f = open(self.filename, 'w')
            f.write(self.get('1.0', 'end'))
            f.close()
            self.master.title('Rhinote %s' % self.filename)
            # Comment out the following line if you don't want a 
            # pop-up message every time you save a file:
            tkMessageBox.showinfo('FYI', 'File Saved.')

    def save_file_as(self, whatever = None):
        self.filename = tkFileDialog.asksaveasfilename(filetypes = self._filetypes)
        f = open(self.filename, 'w')
        f.write(self.get('1.0', 'end'))
        f.close()
        # comment out the following line if you don't want a
        # pop-up message every time you save a file:
        tkMessageBox.showinfo('FYI', 'File Saved')

    def open_file(self, whatever = None, filename = None):
        if not filename:
            self.filename = tkFileDialog.askopenfilename(filetypes = self._filetypes)
            self.master.title('Rhinote %s' % self.filename)
        else:
            self.filename = filename
            self.master.title('Rhinote %s' % self.filename)
        if not (self.filename == ''):
            f = open(self.filename, 'r')
            f2 = f.read()
            self.delete('1.0', 'end')
            self.insert('1.0', f2)
            f.close()
            self.master.title('Rhinote %s)' % self.filename)

    def new_window(self, event):
        Rhinote()

    def printfile(self, whatever = None):
        f = open(self.printfilename, 'w')
        f.write(self.get('1.0', 'end'))
        f.close
        # 'enscript' formats the text; lpr sends it to the default printer;
        # enscript's -B option suppresses page headers.
        system('enscript -B --word-wrap $HOME/.Rhinoteprintfile > lpr &')

    def help(self, whatever = None):
        tkMessageBox.showinfo('Rhinote Help', message = '''
Editing Commands
    Ctrl-x : Cut selected text
    Ctrl-c : Copy selected text
    Ctrl-v : Paste cut/copied text
    Ctrl-Z : Undo
    Ctrl-Shift-z : Redo

File Commands
    Ctrl-o : Open file
    Ctrl-s : Save current note
    Ctrl-a : Save current note as <filename>
    Ctrl-p : Print current note
    Ctrl-n : Open new Rhinote

General
    Ctrl-h : Display this help window

Rhinote version 0.7.4
Free Software distributed under the GNU General Public License
http://rhinote.tuxfamily.org
''')

    def __init__(self, master, **kw):
        Text.__init__(self, master, **kw)
        self.bind('<Control-n>', self.new_window)
        self.bind('<Control-N>', self.new_window)
        self.bind('<Control-o>', self.open_file)
        self.bind('<Control-O>', self.open_file)
        self.bind('<Control-s>', self.save_file)
        self.bind('<Control-S>', self.save_file)
        self.bind('<Control-a>', self.save_file_as)
        self.bind('<Control-A>', self.save_file_as)
        self.bind('<Control-p>', self.printfile)
        self.bind('<Control-P>', self.printfile)
        self.bind('<Control-h>', self.help)
        self.bind('<Control-H>', self.help)
        self.master = master
        self.filename = ''
        self.printfilename = os.environ['HOME']+'/.Rhinoteprintfile'
        self._filetypes = [
        ('Text/ASCII', '*.txt'),
        ('Rhinote files', '*.rhi'),
            ('All files', '*'),
            ]

# make it so:
if __name__ == '__main__':
    Rhinote()