Calculadora: emitindo os operadores e potenciação

This commit is contained in:
Luiz Otávio
2023-03-04 08:35:08 -03:00
parent e6b23664d0
commit f53db75afc
2 changed files with 12 additions and 7 deletions

View File

@@ -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):

View File

@@ -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()