From f53db75afca6d81f6c4ea1754341ef495c9b5b7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Ot=C3=A1vio?= Date: Sat, 4 Mar 2023 08:35:08 -0300 Subject: [PATCH] =?UTF-8?q?Calculadora:=20emitindo=20os=20operadores=20e?= =?UTF-8?q?=20potencia=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aula202-calculadora/buttons.py | 1 + aula202-calculadora/display.py | 18 +++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/aula202-calculadora/buttons.py b/aula202-calculadora/buttons.py index 3fc6e57..4ae6a21 100644 --- a/aula202-calculadora/buttons.py +++ b/aula202-calculadora/buttons.py @@ -71,6 +71,7 @@ class ButtonsGrid(QGridLayout): self.display.delPressed.connect(self.display.backspace) self.display.clearPressed.connect(self.vouApagarVocê) self.display.inputPressed.connect(self.vouApagarVocê) + self.display.operatorPressed.connect(self.vouApagarVocê) for rowNumber, rowData in enumerate(self._gridMask): for colNumber, buttonText in enumerate(rowData): diff --git a/aula202-calculadora/display.py b/aula202-calculadora/display.py index e0a0b33..bbce273 100644 --- a/aula202-calculadora/display.py +++ b/aula202-calculadora/display.py @@ -10,6 +10,7 @@ class Display(QLineEdit): delPressed = Signal() clearPressed = Signal() inputPressed = Signal(str) + operatorPressed = Signal(str) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -31,30 +32,33 @@ class Display(QLineEdit): isEnter = key in [KEYS.Key_Enter, KEYS.Key_Return, KEYS.Key_Equal] isDelete = key in [KEYS.Key_Backspace, KEYS.Key_Delete, KEYS.Key_D] isEsc = key in [KEYS.Key_Escape, KEYS.Key_C] + isOperator = key in [ + KEYS.Key_Plus, KEYS.Key_Minus, KEYS.Key_Slash, KEYS.Key_Asterisk, + KEYS.Key_P, + ] if isEnter: - print(f'EQ {text} pressionado, sinal emitido', type(self).__name__) self.eqPressed.emit() return event.ignore() if isDelete: - print(f'isDelete {text} pressionado, sinal emitido', - type(self).__name__) self.delPressed.emit() return event.ignore() if isEsc: - print('isEsc pressionado, sinal emitido', type(self).__name__) self.clearPressed.emit() return event.ignore() + if isOperator: + if text.lower() == 'p': + text = '^' + self.operatorPressed.emit(text) + return event.ignore() + # Não passar daqui se não tiver texto if isEmpty(text): return event.ignore() if isNumOrDot(text): - print( - 'inputPressed pressionado, sinal emitido', type(self).__name__ - ) self.inputPressed.emit(text) return event.ignore()