Skip to content

Commit 0632c34

Browse files
committed
upload projeto patrimônio
1 parent 5ac965d commit 0632c34

File tree

14 files changed

+2433
-0
lines changed

14 files changed

+2433
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import ttkbootstrap as ttk
2+
from ttkbootstrap import Style
3+
from ttkbootstrap.constants import *
4+
from comportamento import JanelaControl as JControl
5+
from frame_principal import FramePrincipal as FPrincipal
6+
from configuracao import TopTema as TTEma, TopLocais as TLocais, TopCategorias as TCategorias
7+
from crud import Crud
8+
from ttkbootstrap.dialogs import Messagebox as Msg
9+
10+
11+
class Tela:
12+
def mudar_tema(self, tema):
13+
self.tema = ttk.Style().theme_use(tema)
14+
self.customizar_tema()
15+
16+
def customizar_tema(self):
17+
style = Style()
18+
style = Style(style.theme_use())
19+
style.configure('TButton', font=('helvetica', 16, 'bold'))
20+
style.configure('TLabelframe.Label', font=('Helvetica', 16, 'bold'))
21+
style.configure('Toolbutton', font=('Helvetica', 16, 'bold'))
22+
style.configure('TNotebook.Tab', font=('helvatica', 16, 'bold'))
23+
style.configure('Treeview', font=('helvetica', 12), rowheight=18)
24+
style.configure('Treeview.Heading', font=('helvetica', 13, 'bold'))
25+
style.configure('TMenubutton', font=('helvetica', 16, 'bold'))
26+
27+
def apagar_database(self):
28+
opcao = Msg.show_question('Atenção caso prossiga, todos os dados armazenados serão deletados.\nTem certeza que deseja continuar?', 'Resetar dados', buttons=['Cancelar:secondary', 'Continuar:primary'])
29+
if opcao == 'Continuar':
30+
self.crud.drop_database()
31+
self.tela.destroy()
32+
33+
def menu_tela(self):
34+
self.mnu_barra = ttk.Menu(self.tela)
35+
self.mnu_config = ttk.Menu(self.mnu_barra, tearoff=0)
36+
# add cascade mnu barra
37+
self.mnu_barra.add_cascade(label='Configurações', menu=self.mnu_config)
38+
# add command
39+
self.mnu_config.add_command(label='Tema', command=self.toplevel_tema)
40+
self.mnu_config.add_command(label='Locais', command=self.toplevel_local)
41+
self.mnu_config.add_command(label='Categorias', command=self.toplevel_categorias)
42+
self.mnu_config.add_command(label='Resetar dados', command=self.apagar_database)
43+
# associar barra a tela
44+
self.tela.config(menu=self.mnu_barra)
45+
46+
def configurar_tela(self):
47+
self.tela.title('pivaraca patrimonios')
48+
self.tela.withdraw()
49+
self.tela.overrideredirect(True)
50+
self.tela.resizable(False, False)
51+
52+
def toplevel_local(self):
53+
self.att_local = TLocais(self.tela, self)
54+
JControl.controle.add_top_sob(self.att_local.top)
55+
56+
def toplevel_tema(self):
57+
self.att_tema = TTEma(self.tela, self)
58+
JControl.controle.add_top_sob(self.att_tema.top)
59+
60+
def toplevel_categorias(self):
61+
self.att_categorias = TCategorias(self.tela, self)
62+
JControl.controle.add_top_sob(self.att_categorias.top)
63+
64+
def carregar_tema(self):
65+
sql = """select nome
66+
from tema
67+
where id = 1;"""
68+
69+
tema = self.crud.get(sql)
70+
self.mudar_tema(tema[0][0])
71+
72+
def __init__(self, m):
73+
self.tela = m
74+
# configura tela
75+
self.configurar_tela()
76+
self.janela_control = JControl(self.tela, self)
77+
# conexão ao banco
78+
self.crud = Crud()
79+
# selecionar tema
80+
self.carregar_tema()
81+
# customizar tema
82+
self.customizar_tema()
83+
# adiciona menu a tela
84+
self.menu_tela()
85+
# frame tela
86+
self.frame = ttk.Frame(self.tela)
87+
self.frame.pack(expand=True, fill='both')
88+
# atualizar frame
89+
self.att_frame = FPrincipal(self.frame, self)
90+
# centraliza reaparece tela
91+
self.janela_control.centralizar_janela(self.tela)
92+
93+
94+
app = ttk.Window()
95+
att_app = Tela(app)
96+
app.mainloop()
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from crud import Caminho
2+
import ttkbootstrap as ttk
3+
4+
5+
class JanelaControl(Caminho):
6+
controle = None
7+
pai = None
8+
ref = None
9+
10+
def __init__(self, pai, ref):
11+
self._janelas = [pai]
12+
pai.iconbitmap(self.resource_path('icone.ico'))
13+
JanelaControl.controle = self
14+
JanelaControl.pai = pai
15+
JanelaControl.ref = ref
16+
17+
@classmethod
18+
def centralizar_janela(cls, janela):
19+
janela.position_center()
20+
if not janela.winfo_ismapped():
21+
janela.deiconify()
22+
janela.overrideredirect(False)
23+
24+
def comportamento_top(self, top, tp):
25+
if tp == 1:
26+
top.protocol('WM_DELETE_WINDOW', self.voltar)
27+
elif tp == 2:
28+
top.protocol('WM_DELETE_WINDOW', self.voltar_sob)
29+
30+
def add_top(self, top):
31+
self._janelas[-1].withdraw()
32+
self._janelas.append(top)
33+
self.comportamento_top(top, 1)
34+
self.centralizar_janela(top)
35+
top.iconbitmap(self.resource_path('icone.ico'))
36+
37+
def add_top_sob(self, top):
38+
self._janelas.append(top)
39+
self.comportamento_top(top, 2)
40+
top.grab_set()
41+
self.centralizar_janela(top)
42+
top.iconbitmap(self.resource_path('icone.ico'))
43+
44+
def voltar(self):
45+
self._janelas.pop().destroy()
46+
self._janelas[-1].deiconify()
47+
48+
def voltar_sob(self):
49+
self._janelas.pop().destroy()
50+
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import ttkbootstrap as ttk
2+
from ttkbootstrap.constants import *
3+
from frame_inicial import CadastrarLocais as CLocais, SelecionarTema as STema, CadastrarCategorias as CCategorias
4+
5+
6+
7+
8+
class TopLocais:
9+
def configurar_tela(self):
10+
self.top.withdraw()
11+
self.top.title('Cadastro de locais')
12+
self.top.overrideredirect(True)
13+
self.top.resizable(False, False)
14+
15+
def frame_cadastro(self):
16+
self.lfr_cadastro = ttk.Frame(self.frame)
17+
self.lfr_cadastro.pack(side='left', fill='x')
18+
self.att_fr_cadastro = CLocais(self.lfr_cadastro, self)
19+
20+
def __init__(self, pai, ref):
21+
self.pai = pai
22+
self.ref = ref
23+
# toplevel
24+
self.top = ttk.Toplevel(self.pai)
25+
self.configurar_tela()
26+
# frames
27+
self.frame = ttk.Frame(self.top)
28+
self.frame.pack(fill='both', expand=True)
29+
# chamar frames
30+
self.frame_cadastro()
31+
32+
33+
class TopTema:
34+
def configurar_tela(self):
35+
self.top.withdraw()
36+
self.top.title('Selecionar tema')
37+
self.top.overrideredirect(True)
38+
self.top.resizable(False, False)
39+
40+
def frame_cadastro(self):
41+
self.lfr_cadastro = ttk.Frame(self.frame)
42+
self.lfr_cadastro.pack(side='left', fill='x')
43+
self.att_fr_cadastro = STema(self.lfr_cadastro, self)
44+
45+
def __init__(self, pai, ref):
46+
self.pai = pai
47+
self.ref = ref
48+
# toplevel
49+
self.top = ttk.Toplevel(self.pai)
50+
self.configurar_tela()
51+
# frames
52+
self.frame = ttk.Frame(self.top)
53+
self.frame.pack(fill='both', expand=True)
54+
# chamar frames
55+
self.frame_cadastro()
56+
57+
58+
class TopCategorias:
59+
def configurar_tela(self):
60+
self.top.withdraw()
61+
self.top.title('Selecionar tema')
62+
self.top.overrideredirect(True)
63+
self.top.resizable(False, False)
64+
65+
def frame_categorias(self):
66+
self.fr_categorias = ttk.Frame(self.frame)
67+
self.fr_categorias.pack(fill='x')
68+
self.att_fr_categorias = CCategorias(self.fr_categorias, self)
69+
70+
def __init__(self, pai, ref):
71+
self.pai = pai
72+
self.ref = ref
73+
# toplevel
74+
self.top = ttk.Toplevel(self.pai)
75+
self.configurar_tela()
76+
# frame
77+
self.frame = ttk.Frame(self.top)
78+
self.frame.pack(fill='both', expand=True)
79+
# chamar frames
80+
self.frame_categorias()
81+

