Calculadora: os Signals de teclas digitadas aos Slots corretos
This commit is contained in:
@@ -59,19 +59,12 @@ class ButtonsGrid(QGridLayout):
|
||||
self._equation = value
|
||||
self.info.setText(value)
|
||||
|
||||
def vouApagarVocê(self, *args):
|
||||
print(
|
||||
'Signal recebido por "vouApagarVocê" em',
|
||||
type(self).__name__,
|
||||
args,
|
||||
)
|
||||
|
||||
def _makeGrid(self):
|
||||
self.display.eqPressed.connect(self.vouApagarVocê)
|
||||
self.display.eqPressed.connect(self._eq)
|
||||
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ê)
|
||||
self.display.clearPressed.connect(self._clear)
|
||||
self.display.inputPressed.connect(self._insertToDisplay)
|
||||
self.display.operatorPressed.connect(self._configLeftOp)
|
||||
|
||||
for rowNumber, rowData in enumerate(self._gridMask):
|
||||
for colNumber, buttonText in enumerate(rowData):
|
||||
@@ -82,7 +75,7 @@ class ButtonsGrid(QGridLayout):
|
||||
self._configSpecialButton(button)
|
||||
|
||||
self.addWidget(button, rowNumber, colNumber)
|
||||
slot = self._makeSlot(self._insertButtonTextToDisplay, button)
|
||||
slot = self._makeSlot(self._insertToDisplay, buttonText)
|
||||
self._connectButtonClicked(button, slot)
|
||||
|
||||
def _connectButtonClicked(self, button, slot):
|
||||
@@ -100,27 +93,29 @@ class ButtonsGrid(QGridLayout):
|
||||
if text in '+-/*^':
|
||||
self._connectButtonClicked(
|
||||
button,
|
||||
self._makeSlot(self._operatorClicked, button)
|
||||
self._makeSlot(self._configLeftOp, button)
|
||||
)
|
||||
|
||||
if text == '=':
|
||||
self._connectButtonClicked(button, self._eq)
|
||||
|
||||
@Slot()
|
||||
def _makeSlot(self, func, *args, **kwargs):
|
||||
@ Slot(bool)
|
||||
def realSlot(_):
|
||||
func(*args, **kwargs)
|
||||
return realSlot
|
||||
|
||||
def _insertButtonTextToDisplay(self, button):
|
||||
buttonText = button.text()
|
||||
newDisplayValue = self.display.text() + buttonText
|
||||
@Slot()
|
||||
def _insertToDisplay(self, text):
|
||||
newDisplayValue = self.display.text() + text
|
||||
|
||||
if not isValidNumber(newDisplayValue):
|
||||
return
|
||||
|
||||
self.display.insert(buttonText)
|
||||
self.display.insert(text)
|
||||
|
||||
@Slot()
|
||||
def _clear(self):
|
||||
self._left = None
|
||||
self._right = None
|
||||
@@ -128,8 +123,8 @@ class ButtonsGrid(QGridLayout):
|
||||
self.equation = self._equationInitialValue
|
||||
self.display.clear()
|
||||
|
||||
def _operatorClicked(self, button):
|
||||
buttonText = button.text() # +-/* (etc...)
|
||||
@Slot()
|
||||
def _configLeftOp(self, text):
|
||||
displayText = self.display.text() # Deverá ser meu número _left
|
||||
self.display.clear() # Limpa o display
|
||||
|
||||
@@ -144,9 +139,10 @@ class ButtonsGrid(QGridLayout):
|
||||
if self._left is None:
|
||||
self._left = float(displayText)
|
||||
|
||||
self._op = buttonText
|
||||
self._op = text
|
||||
self.equation = f'{self._left} {self._op} ??'
|
||||
|
||||
@Slot()
|
||||
def _eq(self):
|
||||
displayText = self.display.text()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user