Calculadora: botões especiais de operadores, clear e equation
This commit is contained in:
@@ -38,6 +38,12 @@ class ButtonsGrid(QGridLayout):
|
||||
self.display = display
|
||||
self.info = info
|
||||
self._equation = ''
|
||||
self._equationInitialValue = 'Sua conta'
|
||||
self._left = None
|
||||
self._right = None
|
||||
self._op = None
|
||||
|
||||
self.equation = self._equationInitialValue
|
||||
self._makeGrid()
|
||||
|
||||
@property
|
||||
@@ -71,8 +77,14 @@ class ButtonsGrid(QGridLayout):
|
||||
if text == 'C':
|
||||
self._connectButtonClicked(button, self._clear)
|
||||
|
||||
if text in '+-/*':
|
||||
self._connectButtonClicked(
|
||||
button,
|
||||
self._makeSlot(self._operatorClicked, button)
|
||||
)
|
||||
|
||||
def _makeSlot(self, func, *args, **kwargs):
|
||||
@Slot(bool)
|
||||
@ Slot(bool)
|
||||
def realSlot(_):
|
||||
func(*args, **kwargs)
|
||||
return realSlot
|
||||
@@ -87,5 +99,27 @@ class ButtonsGrid(QGridLayout):
|
||||
self.display.insert(buttonText)
|
||||
|
||||
def _clear(self):
|
||||
print('Vou fazer outra coisa aqui')
|
||||
self._left = None
|
||||
self._right = None
|
||||
self._op = None
|
||||
self.equation = self._equationInitialValue
|
||||
self.display.clear()
|
||||
|
||||
def _operatorClicked(self, button):
|
||||
buttonText = button.text() # +-/* (etc...)
|
||||
displayText = self.display.text() # Deverá ser meu número _left
|
||||
self.display.clear() # Limpa o display
|
||||
|
||||
# Se a pessoa clicou no operador sem
|
||||
# configurar qualquer número
|
||||
if not isValidNumber(displayText) and self._left is None:
|
||||
print('Não tem nada para colocar no valor da esquerda')
|
||||
return
|
||||
|
||||
# Se houver algo no número da esquerda,
|
||||
# não fazemos nada. Aguardaremos o número da direita.
|
||||
if self._left is None:
|
||||
self._left = float(displayText)
|
||||
|
||||
self._op = buttonText
|
||||
self.equation = f'{self._left} {self._op} ??'
|
||||
|
||||
Reference in New Issue
Block a user