-
Notifications
You must be signed in to change notification settings - Fork 0
/
text_editor.pyw
164 lines (130 loc) · 4.65 KB
/
text_editor.pyw
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
#Joshpad 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 3 of the License, or
#(at your option) any later version.
#This program is distributed in the 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, see <http://www.gnu.org/licenses/>.
import sys
import tkinter
from tkinter import *
import tkinter.messagebox as tkMessageBox
import tkinter.filedialog as tkFileDialog
import tkinter.messagebox as tkMessageBox
import tkinter.colorchooser as tkColorChoose
askcolor=tkColorChoose.askcolor
import datetime
import webbrowser
from tkinter.filedialog import askopenfilename, asksaveasfilename
if len(sys.argv)>1:
file_n=sys.argv[1]
else:file_n=""
def line():
lin = "_" * 60
text.insert(INSERT,lin)
def date():
data = datetime.date.today()
text.insert(INSERT,data)
def normal():
text.config(font = ("Courier New", 10))
def bold():
text.config(font = ("Courier New", 10, "bold"))
def underline():
text.config(font = ("Courier New", 10, "underline"))
def italic():
text.config(font = ("Courier New",10,"italic"))
def font():
(triple,color) = askcolor()
if color:
text.config(foreground=color)
def kill():
root.destroy()
def about():
pass
def opn():
text.delete(1.0 , END)
file = open(askopenfilename() , 'r')
if file != '':
txt = file.read()
text.insert(INSERT,txt)
else:
pass
def save():
filename = asksaveasfilename()
if filename:
alltext = text.get(1.0, END)
open(filename, 'w').write(alltext)
def copy():
text.clipboard_clear()
text.clipboard_append(text.selection_get())
def paste():
try:
teext = text.selection_get(selection='CLIPBOARD')
text.insert(INSERT, teext)
except:
tkMessageBox.showerror("Error","Cannot paste!")
def clear():
sel = text.get(SEL_FIRST, SEL_LAST)
text.delete(SEL_FIRST, SEL_LAST)
def clearall():
text.delete(1.0 , END)
def background():
(triple,color) = askcolor()
if color:
text.config(background=color)
def about():
ab = Toplevel(root)
txt = "Joshpad\nWebsite: https://github.com/thecodingchicken\nLicense: GPL v3"
txt+= "\nA plain text editor in python"
la = Label(ab,text=txt,foreground='blue')
la.pack()
def web():
webbrowser.open('https://github.com/thecodingchicken')
def start():
root = Tk()
root.title("Joshpad")
menu = Menu(root)
filemenu = Menu(root)
root.config(menu = menu)
menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="Open...", command=opn)
filemenu.add_command(label="Save...", command=save)
filemenu.add_separator()
filemenu.add_command(label="Quit", command=kill)
modmenu = Menu(root)
menu.add_cascade(label="Edit",menu = modmenu)
modmenu.add_command(label="Copy", command = copy)
modmenu.add_command(label="Paste", command=paste)
modmenu.add_separator()
modmenu.add_command(label = "Cancel selection", command = clear)
modmenu.add_command(label = "Erase Everything", command = clearall)
insmenu = Menu(root)
menu.add_cascade(label="Insert",menu= insmenu)
insmenu.add_command(label="Date",command=date)
insmenu.add_command(label="Line",command=line)
formatmenu = Menu(menu)
menu.add_cascade(label="Format",menu = formatmenu)
formatmenu.add_cascade(label="Color...", command = font)
formatmenu.add_separator()
formatmenu.add_radiobutton(label='Normal',command=normal)
formatmenu.add_radiobutton(label='Bold',command=bold)
formatmenu.add_radiobutton(label='Underline',command=underline)
formatmenu.add_radiobutton(label='Italic',command=italic)
persomenu = Menu(root)
menu.add_cascade(label="Customize",menu=persomenu)
persomenu.add_command(label="Background...", command=background)
helpmenu = Menu(menu)
menu.add_cascade(label="?", menu=helpmenu)
helpmenu.add_command(label="Info about Joshpad", command=about)
helpmenu.add_command(label="Website", command = web)
text = Text(root, height=41, width= 90, font = ("Courier New", 10))
scroll = Scrollbar(root, command=text.yview)
scroll.config(command=text.yview)
text.config(yscrollcommand=scroll.set)
scroll.pack(side=RIGHT, fill=Y)
text.pack()
root.resizable(1,1)
root.mainloop()