[go: up one dir, main page]

Menu

[r11]: / note / trunk / spop_note.py  Maximize  Restore  History

Download this file

228 lines (167 with data), 6.0 kB

  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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/python
#-*- coding: UTF-8 -*-
#Import the modules#
import Tkinter
from Tkinter import *
import tkFileDialog
import tkMessageBox
import time
import sys
import codecs
from PIL import Image, ImageTk
import commands
#import the version number out of the file VERSION
version = open("text/version", "r")
version = version.read()
#import about text
abouttext = open("text/abouttext", "r")
abouttext = abouttext.read()
#import Developer list
devellist = open("text/developers", "r")
devellist = devellist.read()
#filenames and fileformats in sPOP Editor
filename = open("tmp/_filename", "r")
filename = filename.read()
_filetypes = [("All","*"),("Text","*.txt"),("Python","*.py")]
#Commands
def new_file(whatever=None):
text.delete("1.0","end")
filename = open("tmp/_filename", "w")
filename.write("")
filename.close()
def save_as_file(whatever=None):
filename = tkFileDialog.asksaveasfilename(filetypes=_filetypes)
filename1 = open("tmp/_filename", "w")
filename1 = filename1.write(filename)
save = codecs.open(filename, "w", "utf-8")
save.write(text.get("1.0","end"))
save.close()
def save_file(whatever=None):
filename = open("tmp/_filename", "r")
filename = filename.read()
save = codecs.open(filename, "w", "utf-8")
save.write(text.get("1.0","end"))
save.close()
def open_file(whatever=None,filename=None):
if not filename:
_filename = tkFileDialog.askopenfilename(filetypes=_filetypes)
else:
_filename = filename
if not (_filename == ""):
try:
f = open(_filename, "r")
f2 = f.read()
except:
f = open(_filename, "w")
f.write("\n")
f.close()
f = open(_filename, "r")
f2 = f.read()
filename1 = open("tmp/_filename", "w")
filename1 = filename1.write(_filename)
text.delete("1.0", "end")
text.insert("1.0", f2)
text.delete("end-1c","end")
f.close()
def quit_editor(whatever=None):
if tkMessageBox.askokcancel("Quit", "Do you really wish to quit?"):
filename = open("tmp/_filename", "w")
filename.write("")
filename.close()
root.destroy()
#Commands Copy,Paste,Select All
def copy_text(whatever=None):
commands.copy_text(text)
def paste_text(whatever=None):
commands.paste_text(text)
def cut_text(whatever=None):
commands.cut_text(text)
def select_all_text(whatever=None):
commands.select_all(text)
#About Window
def about_window(whatever=None):
about_window = Tk()
about_window.title("About sPOP note")
about_label = Label(about_window, text=abouttext)
about_label.pack()
about_devel_label = Label(about_window, text=devellist)
about_devel_label.pack()
about_window_close = Button(about_window, text="Close", command=about_window.destroy)
about_window_close.pack()
about_window.mainloop()
#sPOP Editor Window
root = Tkinter.Tk()
root.title("sPOP Editor "+ version)
root.protocol("WM_DELETE_WINDOW", quit_editor)
menu = Menu(root)
root.config(menu=menu)
#File Menu
filemenu = Menu(menu)
menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="New", command=new_file)
filemenu.add_command(label="Open...", command=open_file)
filemenu.add_command(label="Save", command=save_file)
filemenu.add_command(label="Save As...", command=save_as_file)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=quit_editor)
# Edit Menu
editmenu = Menu(menu)
menu.add_cascade(label="Edit", menu=editmenu)
editmenu.add_command(label="Cut", command=cut_text)
editmenu.add_command(label="Copy", command=copy_text)
editmenu.add_command(label="Paste", command=paste_text)
#Help Menu
helpmenu = Menu(menu)
menu.add_cascade(label="Help", menu=helpmenu)
helpmenu.add_command(label="About...", command=about_window)
#Icons Toolbar
iconframe = Frame(root)
iconframe.pack()
#Load Button Images
image_new_file_load = "icons/new_file.png"
image_new_file = ImageTk.PhotoImage(Image.open(image_new_file_load))
image_save_file_load = "icons/save_file.png"
image_save_file = ImageTk.PhotoImage(Image.open(image_save_file_load))
image_open_file_load = "icons/open_file.png"
image_open_file = ImageTk.PhotoImage(Image.open(image_open_file_load))
image_about_load = "icons/about.png"
image_about = ImageTk.PhotoImage(Image.open(image_about_load))
image_quit_load = "icons/quit.png"
image_quit = ImageTk.PhotoImage(Image.open(image_quit_load))
#Icons Buttons
new_file_image_button = Button(iconframe, image=image_new_file, command=new_file)
new_file_image_button.pack(side=LEFT)
open_file_image_button = Button(iconframe, image=image_open_file, command=open_file)
open_file_image_button.pack(side=LEFT)
save_file_image_button = Button(iconframe, image=image_save_file, command=save_file)
save_file_image_button.pack(side=LEFT)
about_image_button = Button(iconframe, image=image_about, command=about_window)
about_image_button.pack(side=LEFT)
quit_image_button = Button(iconframe, image=image_quit, command=quit_editor)
quit_image_button.pack(side=LEFT)
#Textfield
textframe = Frame(root)
textframe.pack(expand=1)
#Scrollbar
scrollbar = Scrollbar(textframe, relief="raised")
scrollbar.pack(side=RIGHT, fill=Y, expand=1)
#Text Field
text = Tkinter.Text(textframe, bg="white", yscrollcommand=scrollbar.set, relief="raised")
text.pack(expand=1, fill="both")
scrollbar.config(command=text.yview)
#Hotkeys
text.bind("<Control-O>",open_file)
text.bind("<Control-o>",open_file)
text.bind("<Control-S>",save_file)
text.bind("<Control-s>",save_file)
text.bind("<Control-N>",new_file)
text.bind("<Control-n>",new_file)
text.bind("<Control-X>",cut_text)
text.bind("<Control-x>",cut_text)
text.bind("<Control-C>",copy_text)
text.bind("<Control-c>",copy_text)
text.bind("<Control-V>",paste_text)
text.bind("<Control-v>",paste_text)
text.bind("<Control-A>",select_all_text)
text.bind("<Control-a>",select_all_text)
root.mainloop()