From 61538b93aff42d3c4a6804697f56b827dcc424d1 Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Tue, 10 Mar 2026 14:26:22 +1100 Subject: [PATCH] Start working on cart system --- src/Cart.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ src/MovieView.py | 3 ++- 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/Cart.py diff --git a/src/Cart.py b/src/Cart.py new file mode 100644 index 0000000..00da06e --- /dev/null +++ b/src/Cart.py @@ -0,0 +1,61 @@ +from typing import final + +from PySide6.QtWidgets import QWidget +from Movie import Movie +from enum import Enum + +class ShopItemType(Enum): + """ + Enum dictating types of items that can be bought from the cinema. + """ + Movie = 0 + Popcorn = 1 + Frozen_Coke = 2 + +@final +class ShopItem: + """ + Represents an item that can be bought from the cinema. + """ + def __init__(self, type: ShopItemType, quantity: int, movie: Movie | None = None): + """ + Creates a new ShopItem. + Throws: + ValueError - type is ShopItemType.Movie, but movie is not provided as a paramater + Example (creates a ShopItem with type popcorn and quantity 3): + ShopItem(ShopItemType.Popcorn, 3) + """ + self.type = type + self.movie = movie + self.quantity = quantity + self.cost: float + match type: + case ShopItemType.Movie: + if movie != None: + self.cost = movie.price + else: + raise ValueError("ShopItem with type ShopItemType.Movie must provide a movie as an argument") + case ShopItemType.Popcorn: + self.cost = 9.95 + pass + case ShopItemType.Frozen_Coke: + self.cost = 4.95 + +@final +class Cart: + def __init__(self): + self.contents: list[ShopItem] = [] + + def addItem(self, item: ShopItem): + self.contents.append(item) + pass + +cart = Cart() + + +class CartView(QWidget): + def __init__(self): + super().__init__() + global cart + self.setWindowTitle("Work in progress!") + diff --git a/src/MovieView.py b/src/MovieView.py index c57863e..fa3bba4 100644 --- a/src/MovieView.py +++ b/src/MovieView.py @@ -13,6 +13,7 @@ class MovieView(QWidget): self.setMaximumWidth(800) self.setMaximumHeight(600) + self.setWindowTitle("Movie Information") # Create layouts bodylayout = QHBoxLayout() @@ -23,7 +24,7 @@ class MovieView(QWidget): label1.setWordWrap(True) label2 = createImage(movie.image_path) - button1 = QPushButton("Buy") + button1 = QPushButton("Add to cart") button1.setMaximumWidth(100) contentlayout.addWidget(label1, 0, 0, alignment=Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignLeft)