-
Notifications
You must be signed in to change notification settings - Fork 2
/
texteditor.py
617 lines (501 loc) · 21.8 KB
/
texteditor.py
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
"""
Code illustration: 2.12.py
Features Added:
Add context/ Pop-up Menu
Set focus on launch
@Tkinter GUI Application Development Blueprints
"""
import os
from tkinter import *
import tkinter.filedialog
import tkinter.messagebox
import re
from controller import *
PROGRAM_NAME = "ComplexityCounter"
file_name = None
root = Tk()
root.geometry('1080x720')
root.title(PROGRAM_NAME)
code_controller = None
selected_class = None
selected_class_index = None
# show pop-up menu
def reset_all():
global code_controller
global selected_class
global selected_class_index
if code_controller:
code_controller.reset_all()
selected_class = None
selected_class_index = None
def show_popup_menu(event):
popup_menu.tk_popup(event.x_root, event.y_root)
def show_cursor_info_bar():
# show_cursor_info_checked = show_cursor_info.get()
# if show_cursor_info_checked:
# cursor_info_bar.pack(expand='no', fill=None, side='right', anchor='se')
# else:
# cursor_info_bar.pack_forget()
pass
def update_cursor_info_bar(event=None):
row, col = content_text.index(INSERT).split('.')
line_num, col_num = str(int(row)), str(int(col) + 1) # col starts at 0
infotext = "Line: {0} | Column: {1}".format(line_num, col_num)
# cursor_info_bar.config(text=infotext)
def change_theme(event=None):
selected_theme = theme_choice.get()
fg_bg_colors = color_schemes.get(selected_theme)
foreground_color, background_color = fg_bg_colors.split('.')
content_text.config(
background=background_color, fg=foreground_color)
def update_line_numbers(event=None):
line_numbers = get_line_numbers()
line_number_bar.config(state='normal')
line_number_bar.delete('1.0', 'end')
line_number_bar.insert('1.0', line_numbers)
line_number_bar.config(state='disabled')
line_number_bar_left.config(state='normal')
line_number_bar_left.delete('1.0', 'end')
line_number_bar_left.insert('1.0', line_numbers)
line_number_bar_left.config(state='disabled')
def update_complexity_size(event=None):
_complex = get_complexity()
complexity_bar_size.config(state='normal')
complexity_bar_size.delete('1.0', 'end')
complexity_bar_size.insert('1.0', _complex[0])
complexity_bar_size.config(state='disabled')
complexity_bar_tc.config(state='normal')
complexity_bar_tc.delete('1.0', 'end')
complexity_bar_tc.insert('1.0', _complex[1])
complexity_bar_tc.config(state='disabled')
complexity_bar_nc.config(state='normal')
complexity_bar_nc.delete('1.0', 'end')
complexity_bar_nc.insert('1.0', _complex[2])
complexity_bar_nc.config(state='disabled')
complexity_bar_ci.config(state='normal')
complexity_bar_ci.delete('1.0', 'end')
complexity_bar_ci.insert('1.0', _complex[3])
complexity_bar_ci.config(state='disabled')
complexity_bar_TW.config(state='normal')
complexity_bar_TW.delete('1.0', 'end')
complexity_bar_TW.insert('1.0', _complex[4])
complexity_bar_TW.config(state='disabled')
complexity_bar_cps.config(state='normal')
complexity_bar_cps.delete('1.0', 'end')
complexity_bar_cps.insert('1.0', _complex[5])
complexity_bar_cps.config(state='disabled')
complexity_bar_cr.config(state='normal')
complexity_bar_cr.delete('1.0', 'end')
complexity_bar_cr.insert('1.0', _complex[6])
complexity_bar_cr.config(state='disabled')
# for testing
complexity_code_content.config(state='normal')
complexity_code_content.delete('1.0', 'end')
complexity_code_content.insert('1.0', _complex[7])
complexity_code_content.config(state='disabled')
total_complexity['text'] = str(_complex[8])
def load_class(index):
reset_all()
global selected_class
global selected_class_index
selected_class_index = index
selected_class = code_controller.getClassList()[index]
content_text.delete(1.0, END)
content_text.insert(1.0,selected_class.body)
for i,comment in enumerate(selected_class.commentList):
s = indexConverter(comment[0],selected_class.body)
e = indexConverter(comment[1],selected_class.body)
complexity_code_content.tag_add('c'+str(i),s,e)
complexity_code_content.tag_config('c'+str(i),foreground='green')
on_content_changed()
def get_complexity():
size, tc, nc, ci, TW, cps, cr = '','','','','','',''
_test = ''
row, col = content_text.index("end").split('.')
for i in range(1, int(row)):
# TODO: create controller to insert code line < content_text.get(str(i)+'.0',str(i)+'.end') >
# and return value add to the output
start = str(i) + '.0'
end = content_text.index(str(i) + '.end')
s = indexConverter(start, selected_class.body)
e = indexConverter(end, selected_class.body)
# _size = code_controller.calSize(content_text.get(start, end))
_size, _tc, _nc, _ci, _TW, _cps, _cr = code_controller.calComplexityByLine([s,e],selected_class_index)
# TODO : something wrong with size
size += str(_size) + '\n'
tc += str(_tc)+ '\n'
nc += str(_nc)+ '\n'
ci += str(_ci) + '\n'
TW += str(_TW) + '\n'
cps += str(_cps) + '\n'
cr += str(_cr) + '\n'
_test += selected_class.body[s:e] + '\n'
code_controller.cal_total_complexity(_cps,_cr)
_total = code_controller.total_complexity
return [size, tc, nc, ci, TW, cps, cr, _test,_total]
def highlight_line(interval=100):
content_text.tag_remove("active_line", 1.0, "end")
content_text.tag_add(
"active_line", "insert linestart", "insert lineend+1c")
content_text.after(interval, toggle_highlight)
def undo_highlight():
content_text.tag_remove("active_line", 1.0, "end")
def toggle_highlight(event=None):
if to_highlight_line.get():
highlight_line()
else:
undo_highlight()
def on_content_changed(event=None):
update_line_numbers()
update_cursor_info_bar()
update_complexity_size()
def get_line_numbers():
output = '\n'
row, col = content_text.index("end").split('.')
for i in range(1, int(row)):
# TODO: create controller to insert code line < content_text.get(str(i)+'.0',str(i)+'.end') >
# and return value add to the output
output += str(i) + '\n'
return output
def display_about_messagebox(event=None):
tkinter.messagebox.showinfo(
"About", "{}{}".format(PROGRAM_NAME, "\nTkinter GUI Application\n Development Blueprints"))
def display_help_messagebox(event=None):
tkinter.messagebox.showinfo(
"Help", "Help Book: \nTkinter GUI Application\n Development Blueprints",
icon='question')
def exit_editor(event=None):
if tkinter.messagebox.askokcancel("Quit?", "Really quit?"):
root.destroy()
def new_file(event=None):
root.title("Untitled")
global file_name
file_name = None
content_text.delete(1.0, END)
on_content_changed()
def open_file(event=None):
input_file_name = tkinter.filedialog.askopenfilename(defaultextension=".txt",
filetypes=[("All Files", "*.*"), ("Text Documents", "*.txt")])
if input_file_name:
global file_name
file_name = input_file_name
language = file_name.split('.')[1]
root.title('{} - {}'.format(os.path.basename(file_name), PROGRAM_NAME))
content_text.delete(1.0, END)
class_list_bar.delete(0,END)
with open(file_name) as _file:
global code_controller
try:
code_controller = ComplexityController(_file.read(),language)
except Exception as e:
tkinter.messagebox.showinfo(
"Input Error", '{} This file is not valid input.\n{}'.format(file_name,e))
# print(code_controller.getClassList())
for i, _class in enumerate(code_controller.getClassList()):
class_list_bar.insert(i,_class.className)
# content_text.insert(1.0, _file.read())
on_content_changed()
def write_to_file(file_name):
try:
content = content_text.get(1.0, 'end')
with open(file_name, 'w') as the_file:
the_file.write(content)
except IOError:
tkinter.messagebox.showwarning("Save", "Could not save the file.")
def save_as(event=None):
input_file_name = tkinter.filedialog.asksaveasfilename(defaultextension=".txt",
filetypes=[("All Files", "*.*"),
("Text Documents", "*.txt")])
if input_file_name:
global file_name
file_name = input_file_name
write_to_file(file_name)
root.title('{} - {}'.format(os.path.basename(file_name), PROGRAM_NAME))
return "break"
def save(event=None):
global file_name
if not file_name:
save_as()
else:
write_to_file(file_name)
return "break"
def select_all(event=None):
content_text.tag_add('sel', '1.0', 'end')
return "break"
def find_text(event=None):
# search_toplevel = Toplevel(root)
# search_toplevel.title('Find Text')
# search_toplevel.transient(root)
#
# Label(search_toplevel, text="Find All:").grid(row=0, column=0, sticky='e')
#
# search_entry_widget = Entry(
# search_toplevel, width=25)
# search_entry_widget.grid(row=0, column=1, padx=2, pady=2, sticky='we')
# search_entry_widget.focus_set()
# ignore_case_value = IntVar()
# Checkbutton(search_toplevel, text='Ignore Case', variable=ignore_case_value).grid(
# row=1, column=1, sticky='e', padx=2, pady=2)
# Button(search_toplevel, text="Find All", underline=0,
# command=lambda: search_output(
# search_entry_widget.get(), ignore_case_value.get(),
# content_text, search_toplevel, search_entry_widget)
# ).grid(row=0, column=2, sticky='e' + 'w', padx=2, pady=2)
# pass
#
# def close_search_window():
# content_text.tag_remove('match', '1.0', END)
# search_toplevel.destroy()
# search_toplevel.protocol('WM_DELETE_WINDOW', close_search_window)
return "break"
def search_output(needle, if_ignore_case, content_text,
search_toplevel, search_box):
content_text.tag_remove('match', '1.0', END)
matches_found = 0
if needle:
start_pos = '1.0'
while True:
start_pos = content_text.search(needle, start_pos,
nocase=if_ignore_case, stopindex=END)
if not start_pos:
break
end_pos = '{}+{}c'.format(start_pos, len(needle))
content_text.tag_add('match', start_pos, end_pos)
matches_found += 1
start_pos = end_pos
content_text.tag_config(
'match', foreground='red', background='yellow')
search_box.focus_set()
search_toplevel.title('{} matches found'.format(matches_found))
def cut():
content_text.event_generate("<<Cut>>")
on_content_changed()
return "break"
def copy():
content_text.event_generate("<<Copy>>")
return "break"
def paste():
content_text.event_generate("<<Paste>>")
on_content_changed()
return "break"
def undo():
content_text.event_generate("<<Undo>>")
on_content_changed()
return "break"
def redo(event=None):
content_text.event_generate("<<Redo>>")
on_content_changed()
return 'break'
def class_list_select(event):
class_index = class_list_bar.curselection()[0]
load_class(class_index)
def on_scrollbar(*args):
content_text.yview(*args)
line_number_bar.yview(*args)
line_number_bar_left.yview(*args)
complexity_bar_size.yview(*args)
complexity_bar_tc.yview(*args)
complexity_bar_nc.yview(*args)
complexity_bar_ci.yview(*args)
complexity_bar_TW.yview(*args)
complexity_bar_cps.yview(*args)
complexity_bar_cr.yview(*args)
complexity_code_content.yview(*args)
def on_textscroll(*args):
scroll_bar.set(*args)
on_scrollbar('moveto',args[0])
new_file_icon = PhotoImage(file='icons/new_file.gif')
open_file_icon = PhotoImage(file='icons/open_file.gif')
save_file_icon = PhotoImage(file='icons/save.gif')
cut_icon = PhotoImage(file='icons/cut.gif')
copy_icon = PhotoImage(file='icons/copy.gif')
paste_icon = PhotoImage(file='icons/paste.gif')
undo_icon = PhotoImage(file='icons/undo.gif')
redo_icon = PhotoImage(file='icons/redo.gif')
menu_bar = Menu(root)
file_menu = Menu(menu_bar, tearoff=0)
file_menu.add_command(label='Open', accelerator='Ctrl+O', compound='left',
image=open_file_icon, underline=0, command=open_file)
file_menu.add_separator()
file_menu.add_command(label='Exit', accelerator='Alt+F4', command=exit_editor)
menu_bar.add_cascade(label='File', menu=file_menu)
edit_menu = Menu(menu_bar, tearoff=0)
edit_menu.add_command(label='Copy', accelerator='Ctrl+C',
compound='left', image=copy_icon, command=copy)
edit_menu.add_separator()
edit_menu.add_command(label='Find', underline=0,
accelerator='Ctrl+F', command=find_text)
edit_menu.add_separator()
edit_menu.add_command(label='Select All', underline=7,
accelerator='Ctrl+A', command=select_all)
menu_bar.add_cascade(label='Edit', menu=edit_menu)
view_menu = Menu(menu_bar, tearoff=0)
to_highlight_line = BooleanVar()
view_menu.add_checkbutton(label='Highlight Current Line', onvalue=1,
offvalue=0, variable=to_highlight_line, command=toggle_highlight)
themes_menu = Menu(menu_bar, tearoff=0)
view_menu.add_cascade(label='Themes', menu=themes_menu)
color_schemes = {
'Default': '#000000.#FFFFFF',
'Greygarious': '#83406A.#D1D4D1',
'Aquamarine': '#5B8340.#D1E7E0',
'Bold Beige': '#4B4620.#FFF0E1',
'Cobalt Blue': '#ffffBB.#3333aa',
'Olive Green': '#D1E7E0.#5B8340',
'Night Mode': '#FFFFFF.#000000',
}
theme_choice = StringVar()
theme_choice.set('Default')
for k in sorted(color_schemes):
themes_menu.add_radiobutton(
label=k, variable=theme_choice, command=change_theme)
menu_bar.add_cascade(label='View', menu=view_menu)
about_menu = Menu(menu_bar, tearoff=0)
about_menu.add_command(label='About', command=display_about_messagebox)
about_menu.add_command(label='Help', command=display_help_messagebox)
menu_bar.add_cascade(label='About', menu=about_menu)
root.config(menu=menu_bar)
shortcut_bar = Frame(root, height=25)
shortcut_bar.pack(expand='no', fill='x')
icons = ('open_file','copy','find_text')
for i, icon in enumerate(icons):
tool_bar_icon = PhotoImage(file='icons/{}.gif'.format(icon))
cmd = eval(icon)
tool_bar = Button(shortcut_bar, image=tool_bar_icon, command=cmd)
tool_bar.image = tool_bar_icon
tool_bar.pack(side='left')
total_complexity = Label(shortcut_bar, text= 'To check complexity click the class ',font= 'Times 15 bold')
total_complexity.pack(side='right')
title_bar = Label(root,height=1)
title_bar.pack(side='top',fill='x')
class_list_bar_frame = Frame(root)
class_list_bar_frame.pack(side='left',fill='y')
class_list_bar_title = Label(class_list_bar_frame,text='Class List')
class_list_bar_title.pack(anchor='nw')
class_list_bar = Listbox(class_list_bar_frame,selectmode=SINGLE)
class_list_bar.bind('<<ListboxSelect>>',class_list_select)
class_list_bar.pack(side='left',fill='y')
right_frame = Frame(root)
line_number_bar_frame = Frame(right_frame, width=3)
line_number_bar_left_frame = Frame(right_frame, width=3)
complexity_bar_size_frame = Frame(right_frame, width=3)
complexity_bar_tc_frame = Frame(right_frame, width=3)
complexity_bar_nc_frame = Frame(right_frame, width=3)
complexity_bar_ci_frame = Frame(right_frame, width=3)
complexity_bar_TW_frame = Frame(right_frame, width=3)
complexity_bar_cps_frame = Frame(right_frame, width=3)
complexity_bar_cr_frame = Frame(right_frame, width=3)
complexity_code_content_frame = Frame(right_frame)
line_number_bar_left_title= Label(line_number_bar_left_frame,text='l#')
complexity_bar_size_title = Label(complexity_bar_size_frame,text='cs')
complexity_bar_tc_title= Label(complexity_bar_tc_frame,text='tc')
complexity_bar_nc_title= Label(complexity_bar_nc_frame,text='nc')
complexity_bar_ci_title= Label(complexity_bar_ci_frame,text='ci')
complexity_bar_TW_title= Label(complexity_bar_TW_frame,text='TW')
complexity_bar_cps_title= Label(complexity_bar_cps_frame,text='cps')
complexity_bar_cr_title= Label(complexity_bar_cr_frame,text='cr')
complexity_code_content_title= Label(complexity_code_content_frame,text='Source Code')
line_number_bar_title = Label(line_number_bar_frame,text='#')
line_number_bar = Text(line_number_bar_frame, width=3, padx=3, takefocus=0, border=0,
background='khaki', state='disabled', wrap='none') # line number bar right
line_number_bar_left = Text(line_number_bar_left_frame, width=3, padx=3, takefocus=0, border=0,
background='khaki', state='disabled', wrap='none')
complexity_bar_size = Text(complexity_bar_size_frame, width=3, padx=3, takefocus=0, border=0,
background='steelblue', state='disabled', wrap='none')
complexity_bar_tc = Text(complexity_bar_tc_frame, width=3, padx=3, takefocus=0, border=0,
background='skyblue', state='disabled', wrap='none')
complexity_bar_nc = Text(complexity_bar_nc_frame, width=3, padx=3, takefocus=0, border=0,
background='steelblue', state='disabled', wrap='none')
complexity_bar_ci = Text(complexity_bar_ci_frame, width=3, padx=3, takefocus=0, border=0,
background='skyblue', state='disabled', wrap='none')
complexity_bar_TW = Text(complexity_bar_TW_frame, width=3, padx=3, takefocus=0, border=0,
background='steelblue', state='disabled', wrap='none')
complexity_bar_cps = Text(complexity_bar_cps_frame, width=3, padx=3, takefocus=0, border=0,
background='skyblue', state='disabled', wrap='none')
complexity_bar_cr = Text(complexity_bar_cr_frame, width=3, padx=3, takefocus=0, border=0,
background='steelblue', state='disabled', wrap='none')
complexity_code_content = Text(complexity_code_content_frame,width=116, padx=3, takefocus=0, border=0,
background='yellow', state='disabled', wrap='word')
content_text = Text(right_frame,width=1)
#,width=1, wrap='word',padx=3, undo=1,takefocus=0, border=0)
scroll_bar = Scrollbar(content_text)
# content_text.configure(yscrollcommand=scroll_bar.set)
# scroll_bar.config(command=content_text.yview)
scroll_bar['command'] = on_scrollbar
content_text['yscrollcommand'] = on_textscroll
line_number_bar['yscrollcommand'] = on_textscroll
line_number_bar_left['yscrollcommand'] = on_textscroll
complexity_bar_size['yscrollcommand'] = on_textscroll
complexity_bar_tc['yscrollcommand'] = on_textscroll
complexity_bar_nc['yscrollcommand'] = on_textscroll
complexity_bar_ci['yscrollcommand'] = on_textscroll
complexity_bar_TW['yscrollcommand'] = on_textscroll
complexity_bar_cps['yscrollcommand'] = on_textscroll
complexity_bar_cr['yscrollcommand'] = on_textscroll
complexity_code_content['yscrollcommand'] = on_textscroll
# packing
content_text.pack(side='right', fill='y')
complexity_bar_cr_frame.pack(side='right', fill='y')
complexity_bar_cps_frame.pack(side='right', fill='y')
complexity_bar_TW_frame.pack(side='right', fill='y')
complexity_bar_ci_frame.pack(side='right', fill='y')
complexity_bar_nc_frame.pack(side='right', fill='y')
complexity_bar_tc_frame.pack(side='right', fill='y')
complexity_bar_size_frame .pack(side='right', fill='y')
line_number_bar_left_frame.pack(side='right', fill='y')
complexity_code_content_frame.pack(side='right', fill='y')
line_number_bar_left_title.pack()
complexity_bar_size_title.pack()
complexity_bar_tc_title.pack()
complexity_bar_nc_title.pack()
complexity_bar_ci_title.pack()
complexity_bar_TW_title.pack()
complexity_bar_cps_title.pack()
complexity_bar_cr_title.pack()
complexity_code_content_title.pack()
complexity_bar_cr.pack(side='right', fill='y')
complexity_bar_cps.pack(side='right', fill='y')
complexity_bar_TW.pack(side='right', fill='y')
complexity_bar_ci.pack(side='right', fill='y')
complexity_bar_nc.pack(side='right', fill='y')
complexity_bar_tc.pack(side='right', fill='y')
complexity_bar_size.pack(side='right', fill='y')
line_number_bar_frame.pack(side='right', fill='y')
right_frame.pack(side='right',fill='y')
scroll_bar.pack(side='right', fill='y')
line_number_bar_title.pack()
line_number_bar.pack(side='right', fill='y')
complexity_code_content.pack(expand='yes', fill='both')
line_number_bar_left.pack(side='left', fill='y')
# cursor_info_bar = Label(content_text, text='Line: 1 | Column: 1')
# cursor_info_bar.pack(expand='no', fill=None, side='right', anchor='se')
content_text.bind('<KeyPress-F1>', display_help_messagebox)
content_text.bind('<Control-N>', new_file)
content_text.bind('<Control-n>', new_file)
content_text.bind('<Control-O>', open_file)
content_text.bind('<Control-o>', open_file)
content_text.bind('<Control-S>', save)
content_text.bind('<Control-s>', save)
content_text.bind('<Control-f>', find_text)
content_text.bind('<Control-F>', find_text)
content_text.bind('<Control-A>', select_all)
content_text.bind('<Control-a>', select_all)
content_text.bind('<Control-y>', redo)
content_text.bind('<Control-Y>', redo)
content_text.bind('<Any-KeyPress>', on_content_changed)
content_text.tag_configure('active_line', background='ivory2')
# set up the pop-up menu
popup_menu = Menu(content_text)
for i in ('cut', 'copy', 'paste', 'undo', 'redo'):
cmd = eval(i)
popup_menu.add_command(label=i, compound='left', command=cmd)
popup_menu.add_separator()
popup_menu.add_command(label='Select All', underline=7, command=select_all)
content_text.bind('<Button-3>', show_popup_menu)
# bind right mouse click to show pop up and set focus to text widget on launch
content_text.bind('<Button-3>', show_popup_menu)
content_text.focus_set()
root.protocol('WM_DELETE_WINDOW', exit_editor)
root.mainloop()
def test():
pass