View cart
This commit is contained in:
15
src/Cart.py
15
src/Cart.py
@@ -1,6 +1,6 @@
|
||||
from typing import final
|
||||
|
||||
from PySide6.QtWidgets import QWidget
|
||||
from PySide6.QtWidgets import QWidget, QVBoxLayout, QLabel
|
||||
from Movie import Movie
|
||||
from enum import Enum
|
||||
|
||||
@@ -46,6 +46,9 @@ class ShopItem:
|
||||
|
||||
@final
|
||||
class Cart:
|
||||
|
||||
cv: CartView | None = None
|
||||
|
||||
def __init__(self):
|
||||
self.contents: list[ShopItem] = []
|
||||
|
||||
@@ -56,9 +59,19 @@ class Cart:
|
||||
self.contents.append(item)
|
||||
pass
|
||||
|
||||
def show(self):
|
||||
self.cv = CartView()
|
||||
self.cv.show()
|
||||
|
||||
|
||||
cart = Cart()
|
||||
|
||||
class CartView(QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
global cart
|
||||
self.setWindowTitle("Work in progress!")
|
||||
layout = QVBoxLayout()
|
||||
layout.addWidget(QLabel(f"Cart: {cart}"))
|
||||
self.setLayout(layout)
|
||||
|
||||
|
||||
@@ -14,6 +14,9 @@ class Movie:
|
||||
self.price = price
|
||||
self.image_path = image_path
|
||||
self.description = description
|
||||
|
||||
def __repr__(self):
|
||||
return f"Movie(name={self.name}, price={self.price}, image_path={self.image_path}, description={self.description})"
|
||||
|
||||
def createImage(filename: str) -> QLabel:
|
||||
"""
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
from PySide6.QtGui import Qt
|
||||
from PySide6.QtWidgets import QHBoxLayout, QPushButton, QSpinBox, QVBoxLayout, QWidget, QGridLayout, QLabel
|
||||
|
||||
from Cart import ShopItem, ShopItemType
|
||||
from Cart import ShopItem, ShopItemType, cart
|
||||
from Movie import Movie, createImage
|
||||
from config import cart
|
||||
|
||||
class MoviePurchase(QWidget):
|
||||
"""
|
||||
|
||||
19
src/app.py
19
src/app.py
@@ -1,11 +1,11 @@
|
||||
from PySide6.QtWidgets import QApplication, QMainWindow, QWidget, QHBoxLayout
|
||||
from PySide6.QtWidgets import QApplication, QMainWindow, QWidget, QHBoxLayout, QVBoxLayout, QPushButton
|
||||
from typing import final
|
||||
import sys
|
||||
|
||||
from Movie import movies
|
||||
from MovieView import MovieView
|
||||
from MovieButton import MovieButton
|
||||
from config import cart
|
||||
from Cart import Cart, cart
|
||||
|
||||
# Main Window
|
||||
@final
|
||||
@@ -19,11 +19,18 @@ class MainWindow(QMainWindow):
|
||||
|
||||
currentMovie: MovieView | None = None
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, cart: Cart):
|
||||
super().__init__()
|
||||
|
||||
self.setWindowTitle("Cinema Tickets")
|
||||
|
||||
# Main layout, contains button and movies
|
||||
mainLayout = QVBoxLayout()
|
||||
|
||||
button = QPushButton("View Cart")
|
||||
button.clicked.connect(lambda: cart.show())
|
||||
mainLayout.addWidget(button)
|
||||
|
||||
# Create the layout for all the movies
|
||||
layout = QHBoxLayout()
|
||||
|
||||
@@ -37,8 +44,10 @@ class MainWindow(QMainWindow):
|
||||
self.hairypotty = MovieButton(movies["hairypotty"], self.buyHairyPotty)
|
||||
layout.addWidget(self.hairypotty)
|
||||
|
||||
mainLayout.addLayout(layout)
|
||||
|
||||
centralWidget = QWidget()
|
||||
centralWidget.setLayout(layout)
|
||||
centralWidget.setLayout(mainLayout)
|
||||
self.setCentralWidget(centralWidget)
|
||||
|
||||
# Callback functions to set the movie
|
||||
@@ -60,7 +69,7 @@ class MainWindow(QMainWindow):
|
||||
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
window = MainWindow()
|
||||
window = MainWindow(cart)
|
||||
window.show()
|
||||
app.exec()
|
||||
print(cart)
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
from Cart import Cart
|
||||
|
||||
cart = Cart()
|
||||
|
||||
Reference in New Issue
Block a user