commit 2902cd14b2daac82f5d7d5e6765a10432fddc8b3 Author: Maxwell Jeffress Date: Fri Mar 6 11:30:44 2026 +1100 Initial commit diff --git a/app.py b/app.py new file mode 100644 index 0000000..30321da --- /dev/null +++ b/app.py @@ -0,0 +1,96 @@ +from PySide6.QtCore import QSize +from PySide6.QtWidgets import QApplication, QLabel, QPushButton, QMainWindow, QWidget, QBoxLayout +from PySide6.QtGui import QPixmap + +from typing import final + +import sys + +app = QApplication(sys.argv) + +@final +class Movie: + def __init__(self, name: str, price: float, image: QWidget): + self.name = name + self.price = price + self.image = image + +def createImage(filename: str) -> QWidget: + label = QLabel() + pixmap = QPixmap(filename) + label.setPixmap(pixmap.scaled(300, 300)) + return label + +movies = { + "spiderman": Movie("Spider-Man: Very far from home", 39.95, createImage("resources/spiderman.png")), + "cars2": Movie("Cars 2", 79.95, createImage("resources/cars2.png")), + "leo": Movie("The Nerd Movie", 0, createImage("resources/leo.png")) +} + +class MovieView(QWidget): + def __init__(self, movie: Movie): + super().__init__() + + layout = QBoxLayout(QBoxLayout.Direction.TopToBottom) + + self.setWindowTitle("Movie viewer") + label1 = QLabel(f"Buying a ticket for {movie.name}") + label2 = QLabel(f"For cost ${movie.price}") + label3 = movie.image + + layout.addWidget(label1) + layout.addWidget(label2) + layout.addWidget(label3) + + self.setLayout(layout) + +# Main Window +class MainWindow(QMainWindow): + def __init__(self): + super().__init__() + + self.takers: list[MovieView] = [] + + self.setWindowTitle("Cinema Tickets"); + + layout = QBoxLayout(QBoxLayout.Direction.LeftToRight) + + self.spiderman: QPushButton = QPushButton("Buy tickets for spider man"); + self.spiderman.setCheckable(True) + _ = self.spiderman.clicked.connect(self.buySpiderman) + + layout.addWidget(self.spiderman) + + self.cars: QPushButton = QPushButton("Buy tickets for cars 2"); + self.cars.setCheckable(True) + _ = self.cars.clicked.connect(self.buyCars) + + layout.addWidget(self.cars) + + self.leo: QPushButton = QPushButton("Buy tickets for the nerd movie"); + self.leo.setCheckable(True) + _ = self.leo.clicked.connect(self.buyLeo) + + layout.addWidget(self.leo) + + centralWidget = QWidget() + centralWidget.setLayout(layout) + self.setCentralWidget(centralWidget) + + def buySpiderman(self): + self.takers.append(MovieView(movies["spiderman"])) + self.takers[-1].show() + + def buyLeo(self): + self.takers.append(MovieView(movies["leo"])) + self.takers[-1].show() + + def buyCars(self): + self.takers.append(MovieView(movies["cars2"])) + self.takers[-1].show() + + +window = MainWindow() +window.show() + +exit(app.exec()) diff --git a/resources/cars2.png b/resources/cars2.png new file mode 100644 index 0000000..f8f135b Binary files /dev/null and b/resources/cars2.png differ diff --git a/resources/leo.png b/resources/leo.png new file mode 100644 index 0000000..ec54505 Binary files /dev/null and b/resources/leo.png differ diff --git a/resources/spiderman.png b/resources/spiderman.png new file mode 100644 index 0000000..eb40e20 Binary files /dev/null and b/resources/spiderman.png differ