Calculadora: criando a grid de botões
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
from PySide6.QtWidgets import QGridLayout, QPushButton
|
from PySide6.QtWidgets import QGridLayout, QPushButton
|
||||||
|
from utils import isEmpty, isNumOrDot
|
||||||
from variables import MEDIUM_FONT_SIZE
|
from variables import MEDIUM_FONT_SIZE
|
||||||
|
|
||||||
|
|
||||||
@@ -12,17 +13,27 @@ class Button(QPushButton):
|
|||||||
font.setPixelSize(MEDIUM_FONT_SIZE)
|
font.setPixelSize(MEDIUM_FONT_SIZE)
|
||||||
self.setFont(font)
|
self.setFont(font)
|
||||||
self.setMinimumSize(75, 75)
|
self.setMinimumSize(75, 75)
|
||||||
self.setProperty('cssClass', 'specialButton')
|
|
||||||
|
|
||||||
|
|
||||||
class ButtonsGrid(QGridLayout):
|
class ButtonsGrid(QGridLayout):
|
||||||
def __init__(self, *args, **kwargs) -> None:
|
def __init__(self, *args, **kwargs) -> None:
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
self._grid_mask = [
|
self._gridMask = [
|
||||||
['C', '◀', '^', '/'],
|
['C', '◀', '^', '/'],
|
||||||
['7', '8', '9', '*'],
|
['7', '8', '9', '*'],
|
||||||
['4', '5', '6', '-'],
|
['4', '5', '6', '-'],
|
||||||
['1', '2', '3', '+'],
|
['1', '2', '3', '+'],
|
||||||
['', '0', '.', '='],
|
['', '0', '.', '='],
|
||||||
]
|
]
|
||||||
|
self._makeGrid()
|
||||||
|
|
||||||
|
def _makeGrid(self):
|
||||||
|
for rowNumber, rowData in enumerate(self._gridMask):
|
||||||
|
for colNumber, buttonText in enumerate(rowData):
|
||||||
|
button = Button(buttonText)
|
||||||
|
|
||||||
|
if not isNumOrDot(buttonText) and not isEmpty(buttonText):
|
||||||
|
button.setProperty('cssClass', 'specialButton')
|
||||||
|
|
||||||
|
self.addWidget(button, rowNumber, colNumber)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from buttons import Button, ButtonsGrid
|
from buttons import ButtonsGrid
|
||||||
from display import Display
|
from display import Display
|
||||||
from info import Info
|
from info import Info
|
||||||
from main_window import MainWindow
|
from main_window import MainWindow
|
||||||
|
|||||||
11
aula202-calculadora/utils.py
Normal file
11
aula202-calculadora/utils.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
NUM_OR_DOT_REGEX = re.compile(r'^[0-9.]$')
|
||||||
|
|
||||||
|
|
||||||
|
def isNumOrDot(string: str):
|
||||||
|
return bool(NUM_OR_DOT_REGEX.search(string))
|
||||||
|
|
||||||
|
|
||||||
|
def isEmpty(string: str):
|
||||||
|
return len(string) == 0
|
||||||
Reference in New Issue
Block a user