Adding stuff to cart
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
src/__pycache__
|
src/__pycache__
|
||||||
|
.venv
|
||||||
10
.idea/.gitignore
generated
vendored
Normal file
10
.idea/.gitignore
generated
vendored
Normal 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
15
.idea/at1.iml
generated
Normal 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
7
.idea/discord.xml
generated
Normal 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>
|
||||||
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal 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
7
.idea/misc.xml
generated
Normal 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
8
.idea/modules.xml
generated
Normal 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
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
17
src/Cart.py
17
src/Cart.py
@@ -17,7 +17,7 @@ class ShopItem:
|
|||||||
"""
|
"""
|
||||||
Represents an item that can be bought from the cinema.
|
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.
|
Creates a new ShopItem.
|
||||||
Throws:
|
Throws:
|
||||||
@@ -25,13 +25,13 @@ class ShopItem:
|
|||||||
Example (creates a ShopItem with type popcorn and quantity 3):
|
Example (creates a ShopItem with type popcorn and quantity 3):
|
||||||
ShopItem(ShopItemType.Popcorn, 3)
|
ShopItem(ShopItemType.Popcorn, 3)
|
||||||
"""
|
"""
|
||||||
self.type = type
|
self.type = shoptype
|
||||||
self.movie = movie
|
self.movie = movie
|
||||||
self.quantity = quantity
|
self.quantity = quantity
|
||||||
self.cost: float
|
self.cost: float
|
||||||
match type:
|
match shoptype:
|
||||||
case ShopItemType.Movie:
|
case ShopItemType.Movie:
|
||||||
if movie != None:
|
if movie is not None:
|
||||||
self.cost = movie.price
|
self.cost = movie.price
|
||||||
else:
|
else:
|
||||||
raise ValueError("ShopItem with type ShopItemType.Movie must provide a movie as an argument")
|
raise ValueError("ShopItem with type ShopItemType.Movie must provide a movie as an argument")
|
||||||
@@ -41,18 +41,21 @@ class ShopItem:
|
|||||||
case ShopItemType.Frozen_Coke:
|
case ShopItemType.Frozen_Coke:
|
||||||
self.cost = 4.95
|
self.cost = 4.95
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"ShopItem(type={self.type}, movie={self.movie}, quantity={self.quantity}, cost={self.cost})"
|
||||||
|
|
||||||
@final
|
@final
|
||||||
class Cart:
|
class Cart:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.contents: list[ShopItem] = []
|
self.contents: list[ShopItem] = []
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"Cart(contents={self.contents})"
|
||||||
|
|
||||||
def addItem(self, item: ShopItem):
|
def addItem(self, item: ShopItem):
|
||||||
self.contents.append(item)
|
self.contents.append(item)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
cart = Cart()
|
|
||||||
|
|
||||||
|
|
||||||
class CartView(QWidget):
|
class CartView(QWidget):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|||||||
@@ -1,6 +1,93 @@
|
|||||||
from PySide6.QtGui import Qt
|
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 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):
|
class MovieView(QWidget):
|
||||||
"""
|
"""
|
||||||
@@ -11,6 +98,10 @@ class MovieView(QWidget):
|
|||||||
def __init__(self, movie: Movie):
|
def __init__(self, movie: Movie):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
self.movie: Movie = movie
|
||||||
|
|
||||||
|
self.mp: MoviePurchase = MoviePurchase(self.movie)
|
||||||
|
|
||||||
self.setMaximumWidth(800)
|
self.setMaximumWidth(800)
|
||||||
self.setMaximumHeight(600)
|
self.setMaximumHeight(600)
|
||||||
self.setWindowTitle("Movie Information")
|
self.setWindowTitle("Movie Information")
|
||||||
@@ -26,6 +117,7 @@ class MovieView(QWidget):
|
|||||||
|
|
||||||
button1 = QPushButton("Add to cart")
|
button1 = QPushButton("Add to cart")
|
||||||
button1.setMaximumWidth(100)
|
button1.setMaximumWidth(100)
|
||||||
|
_ = button1.clicked.connect(self.buyCallback)
|
||||||
|
|
||||||
contentlayout.addWidget(label1, 0, 0, alignment=Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignLeft)
|
contentlayout.addWidget(label1, 0, 0, alignment=Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignLeft)
|
||||||
contentlayout.addWidget(button1, 1, 0, alignment=Qt.AlignmentFlag.AlignBottom | 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)
|
self.setLayout(bodylayout)
|
||||||
|
|
||||||
|
def buyCallback(self):
|
||||||
|
self.mp = MoviePurchase(self.movie)
|
||||||
|
self.mp.show()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import sys
|
|||||||
from Movie import movies
|
from Movie import movies
|
||||||
from MovieView import MovieView
|
from MovieView import MovieView
|
||||||
from MovieButton import MovieButton
|
from MovieButton import MovieButton
|
||||||
|
from config import cart
|
||||||
|
|
||||||
# Main Window
|
# Main Window
|
||||||
@final
|
@final
|
||||||
@@ -61,4 +62,5 @@ class MainWindow(QMainWindow):
|
|||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
window = MainWindow()
|
window = MainWindow()
|
||||||
window.show()
|
window.show()
|
||||||
sys.exit(app.exec())
|
app.exec()
|
||||||
|
print(cart)
|
||||||
|
|||||||
3
src/config.py
Normal file
3
src/config.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from Cart import Cart
|
||||||
|
|
||||||
|
cart = Cart()
|
||||||
Reference in New Issue
Block a user