Start working on cart system

This commit is contained in:
2026-03-10 14:26:22 +11:00
parent 2a9a5df30d
commit 61538b93af
2 changed files with 63 additions and 1 deletions

61
src/Cart.py Normal file
View File

@@ -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!")

View File

@@ -13,6 +13,7 @@ class MovieView(QWidget):
self.setMaximumWidth(800) self.setMaximumWidth(800)
self.setMaximumHeight(600) self.setMaximumHeight(600)
self.setWindowTitle("Movie Information")
# Create layouts # Create layouts
bodylayout = QHBoxLayout() bodylayout = QHBoxLayout()
@@ -23,7 +24,7 @@ class MovieView(QWidget):
label1.setWordWrap(True) label1.setWordWrap(True)
label2 = createImage(movie.image_path) label2 = createImage(movie.image_path)
button1 = QPushButton("Buy") button1 = QPushButton("Add to cart")
button1.setMaximumWidth(100) button1.setMaximumWidth(100)
contentlayout.addWidget(label1, 0, 0, alignment=Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignLeft) contentlayout.addWidget(label1, 0, 0, alignment=Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignLeft)