From 5b4176f51485b9ab0f1f244220b0b17d4f12952e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Ot=C3=A1vio?= Date: Fri, 3 Mar 2023 06:21:30 -0300 Subject: [PATCH] =?UTF-8?q?Calculadora:=20iniciando=20a=20configura=C3=A7?= =?UTF-8?q?=C3=A3o=20dos=20bot=C3=B5es=20especiais?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aula202-calculadora/buttons.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/aula202-calculadora/buttons.py b/aula202-calculadora/buttons.py index 22211f5..488b43e 100644 --- a/aula202-calculadora/buttons.py +++ b/aula202-calculadora/buttons.py @@ -56,15 +56,22 @@ class ButtonsGrid(QGridLayout): if not isNumOrDot(buttonText) and not isEmpty(buttonText): button.setProperty('cssClass', 'specialButton') + self._configSpecialButton(button) self.addWidget(button, rowNumber, colNumber) - buttonSlot = self._makeButtonDisplaySlot( - self._insertButtonTextToDisplay, - button, - ) - button.clicked.connect(buttonSlot) # type: ignore + slot = self._makeSlot(self._insertButtonTextToDisplay, button) + self._connectButtonClicked(button, slot) - def _makeButtonDisplaySlot(self, func, *args, **kwargs): + def _connectButtonClicked(self, button, slot): + button.clicked.connect(slot) # type: ignore + + def _configSpecialButton(self, button): + text = button.text() + + if text == 'C': + self._connectButtonClicked(button, self._clear) + + def _makeSlot(self, func, *args, **kwargs): @Slot(bool) def realSlot(_): func(*args, **kwargs) @@ -78,3 +85,7 @@ class ButtonsGrid(QGridLayout): return self.display.insert(buttonText) + + def _clear(self): + print('Vou fazer outra coisa aqui') + self.display.clear()