-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
80 lines (69 loc) · 3.19 KB
/
main.py
File metadata and controls
80 lines (69 loc) · 3.19 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
from src import *
from tkinter.filedialog import askopenfilename
class App:
def __init__(self):
"""Inicializa a aplicação e define os botões da interface."""
# Logo do app
icon = CTkLabel(FRAME_READER, image=IMG_LOGO, text=None)
icon.pack(pady=10)
# Elementos do frame_bar
btn_add_file = CTkButton(FRAME_BAR, image=BTN_IMPORT_ICON, text=None, width=50, height=75, command=self.add_file)
btn_del_file = CTkButton(FRAME_BAR, image=BTN_DELETE_ICON, text=None, width=75, height=75, command=self.delete_file)
lbl_img_moon = CTkLabel(FRAME_BAR, image=IMG_MOON_ICON, text=None)
# Switch Theme Dark
self.switch_var = StringVar(value="off")
self.switch_var.trace_add("write", lambda *args: self.toggle_theme())
btn_theme = CTkSwitch(FRAME_BAR, text=None, width=25, variable=self.switch_var, onvalue="on", offvalue="off")
# Agrupando elementos do frame_bar e adicionando-os na tela
btn_bar = [btn_add_file, btn_del_file, lbl_img_moon, btn_theme]
for btn in btn_bar:
btn.pack(padx=15, pady=10)
def toggle_theme(self):
"""Ativa ou desativa o modo theme Dark."""
if self.switch_var.get() == "on":
MASTER.dark_theme()
else:
MASTER.clear_theme()
def draw_files(self):
"""Desenha os arquivos na interface."""
path_index = 2
max_columns = 5
files_list = DB.get_datas()
# Iteração com a lista de Files
for index, file in enumerate(files_list):
row = index // max_columns
column = index % max_columns
new_file = File(FRAME_FILE, file[path_index])
new_file.grid(row=row, column=column, padx=20, pady=25)
def add_file(self):
"""Adiciona um novo arquivo à lista."""
# Importando Ebooks/PDF
'''Definindo:
- Diretório inicial do explorador de arquivos
- Título da aba
- Tipos de arquivos aceitáveis (.pdf/ .docx/ .txt)'''
filedir = askopenfilename(initialdir=getcwd(),
title="Selecionar Arquivo",
filetype=(("PDF File", ".pdf"),
("Doc file", ".docx"),
("Text file", ".txt"),
("All File", '*')))
if not filedir == "":
# Criando um novo "File"
# Adicionando no Banco de Dados
new_file = File(FRAME_FILE, filedir)
DB.add_data((new_file.title, str(new_file.path), new_file.extension))
MASTER.after(10, self.draw_files)
def delete_file(self):
"""Remove um arquivo da lista."""
dialog = CTkInputDialog(text="Nome do Arquivo:", title="Remover Arquivo")
title_file = dialog.get_input()
DB.delete_data(title_file)
MASTER.after(10, self.draw_files)
def run(self):
"""Inicia a aplicação e mantém a interface em execução."""
MASTER.after(10, self.draw_files)
MASTER.mainloop()
if __name__ == "__main__":
app = App()
app.run()