diff --git a/.gitignore b/.gitignore index 550d67d..c5a2044 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ src/__pycache__ +.venv \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/.idea/.gitignore @@ -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/ diff --git a/.idea/at1.iml b/.idea/at1.iml new file mode 100644 index 0000000..a0bcb9e --- /dev/null +++ b/.idea/at1.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/discord.xml b/.idea/discord.xml new file mode 100644 index 0000000..30bab2a --- /dev/null +++ b/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5776697 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..205f3bc --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Cart.py b/src/Cart.py index 00da06e..db5a4df 100644 --- a/src/Cart.py +++ b/src/Cart.py @@ -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__() diff --git a/src/MovieView.py b/src/MovieView.py index fa3bba4..2722ad3 100644 --- a/src/MovieView.py +++ b/src/MovieView.py @@ -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() + diff --git a/src/app.py b/src/app.py index 3ba2aec..ca7d380 100644 --- a/src/app.py +++ b/src/app.py @@ -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) diff --git a/src/config.py b/src/config.py new file mode 100644 index 0000000..8906d23 --- /dev/null +++ b/src/config.py @@ -0,0 +1,3 @@ +from Cart import Cart + +cart = Cart()