-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnotepad.py
More file actions
113 lines (90 loc) · 2.68 KB
/
notepad.py
File metadata and controls
113 lines (90 loc) · 2.68 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
import PySimpleGUI as sg #pip install PySimpleGUI
from cx_Freeze import setup, Executable
sg.ChangeLookAndFeel("DarkBrown") # Theame
WIN_W = 90
WIN_H = 25
filename = None
file_new = "Novo (CTRL+G)"
file_open = "Abrir (CTR+O)"
file_save = "Salva Arquivo (CTRL+S)"
sg.Text()
menu_layout = (
["Arquivo", [file_new, file_open, file_save, "Salvar Como", "---", "Sair"]],
["Editar", ["Caixa Alta", "Caixa Baixa"]],
["Ajuda", ["OI"]],
)
layout = [
[sg.MenuBar(menu_layout)],
[
sg.Multiline(
font=("Consolas", 15), text_color="white", size=(WIN_W, WIN_H), key="_BODY_"
)
],
]
window = sg.Window(
"Bloco de Notas",
layout=layout,
margins=(0, 0),
resizable=True,
return_keyboard_events=True,
icon="./img/logo.ico",
)
window.read(timeout=1)
window["_BODY_"].expand(expand_x=True, expand_y=True)
def new_file() -> str:
window["_BODY_"].update(value="")
filename = None
return filename
def open_file() -> str:
try:
filename: str = sg.popup_get_file("Open File", no_window=True)
except:
return
if filename not in (None, "") and not isinstance(filename, tuple):
with open(filename, "r") as f:
window["_BODY_"].update(value=f.read())
return filename
def save_file(filename: str):
if filename not in (None, ""):
with open(filename, "w") as f:
f.write(values.get("_BODY_"))
else:
save_file_as()
def save_file_as() -> str:
try:
filename: str = sg.popup_get_file(
"Save File",
save_as=True,
no_window=True,
default_extension=".txt",
file_types=(("Text", ".txt"),),
)
except:
return
if filename not in (None, "") and not isinstance(filename, tuple):
with open(filename, "w") as f:
f.write(values.get("_BODY_"))
return filename
def caixa_baixa():
window["_BODY_"].update(value=str(values["_BODY_"]).lower())
def caixa_alta():
window["_BODY_"].update(value=str(values["_BODY_"]).upper())
while True:
event, values = window.read()
if event in (None, "Exit"):
window.close()
break
if event in (file_new, "n:77"):
filename = new_file()
if event in (file_open, "o:78"):
filename = open_file()
if event in (file_save, "s:83"):
save_file(filename)
if event in ("Save As",):
filename = save_file_as()
if event == "Caixa Alta":
caixa_alta()
if event == "Caixa Baixa":
caixa_baixa()
Notepad = Notepad()
Notepad.Iniciar()