Calculadora: emitindo os operadores e potenciação
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user