Calculadora: Info (QLabel), TYPE_CHECKING, getter e setter e Circular Imports
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
from display import Display
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from PySide6.QtCore import Slot
|
||||
from PySide6.QtWidgets import QGridLayout, QPushButton
|
||||
from utils import isEmpty, isNumOrDot, isValidNumber
|
||||
from variables import MEDIUM_FONT_SIZE
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from display import Display
|
||||
from info import Info
|
||||
|
||||
|
||||
class Button(QPushButton):
|
||||
def __init__(self, *args, **kwargs):
|
||||
@@ -18,7 +23,9 @@ class Button(QPushButton):
|
||||
|
||||
|
||||
class ButtonsGrid(QGridLayout):
|
||||
def __init__(self, display: Display, *args, **kwargs) -> None:
|
||||
def __init__(
|
||||
self, display: 'Display', info: 'Info', *args, **kwargs
|
||||
) -> None:
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self._gridMask = [
|
||||
@@ -29,8 +36,19 @@ class ButtonsGrid(QGridLayout):
|
||||
['', '0', '.', '='],
|
||||
]
|
||||
self.display = display
|
||||
self.info = info
|
||||
self._equation = ''
|
||||
self._makeGrid()
|
||||
|
||||
@property
|
||||
def equation(self):
|
||||
return self._equation
|
||||
|
||||
@equation.setter
|
||||
def equation(self, value):
|
||||
self._equation = value
|
||||
self.info.setText(value)
|
||||
|
||||
def _makeGrid(self):
|
||||
for rowNumber, rowData in enumerate(self._gridMask):
|
||||
for colNumber, buttonText in enumerate(rowData):
|
||||
|
||||
@@ -21,7 +21,7 @@ if __name__ == '__main__':
|
||||
app.setWindowIcon(icon)
|
||||
|
||||
# Info
|
||||
info = Info('2.0 ^ 10.0 = 1024')
|
||||
info = Info('Sua conta')
|
||||
window.addWidgetToVLayout(info)
|
||||
|
||||
# Display
|
||||
@@ -29,7 +29,7 @@ if __name__ == '__main__':
|
||||
window.addWidgetToVLayout(display)
|
||||
|
||||
# Grid
|
||||
buttonsGrid = ButtonsGrid(display)
|
||||
buttonsGrid = ButtonsGrid(display, info)
|
||||
window.vLayout.addLayout(buttonsGrid)
|
||||
|
||||
# Executa tudo
|
||||
|
||||
Reference in New Issue
Block a user