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