-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·183 lines (147 loc) · 6.97 KB
/
Copy pathmain.py
File metadata and controls
executable file
·183 lines (147 loc) · 6.97 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
from tkinter import *
from tkinter.filedialog import asksaveasfilename,askopenfilename
from tkinter import colorchooser,messagebox
from spellchecker import SpellChecker
import sys
from widget_registry import register_widget
from file_functions import *
from edit_functions import *
from customize_functions import *
from help_functions import *
from print_function import *
from clipboard_functions import *
#welcome to TkT
root=Tk()
root.title("『Tk』Ed")
root.geometry("1280x720")
img=PhotoImage(file='assets/code.png')
root.iconphoto(True,img)
def New_page(event=None):
print("Opening a new file")
T.delete("1.0",END)
notification("New File",700)
T.after(1000,main)
# main()
def spell_check(event=None):
spell = SpellChecker()
misspelled = T.get("1.0",END)
words = misspelled.split()
correction = []
for i in words:
correction.append(spell.correction(i))
corrected_string = ' '.join(correction)
T.delete('1.0',END)
T.insert(END, corrected_string)
def main():
global T
frame=Frame(root)
frame.grid(row=0, column=0, sticky='e')
menubar=Menu(root)
global Options_Menu
Options_Menu=Menu(menubar,tearoff=0)
# menubar.bind('<Alt-1>', Options_Menu)
menubar.add_cascade(label="File", menu=Options_Menu)
# root.bind('<Alt-1>')
Options_Menu.add_command(label="New",command=New_page,accelerator="Ctrl+n")
root.bind('<Control-n>', New_page)
Options_Menu.add_command(label="Open",command=Fetch_file_path,accelerator="Ctrl+o")
root.bind('<Control-o>', Fetch_file_path)
Options_Menu.add_command(label="Save",command=Save,accelerator="Ctrl+s")
root.bind('<Control-s>', Save)
Options_Menu.add_command(label="SaveAs",command=saveAs,accelerator="Ctrl+Shift+S")
root.bind('<Control-Shift-S>', saveAs)
Options_Menu.add_command(label="SpellCheck", command=spell_check,accelerator="F7")
root.bind('<F7>',spell_check)
Options_Menu.add_command(label="ClearScreen",command=clear_all,accelerator="Ctrl+l")
root.bind('<Control-l>',clear_all)
Options_Menu.add_separator()
Options_Menu.add_command(label="Exit",command = lambda: close_window(root))
Edit_Menu=Menu(menubar,tearoff=0)
menubar.add_cascade(label="Edit",menu=Edit_Menu)
Edit_Menu.add_command(label="Bold",command=set_bold,accelerator="Ctrl+b")
root.bind("<Control-b>",set_bold)
Edit_Menu.add_command(label="Italics",command=set_italics,accelerator="Ctrl+i")
root.bind("<Control-i>",set_italics)
Edit_Menu.add_command(label="Underline",command=set_underline,accelerator="Ctrl+u")
root.bind("<Control-u>",set_underline)
Edit_Menu.add_command(label="Stikethrough",command=set_strike,accelerator="Ctrl+r")
root.bind("<Control-r>",set_strike)
Edit_Menu.add_command(label="Bold&Italics",command=set_bold_italics,accelerator="Ctrl+Shift+B")
root.bind("<Control-Shift-B>",set_bold_italics)
Edit_Menu.add_command(label="Remove",command=remove_emphasis,accelerator="Ctrl+Shift+R")
root.bind("<Control-Shift-R>",remove_emphasis)
Edit_Menu.add_separator()
Edit_Menu.add_command(label="Highlight Text",command=highlight_text,accelerator="Ctrl+e")
root.bind("<Control-e>",highlight_text)
Edit_Menu.add_command(label="Find and Replace",command=find_and_replace,accelerator="Ctrl+f")
root.bind("<Control-f>",find_and_replace)
Customize_Menu=Menu(menubar,tearoff=0)
menubar.add_cascade(label="Customize",menu=Customize_Menu)
Customize_Menu.add_command(label="Font Style",command=Sel_font_style)
Customize_Menu.add_command(label="Font Size",command=Set_font_size)
Customize_Menu.add_command(label="BG Color",command=Sel_bg_color)
Customize_Menu.add_command(label="FG Color",command=Sel_fg_color)
Help_menu=Menu(menubar,tearoff=0)
menubar.add_cascade(label="Help",menu=Help_menu)
Help_menu.add_command(label="ReadMe",command=Open_ReadMe)
Help_menu.add_command(label="Shortcuts",command=Open_Shortcuts,accelerator="F1")
root.bind('<F1>',Open_Shortcuts)
Print_menu=Menu(menubar,tearoff=0)
menubar.add_cascade(label="Print",menu=Print_menu)
Print_menu.add_command(label="Generate PDF",command=convert_to_pdf,accelerator="Ctrl+p")
root.bind("<Control-p>",convert_to_pdf)
Clipboard_Menu=Menu(menubar,tearoff=0)
menubar.add_cascade(label="ClipBoard",menu=Clipboard_Menu)
Clipboard_Menu.add_command(label="Copy", command=copy_text, accelerator="Ctrl+c")
Clipboard_Menu.add_command(label="Cut", command=cut_text, accelerator="Ctrl+x")
Clipboard_Menu.add_command(label="Paste", command=paste_text, accelerator="Ctrl+v")
T=Text(root,height=700,width=700,undo=True,wrap=NONE)
T.grid(row=0, column=0, sticky='nsew')
T.focus_set()
register_widget('text_widget',T)
def open_clipboard_menu(event=None):
"""Open a dropdown menu for clipboard items (keyboard navigable)."""
if not local_clipboard:
messagebox.showinfo("Clipboard", "Clipboard is empty!")
return
menu = Menu(root, tearoff=0)
for item in local_clipboard:
display = item.replace("\n", " ")
menu.add_command(label=display, command=lambda i=item: paste_text(item=i))
# Show menu below the Text widget cursor
x = clipboard_btn.winfo_rootx()
y = clipboard_btn.winfo_rooty() + clipboard_btn.winfo_height() # below the button
menu.post(x, y)
# Bind F8 to open the clipboard menu
root.bind("<F8>", open_clipboard_menu)
T.bind("<Control-c>", copy_text)
T.bind("<Control-x>", cut_text)
T.bind("<Control-v>", paste_text)
Font_tuple=(font_name,font_size,"normal")
T.configure(font=Font_tuple,foreground=color_hex_fg_code,background=color_hex_bg_code)
root.grid_rowconfigure(0, weight=1)
root.grid_columnconfigure(0, weight=1)
root.config(menu=menubar)
scroll_bar_v=Scrollbar(root,orient=VERTICAL,command=T.yview)
scroll_bar_v.grid(row=0,column=1,sticky='ns')
T.config(yscrollcommand=scroll_bar_v.set)
scroll_bar_h=Scrollbar(root,orient=HORIZONTAL,command=T.xview)
scroll_bar_h.grid(row=1,column=0,sticky='ew')
T.config(xscrollcommand=scroll_bar_h.set)
# -------------------- Clipboard Button --------------------
def show_clipboard_menu(event=None):
if not local_clipboard:
messagebox.showinfo("Clipboard", "Clipboard is empty!")
return
menu = Menu(root, tearoff=0)
for item in local_clipboard:
display = item.replace("\n", " ")
menu.add_command(label=display, command=lambda i=item: paste_text(item=i))
menu.tk_popup(clipboard_btn.winfo_rootx(), clipboard_btn.winfo_rooty() + clipboard_btn.winfo_height())
clipboard_btn = Button(root, text="📋", font=("Arial", 12), command=show_clipboard_menu)
clipboard_btn.place(relx=0.98, rely=0, anchor="ne") # Top-right corner
if len(sys.argv) == 2 :
Fetch_file_path()
root.mainloop()
if __name__ == "__main__":
main()