#!/usr/bin/env python3
from PyQt6.QtWidgets import (
QApplication, QWidget, QHBoxLayout, QVBoxLayout, QPushButton,
QFrame, QLabel, QSizePolicy, QSpacerItem
)
from PyQt6.QtGui import QPainter, QPaintEvent, QColor, QPen, QBrush, QMouseEvent
from PyQt6.QtCore import Qt, QRect, QSize, QPointF
import sys
# noinspection SpellCheckingInspection
class Bitton(QWidget):
def __init__(self):
super().__init__()
self.power: int= 0
self.state: bool = False
self.setMaximumSize(30, 30)
def mouseReleaseEvent(self, a0):
self.state = not self.state
self.update()
def paintEvent(self, pe: QPaintEvent):
pen_color: QColor = QColor("#30aa53") if self.state else QColor("#204023")
brush_color: QColor = QColor("#78ffa3") if self.state else QColor("#258022")
p: QPainter = QPainter(self)
p.setRenderHint(QPainter.RenderHint.Antialiasing)
p.setPen(QPen(pen_color, 3))
p.setBrush(brush_color)
p.drawRoundedRect(self.rect().toRectF(), 4.0, 4.0)
p.drawText(QPointF(), "0")
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Nonbinary, the Decimal/Binary/Hex Calculator")
self.resize(400, 400)
self.build_ui()
def build_ui(self):
hLayout: QHBoxLayout = QHBoxLayout()
for b in range(8):
bit: Bitton = Bitton()
bit.power = b
hLayout.addWidget(bit)
if b == 3: hLayout.addSpacing(4)
self.setLayout(hLayout)
def main():
app = QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec())
if __name__ == "__main__":
main()