gerenciador-patrimonio/crud.py

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import sqlite3
2+
from sqlite3 import Error
3+
import os, sys
4+
5+
6+
class Caminho:
7+
def resource_path(self, relativo):
8+
try:
9+
base = sys._MEIPASS
10+
except Exception:
11+
base = os.path.abspath('.')
12+
return os.path.join(base, relativo)
13+
14+
15+
16+
class Conexao(Caminho):
17+
def verificar_banco(self, cursor):
18+
tabelas = cursor.execute('select name from sqlite_master where type="table" ;').fetchall()
19+
if len(tabelas) > 1:
20+
return 1
21+
else:
22+
return 0
23+
24+
def dump(self, conexao, vazio):
25+
if not vazio:
26+
with open(self.resource_path('dump.txt'), 'r', encoding='utf-8') as dump:
27+
cursor = conexao.cursor().executescript(dump.read())
28+
29+
def get_conexao(self):
30+
caminho = (os.path.abspath('patrimonios.db'))
31+
conexao = None
32+
try:
33+
conexao = sqlite3.connect(caminho)
34+
self.dump(conexao, self.verificar_banco(conexao.cursor()))
35+
conexao.cursor().execute('PRAGMA foreign_keys = ON;')
36+
except Error as er:
37+
print(er)
38+
return conexao
39+
40+
41+
class Crud:
42+
def __init__(self):
43+
self.conexao = Conexao()
44+
45+
#inserir
46+
def insert(self, sql):
47+
try:
48+
con = self.conexao.get_conexao()
49+
cursor = con.cursor()
50+
cursor.execute(sql)
51+
if cursor.rowcount == 1:
52+
con.commit()
53+
con.close()
54+
return cursor.rowcount
55+
except Error as er:
56+
print(er)
57+
58+
#inserir retorna id
59+
def insert_id(self, sql):
60+
try:
61+
con = self.conexao.get_conexao()
62+
cursor = con.cursor()
63+
cursor.execute(sql)
64+
id = None
65+
if cursor.rowcount == 1:
66+
id = cursor.execute('select last_insert_rowid()').fetchone()[0]
67+
con.commit()
68+
con.close()
69+
return id
70+
except Error as er:
71+
print(er)
72+
73+
#listar
74+
def get(self, sql):
75+
try:
76+
con = self.conexao.get_conexao()
77+
cursor = con.cursor()
78+
cursor.execute(sql)
79+
resultado = cursor.fetchall()
80+
con.close()
81+
return resultado
82+
except Error as er:
83+
print(er)
84+
85+
def update(self, sql):
86+
try:
87+
con = self.conexao.get_conexao()
88+
cursor = con.cursor()
89+
cursor.execute(sql)
90+
if cursor.rowcount == 1:
91+
con.commit()
92+
con.close()
93+
return cursor.rowcount
94+
except Error as er:
95+
print(er)
96+
97+
def update_id(self, sql):
98+
try:
99+
con = self.conexao.get_conexao()
100+
cursor = con.cursor()
101+
cursor.execute(sql)
102+
if cursor.rowcount == 1:
103+
con.commit()
104+
con.close()
105+
return cursor.rowcount
106+
except Error as er:
107+
print(er)
108+
109+
#excluir
110+
def delete(self, sql):
111+
try:
112+
con = self.conexao.get_conexao()
113+
cursor = con.cursor()
114+
cursor.execute(sql)
115+
if cursor.rowcount == 1:
116+
con.commit()
117+
con.close()
118+
return cursor.rowcount
119+
except Error as er:
120+
print(er)
121+
122+
def drop_database(self):
123+
sql = ''' select name from sqlite_master where type="table" ;'''
124+
try:
125+
con = self.conexao.get_conexao()
126+
cursor = con.cursor()
127+
cursor.execute('PRAGMA foreign_keys = OFF;')
128+
tabelas = cursor.execute(sql).fetchall()
129+
if tabelas:
130+
for tabela in tabelas:
131+
nome_tabela = tabela[0]
132+
if nome_tabela != 'sqlite_sequence':
133+
sql1 = f''' drop table if exists {nome_tabela} ;'''
134+
sql2 = f''' delete from sqlite_sequence where name = "{nome_tabela}" ;'''
135+
cursor.execute(sql1)
136+
cursor.execute(sql2)
137+
con.commit()
138+
con.close()
139+
140+
except Error as er:
141+
print(er)

0 commit comments

Comments
 (0)