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.QtCore import Slot
|
||||||
from PySide6.QtWidgets import QGridLayout, QPushButton
|
from PySide6.QtWidgets import QGridLayout, QPushButton
|
||||||
from utils import isEmpty, isNumOrDot, isValidNumber
|
from utils import isEmpty, isNumOrDot, isValidNumber
|
||||||
from variables import MEDIUM_FONT_SIZE
|
from variables import MEDIUM_FONT_SIZE
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from display import Display
|
||||||
|
from info import Info
|
||||||
|
|
||||||
|
|
||||||
class Button(QPushButton):
|
class Button(QPushButton):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
@@ -18,7 +23,9 @@ class Button(QPushButton):
|
|||||||
|
|
||||||
|
|
||||||
class ButtonsGrid(QGridLayout):
|
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)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
self._gridMask = [
|
self._gridMask = [
|
||||||
@@ -29,8 +36,19 @@ class ButtonsGrid(QGridLayout):
|
|||||||
['', '0', '.', '='],
|
['', '0', '.', '='],
|
||||||
]
|
]
|
||||||
self.display = display
|
self.display = display
|
||||||
|
self.info = info
|
||||||
|
self._equation = ''
|
||||||
self._makeGrid()
|
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):
|
def _makeGrid(self):
|
||||||
for rowNumber, rowData in enumerate(self._gridMask):
|
for rowNumber, rowData in enumerate(self._gridMask):
|
||||||
for colNumber, buttonText in enumerate(rowData):
|
for colNumber, buttonText in enumerate(rowData):
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ if __name__ == '__main__':
|
|||||||
app.setWindowIcon(icon)
|
app.setWindowIcon(icon)
|
||||||
|
|
||||||
# Info
|
# Info
|
||||||
info = Info('2.0 ^ 10.0 = 1024')
|
info = Info('Sua conta')
|
||||||
window.addWidgetToVLayout(info)
|
window.addWidgetToVLayout(info)
|
||||||
|
|
||||||
# Display
|
# Display
|
||||||
@@ -29,7 +29,7 @@ if __name__ == '__main__':
|
|||||||
window.addWidgetToVLayout(display)
|
window.addWidgetToVLayout(display)
|
||||||
|
|
||||||
# Grid
|
# Grid
|
||||||
buttonsGrid = ButtonsGrid(display)
|
buttonsGrid = ButtonsGrid(display, info)
|
||||||
window.vLayout.addLayout(buttonsGrid)
|
window.vLayout.addLayout(buttonsGrid)
|
||||||
|
|
||||||
# Executa tudo
|
# Executa tudo
|
||||||
|
|||||||
Reference in New Issue
Block a user