forked from punithpatil/tkinter-text-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·92 lines (76 loc) · 2.96 KB
/
main.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
#!/usr/bin/env python3
'''
Copyright (C) 2015 Punith Patil
Copyright (C) 2019-2020 Joaquín Cuéllar
This file is part of Basic Simple Text Editor.
Basic Simple Text Editor 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.
Basic Simple Text Editor 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 Basic Simple Text Editor.
If not, see <https://www.gnu.org/licenses/>.
'''
import my_globals
import tkinter as tk
from tkinter.font import Font
from tkinter.scrolledtext import ScrolledText
import file_menu
import edit_menu
import format_menu
import help_menu
class mainWindow:
def __init__(self, master=None):
self.master = master
self.set_app_title(None)
self.font = Font(family="Verdana", size=10)
self.text = ScrolledText(self.master, state='normal',
height=400, width=400,
wrap='word',
font=self.font, pady=2,
padx=3, undo=True, bg='white')
self.text.pack(fill=tk.Y, expand=1)
self.text.focus_set()
self.menubar = tk.Menu(self.master, relief=tk.FLAT)
self.selectedText = None
'''configure events'''
self.events()
def build(self):
self.fileMenu = file_menu.fileMenu(self.text, self.master, self)
self.editMenu = edit_menu.editMenu(self.text, self.master, self)
self.formatMenu = format_menu.formatMenu(self.text, self.master, self)
self.helpMenu = help_menu.helpMenu(self.text, self.master, self)
def events(self):
self.text.bind("<<Selection>>", self.selected_text)
self.master.bind("<Button-1>", self.mouse_click)
self.menubar.bind("<Button-1>", self.mouse_click)
def set_app_title(self, file_name):
app_title = my_globals.BTTE_NAME() + '-'
app_title += 'v' + my_globals.BTTE_VERSION() + '-'
if not file_name:
file_name = "Untitled"
app_title += file_name
self.master.title(app_title)
'''EVENTS'''
def selected_text(self, event):
oldSelectedText = self.selectedText
try:
self.selectedText = self.text.get(tk.SEL_FIRST, tk.SEL_LAST)
except:
self.selectedText = None
''' update edit menu'''
if oldSelectedText != self.selectedText:
self.editMenu.update()
def mouse_click(self, event):
self.editMenu.rightClick.unpost()
root = tk.Tk()
root.geometry("300x250+300+300")
root.minsize(width=400, height=400)
appWin = mainWindow(root)
appWin.build()
root.mainloop()