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.display = display
|
||||||
self.info = info
|
self.info = info
|
||||||
self._equation = ''
|
self._equation = ''
|
||||||
|
self._equationInitialValue = 'Sua conta'
|
||||||
|
self._left = None
|
||||||
|
self._right = None
|
||||||
|
self._op = None
|
||||||
|
|
||||||
|
self.equation = self._equationInitialValue
|
||||||
self._makeGrid()
|
self._makeGrid()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -71,6 +77,12 @@ class ButtonsGrid(QGridLayout):
|
|||||||
if text == 'C':
|
if text == 'C':
|
||||||
self._connectButtonClicked(button, self._clear)
|
self._connectButtonClicked(button, self._clear)
|
||||||
|
|
||||||
|
if text in '+-/*':
|
||||||
|
self._connectButtonClicked(
|
||||||
|
button,
|
||||||
|
self._makeSlot(self._operatorClicked, button)
|
||||||
|
)
|
||||||
|
|
||||||
def _makeSlot(self, func, *args, **kwargs):
|
def _makeSlot(self, func, *args, **kwargs):
|
||||||
@ Slot(bool)
|
@ Slot(bool)
|
||||||
def realSlot(_):
|
def realSlot(_):
|
||||||
@@ -87,5 +99,27 @@ class ButtonsGrid(QGridLayout):
|
|||||||
self.display.insert(buttonText)
|
self.display.insert(buttonText)
|
||||||
|
|
||||||
def _clear(self):
|
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()
|
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