From e2d36b3651e7b340ae98b5b4798ffa54cf0fc8ed Mon Sep 17 00:00:00 2001 From: arcbra Date: Mon, 14 Aug 2023 00:25:48 +0200 Subject: [PATCH] Added ANS button and history view --- app/calculador.py | 2 +- app/calculadora.py | 84 +++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 77 insertions(+), 9 deletions(-) diff --git a/app/calculador.py b/app/calculador.py index ac24aa2..d491b03 100644 --- a/app/calculador.py +++ b/app/calculador.py @@ -20,7 +20,7 @@ def __calculation_validation(self, calc): result = eval(calc) return self.__format_result(result=result) - except (NameError, ZeroDivisionError, SyntaxError, ValueError): + except (NameError, ZeroDivisionError, SyntaxError, ValueError, OverflowError): return 'Erro' def __format_result(self, result): diff --git a/app/calculadora.py b/app/calculadora.py index 168cb3f..24d0157 100644 --- a/app/calculadora.py +++ b/app/calculadora.py @@ -32,7 +32,7 @@ class Calculadora(object): 4 | 5 | 6 | - 1 | 2 | 3 | + . | 0 | = | / - | | ^ | √ + 🕑|Ans| ^ | √ OBS: É necessário importar o modulo style contido na pacote view, e selecionar uma de suas classes de estilo. @@ -70,6 +70,11 @@ def __init__(self, master): self._create_buttons(self._frame_buttons) self._create_menu(self.master) + # Dados de história + self._history_results = [] + self._history_operations = [] + self._count_operations = 0 + @staticmethod def _load_settings(): """Utilitário para carregar o arquivo de confirgurações da calculadora.""" @@ -169,10 +174,8 @@ def _create_buttons(self, master): self._BTN_DEL = tk.Button(master, text='<', cnf=self.theme['BTN_CLEAR']) self._BTN_RESULT = tk.Button(master, text='=', cnf=self.theme['BTN_OPERADOR']) self._BTN_DOT = tk.Button(master, text='.', cnf=self.theme['BTN_DEFAULT']) - - # Instânciação dos botões vazios, para futura implementação - self._BTN_VAZIO1 = tk.Button(master, text='', cnf=self.theme['BTN_OPERADOR']) - self._BTN_VAZIO2 = tk.Button(master, text='', cnf=self.theme['BTN_OPERADOR']) + self._BTN_ANS = tk.Button(master, text='ANS', cnf=self.theme['BTN_OPERADOR']) + self._BTN_HISTORY = tk.Button(master, text='🕑', cnf=self.theme['BTN_DEFAULT']) # Distribuição dos botões em um gerenciador de layout grid # Linha 0 @@ -206,8 +209,8 @@ def _create_buttons(self, master): self._BTN_DIV.grid(row=4, column=3, padx=1, pady=1) # Linha 5 - self._BTN_VAZIO1.grid(row=5, column=0, padx=1, pady=1) - self._BTN_VAZIO2.grid(row=5, column=1, padx=1, pady=1) + self._BTN_HISTORY.grid(row=5, column=0, padx=1, pady=1) + self._BTN_ANS.grid(row=5, column=1, padx=1, pady=1) self._BTN_EXP.grid(row=5, column=2, padx=1, pady=1) self._BTN_RAIZ.grid(row=5, column=3, padx=1, pady=1) @@ -239,6 +242,10 @@ def _create_buttons(self, master): self._BTN_DEL['command'] = self._del_last_value_in_input self._BTN_CLEAR['command'] = self._clear_input self._BTN_RESULT['command'] = self._get_data_in_input + self._BTN_ANS['command'] = self._get_ans_number + + # Novas janelas para ver a história + self._BTN_HISTORY.bind("