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.delPressed.connect(self.display.backspace)
|
||||||
self.display.clearPressed.connect(self.vouApagarVocê)
|
self.display.clearPressed.connect(self.vouApagarVocê)
|
||||||
self.display.inputPressed.connect(self.vouApagarVocê)
|
self.display.inputPressed.connect(self.vouApagarVocê)
|
||||||
|
self.display.operatorPressed.connect(self.vouApagarVocê)
|
||||||
|
|
||||||
for rowNumber, rowData in enumerate(self._gridMask):
|
for rowNumber, rowData in enumerate(self._gridMask):
|
||||||
for colNumber, buttonText in enumerate(rowData):
|
for colNumber, buttonText in enumerate(rowData):
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ class Display(QLineEdit):
|
|||||||
delPressed = Signal()
|
delPressed = Signal()
|
||||||
clearPressed = Signal()
|
clearPressed = Signal()
|
||||||
inputPressed = Signal(str)
|
inputPressed = Signal(str)
|
||||||
|
operatorPressed = Signal(str)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*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]
|
isEnter = key in [KEYS.Key_Enter, KEYS.Key_Return, KEYS.Key_Equal]
|
||||||
isDelete = key in [KEYS.Key_Backspace, KEYS.Key_Delete, KEYS.Key_D]
|
isDelete = key in [KEYS.Key_Backspace, KEYS.Key_Delete, KEYS.Key_D]
|
||||||
isEsc = key in [KEYS.Key_Escape, KEYS.Key_C]
|
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:
|
if isEnter:
|
||||||
print(f'EQ {text} pressionado, sinal emitido', type(self).__name__)
|
|
||||||
self.eqPressed.emit()
|
self.eqPressed.emit()
|
||||||
return event.ignore()
|
return event.ignore()
|
||||||
|
|
||||||
if isDelete:
|
if isDelete:
|
||||||
print(f'isDelete {text} pressionado, sinal emitido',
|
|
||||||
type(self).__name__)
|
|
||||||
self.delPressed.emit()
|
self.delPressed.emit()
|
||||||
return event.ignore()
|
return event.ignore()
|
||||||
|
|
||||||
if isEsc:
|
if isEsc:
|
||||||
print('isEsc pressionado, sinal emitido', type(self).__name__)
|
|
||||||
self.clearPressed.emit()
|
self.clearPressed.emit()
|
||||||
return event.ignore()
|
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
|
# Não passar daqui se não tiver texto
|
||||||
if isEmpty(text):
|
if isEmpty(text):
|
||||||
return event.ignore()
|
return event.ignore()
|
||||||
|
|
||||||
if isNumOrDot(text):
|
if isNumOrDot(text):
|
||||||
print(
|
|
||||||
'inputPressed pressionado, sinal emitido', type(self).__name__
|
|
||||||
)
|
|
||||||
self.inputPressed.emit(text)
|
self.inputPressed.emit(text)
|
||||||
return event.ignore()
|
return event.ignore()
|
||||||
|
|||||||
Reference in New Issue
Block a user