Adding stuff to cart

This commit is contained in:
2026-03-16 10:19:16 +11:00
parent 61538b93af
commit a9530819a0
12 changed files with 174 additions and 10 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
src/__pycache__
.venv

10
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,10 @@
# Default ignored files
/shelf/
/workspace.xml
# Ignored default folder with query files
/queries/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

15
.idea/at1.iml generated Normal file
View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.14 (at1)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="format" value="PLAIN" />
<option name="myDocStringFormat" value="Plain" />
</component>
</module>

7
.idea/discord.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="ASK" />
<option name="description" value="" />
</component>
</project>

View File

@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.14 (at1)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.14 (at1)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/at1.iml" filepath="$PROJECT_DIR$/.idea/at1.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@@ -17,7 +17,7 @@ class ShopItem:
"""
Represents an item that can be bought from the cinema.
"""
def __init__(self, type: ShopItemType, quantity: int, movie: Movie | None = None):
def __init__(self, shoptype: ShopItemType, quantity: int, movie: Movie | None = None):
"""
Creates a new ShopItem.
Throws:
@@ -25,13 +25,13 @@ class ShopItem:
Example (creates a ShopItem with type popcorn and quantity 3):
ShopItem(ShopItemType.Popcorn, 3)
"""
self.type = type
self.type = shoptype
self.movie = movie
self.quantity = quantity
self.cost: float
match type:
match shoptype:
case ShopItemType.Movie:
if movie != None:
if movie is not None:
self.cost = movie.price
else:
raise ValueError("ShopItem with type ShopItemType.Movie must provide a movie as an argument")
@@ -41,18 +41,21 @@ class ShopItem:
case ShopItemType.Frozen_Coke:
self.cost = 4.95
def __repr__(self):
return f"ShopItem(type={self.type}, movie={self.movie}, quantity={self.quantity}, cost={self.cost})"
@final
class Cart:
def __init__(self):
self.contents: list[ShopItem] = []
def __repr__(self):
return f"Cart(contents={self.contents})"
def addItem(self, item: ShopItem):
self.contents.append(item)
pass
cart = Cart()
class CartView(QWidget):
def __init__(self):
super().__init__()

View File

@@ -1,6 +1,93 @@
from PySide6.QtGui import Qt
from PySide6.QtWidgets import QHBoxLayout, QPushButton, QSpinBox, QVBoxLayout, QWidget, QGridLayout, QLabel
from Cart import ShopItem, ShopItemType
from Movie import Movie, createImage
from PySide6.QtWidgets import QHBoxLayout, QPushButton, QWidget, QGridLayout, QLabel
from config import cart
class MoviePurchase(QWidget):
"""
Widget that helps the user to select the amount of tickets they would like.
Also attempts to upsell the user with popcorn and soft drink.
"""
def __init__(self, movie: Movie):
super().__init__()
self.movie: Movie = movie
bodylayout = QVBoxLayout()
sidebysidelayout = QHBoxLayout()
self.setMaximumWidth(800)
self.setMaximumHeight(600)
self.setMinimumWidth(800)
self.setMinimumHeight(600)
# Left layout - contains the box for the quantity of tickets
leftlayout = QGridLayout()
leftlayout.setAlignment(Qt.AlignTop | Qt.AlignLeft)
leftlayout.addWidget(QLabel("Amount of tickets to get:"), 0, 0)
self.tickets: QSpinBox = QSpinBox()
self.tickets.setRange(1, 50)
self.tickets.setSingleStep(1)
self.tickets.setValue(1)
leftlayout.addWidget(self.tickets, 1, 0)
# Right layout - contains the box for upselling the customer
rightlayout = QGridLayout()
rightlayout.setAlignment(Qt.AlignTop | Qt.AlignLeft)
rightlayout.addWidget(QLabel("The Snackbar"), 0, 0)
# Popcorn
rightlayout.addWidget(QLabel("Popcorn ($8.50 per unit)"), 1, 0)
self.popcorn: QSpinBox = QSpinBox()
self.popcorn.setRange(0, 50)
self.popcorn.setSingleStep(1)
self.popcorn.setValue(1)
rightlayout.addWidget(self.popcorn, 2, 0)
# Frozen Coke
rightlayout.addWidget(QLabel("Frozen Coke ($4.50 per unit)"), 3, 0)
self.frozencoke: QSpinBox = QSpinBox()
self.frozencoke.setRange(0, 50)
self.frozencoke.setSingleStep(1)
self.frozencoke.setValue(1)
rightlayout.addWidget(self.frozencoke, 4, 0)
# Lolly bag
rightlayout.addWidget(QLabel("Lolly Bag ($3.50 per unit)"), 5, 0)
self.lollybag: QSpinBox = QSpinBox()
self.lollybag.setRange(0, 50)
self.lollybag.setSingleStep(1)
self.lollybag.setValue(1)
rightlayout.addWidget(self.lollybag, 6, 0)
sidebysidelayout.addLayout(leftlayout)
sidebysidelayout.addLayout(rightlayout)
# Button to add stuff to cart
self.cartButton: QPushButton = QPushButton("Add to Cart")
_ = self.cartButton.clicked.connect(self.buttonCallback)
bodylayout.addLayout(sidebysidelayout)
bodylayout.addWidget(self.cartButton)
self.setLayout(bodylayout)
self.setWindowTitle("Adding movie to cart")
def buttonCallback(self):
global cart
cart.addItem(ShopItem(ShopItemType.Movie, 1, self.movie))
print("Yay adding to cart")
confirmLayout = QVBoxLayout()
confirmLayout.addWidget(QLabel("Added to cart!"))
self.setLayout(confirmLayout)
pass
class MovieView(QWidget):
"""
@@ -11,6 +98,10 @@ class MovieView(QWidget):
def __init__(self, movie: Movie):
super().__init__()
self.movie: Movie = movie
self.mp: MoviePurchase = MoviePurchase(self.movie)
self.setMaximumWidth(800)
self.setMaximumHeight(600)
self.setWindowTitle("Movie Information")
@@ -26,6 +117,7 @@ class MovieView(QWidget):
button1 = QPushButton("Add to cart")
button1.setMaximumWidth(100)
_ = button1.clicked.connect(self.buyCallback)
contentlayout.addWidget(label1, 0, 0, alignment=Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignLeft)
contentlayout.addWidget(button1, 1, 0, alignment=Qt.AlignmentFlag.AlignBottom | Qt.AlignmentFlag.AlignLeft)
@@ -35,4 +127,8 @@ class MovieView(QWidget):
self.setLayout(bodylayout)
def buyCallback(self):
self.mp = MoviePurchase(self.movie)
self.mp.show()

View File

@@ -5,6 +5,7 @@ import sys
from Movie import movies
from MovieView import MovieView
from MovieButton import MovieButton
from config import cart
# Main Window
@final
@@ -56,9 +57,10 @@ class MainWindow(QMainWindow):
def buyHairyPotty(self):
self.currentMovie = MovieView(movies["hairypotty"])
self.currentMovie.show()
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())
app.exec()
print(cart)

3
src/config.py Normal file
View File

@@ -0,0 +1,3 @@
from Cart import Cart
cart = Cart()