Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development Progress - week 06 #56

Merged
merged 8 commits into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions pyqt5-gui/favourites.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/usr/bin/python3
import math
import sys
import inspect
from collections import deque

# Import PyQt5 Engine
from PyQt5.QtWidgets import (QApplication,
QWidget,
QPushButton,
QGridLayout,
QLabel,
QFrame,
QGroupBox,
QLineEdit,
QMessageBox,
QPlainTextEdit,
QHBoxLayout,
QVBoxLayout,
QGraphicsDropShadowEffect,
QGraphicsOpacityEffect,
)

from PyQt5.QtGui import *
from PyQt5.QtCore import *

sys.path.append(r'.')
sys.path.append(r'..')
from collections import deque
from db_handle import postgres_conn


def favourites_menu():
global products_groupbox

products_groupbox = QGroupBox("Favourites")
products_grid_layout = QGridLayout()

"""ADD CUSTOM FONT TO ARRAY READY TO BE LOADED TO ANY TEXT OBJECT"""
font = QFontDatabase.addApplicationFont(r'../fonts/jetbrains-mono.regular.ttf')
if font < 0:
print('Error loading fonts!')
fonts = QFontDatabase.applicationFontFamilies(font)

postgres_conn.admin_client()

"""INNER JOIN QUERY THAT WILL GIVE US EVERY PRODUCT'S DATA"""
postgres_conn.POSTGRES_CURSOR.execute(f"select products.product_id, favourite_products.username, "
f"products.product_name, products.single_price, products.quantity, "
f"products.product_description, products.subcategory"
f" from products inner join favourite_products on "
f"favourite_products.product_id=products.product_id "
f"where favourite_products.username = 'pesho';")
result = deque(postgres_conn.POSTGRES_CURSOR.fetchall())
print(result)

for row in range(math.ceil(len(result) / 3)):
for col in range(3):
if result:
current_product = result.popleft()
product_id, username, product_name, price, quantity, product_description, subcategory = current_product

current_vertical_layout = QVBoxLayout()

product_image = QLabel()
product_image.setFixedSize(250, 200)
product_image.setPixmap(QPixmap(f"../img/products/{subcategory}/{product_name}.png"))
product_image.setScaledContents(True)

current_title = QLabel()
current_title.setText('Test Title')
current_title.setFont(QFont(fonts[0], 12))

current_sku = QLabel()
current_sku.setText(product_id)
current_sku.setFont(QFont(fonts[0], 10))

current_description = QLabel(product_description)
current_description.setWordWrap(True)
current_description.setFont(QFont(fonts[0], 9))

current_buttons_layout = QHBoxLayout()
current_buttons_layout.setAlignment(Qt.AlignLeft)

current_favorites_button = QPushButton()
current_favorites_button.setFixedWidth(35)
current_favorites_button.setFixedHeight(35)
current_favorites_button.setIcon(QIcon(r'../img/favorite.png'))
current_favorites_button.setIconSize(QSize(30, 30))
current_favorites_button.setFont(QFont(fonts[0], 12))

current_basket_button = QPushButton()
current_basket_button.setFixedWidth(35)
current_basket_button.setFixedHeight(35)
current_basket_button.setIcon(QIcon(r'../img/shoppingcart.png'))
current_basket_button.setIconSize(QSize(30, 30))
current_basket_button.setFont(QFont(fonts[0], 12))

current_buttons_layout.addWidget(current_favorites_button)
current_buttons_layout.addWidget(current_basket_button)

current_vertical_layout.insertWidget(0, product_image)
current_vertical_layout.addWidget(current_title)
current_vertical_layout.addWidget(current_sku)
current_vertical_layout.addWidget(current_description)
current_vertical_layout.addLayout(current_buttons_layout)

current_vertical_layout.addStretch()
current_vertical_layout.addSpacing(10)

products_grid_layout.addLayout(current_vertical_layout, 0, col)

products_groupbox.setLayout(products_grid_layout)

return products_groupbox
12 changes: 10 additions & 2 deletions pyqt5-gui/main_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
sys.path.append(r'..')
from collections import deque
from db_handle import postgres_conn
import about, subcategories, edit_account, payment_options, products
import about, subcategories, edit_account, payment_options, products, favourites

# This global variable should be modified to accept it's value dynamically, based on the cattegory button clicked
global subcategory_name
Expand Down Expand Up @@ -53,6 +53,9 @@ def open_func(curr_subcat_name):
def open_category_func(subcat_name):
return lambda: open_func(subcat_name)

def open_favourites_func():
return lambda: open_favourites()

"""LEFT LAYOUT BUTTONS CALL FUNCTION"""
left_layout_buttons_dict = {
'edit_account': lambda: open_update_account(),
Expand Down Expand Up @@ -113,7 +116,6 @@ def open_category_func(subcat_name):
button.clicked.connect(left_layout_buttons_dict[button_function])
buttons.appendleft(button)


left_buttons_layout.addWidget(button)

left_buttons_layout.addStretch(0)
Expand All @@ -129,6 +131,7 @@ def open_category_func(subcat_name):
favourites_button.setFont(QFont(fonts[0], 9))
favourites_button.setFixedWidth(120)
favourites_button.setFixedHeight(30)
favourites_button.clicked.connect(open_favourites_func())

about_button = QPushButton()
about_button.setText("About")
Expand Down Expand Up @@ -299,6 +302,11 @@ def open_subcategories(sub_cat_name):
subcategories_layout = subcategories.open_subcategory(sub_cat_name)
categories_groupbox.hide()
main_layout.addWidget(subcategories_layout, 1, 1)

def open_favourites():
favourites_layout = favourites.favourites_menu()
categories_groupbox.hide()
main_layout.addWidget(favourites_layout, 1, 1)


"""OBSOLETE - KEEP FOR NOW FOR DEBUGING PURPOSES, BUT MOST PROBEBLY WONT BE NEEDED"""
Expand Down
Empty file added pyqt5-gui/myFile
Empty file.
20 changes: 18 additions & 2 deletions pyqt5-gui/products.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/python3
import sys
import requests
import inspect
from collections import deque

# Import PyQt5 Engine
from PyQt5.QtWidgets import (QApplication,
QWidget,
Expand Down Expand Up @@ -30,6 +32,10 @@
def products_menu(subcategory_name):
global products_groupbox

"""THIS FUNCTION WILL REDIRECT THE CURRENT PROD ID AND PROD NAME TO THE INSERT TO THE POSTGRE DB FUNCTION"""
def redirect_to_insert_to_postgre_func(prod_id, prod_name):
return lambda: insert_into_favourite_products(prod_id, prod_name)

products_groupbox = QGroupBox("Products")
products_grid_layout = QGridLayout()

Expand All @@ -49,11 +55,13 @@ def products_menu(subcategory_name):
products_ids = deque(p[2] for p in result)
print(products_names)


for col in range(3):

current_vertical_layout = QVBoxLayout()

product_name = products_names.popleft()
product_id = products_ids.popleft()

product_image = QLabel()
product_image.setFixedSize(250, 200)
Expand All @@ -65,7 +73,7 @@ def products_menu(subcategory_name):
current_title.setFont(QFont(fonts[0], 12))

current_sku = QLabel()
current_sku.setText(products_ids.popleft())
current_sku.setText(product_id)
current_sku.setFont(QFont(fonts[0], 10))

product_description = products_descriptions.popleft()
Expand All @@ -87,6 +95,7 @@ def products_menu(subcategory_name):
current_favorites_button.setIcon(QIcon(r'../img/favorite.png'))
current_favorites_button.setIconSize(QSize(30, 30))
current_favorites_button.setFont(QFont(fonts[0], 12))
current_favorites_button.clicked.connect(redirect_to_insert_to_postgre_func(product_id, product_name))

current_basket_button = QPushButton()
current_basket_button.setFixedWidth(35)
Expand All @@ -111,4 +120,11 @@ def products_menu(subcategory_name):

products_groupbox.setLayout(products_grid_layout)

def insert_into_favourite_products(curr_id, curr_product_name):
postgres_conn.POSTGRES_CURSOR.execute(f"INSERT INTO favourite_products VALUES "
f"('pesho', '{curr_id}', '{curr_product_name}')")
postgres_conn.POSTGRES_CONNECTION.commit()
print("Done") # this line is only to check if the function is executing


return products_groupbox
2 changes: 1 addition & 1 deletion pyqt5-gui/subcategories.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def open_products(cat):
product_layout = products.products_menu(cat)
main_grid_layout.addWidget(product_layout, 1, 0)
subcategories_groupbox.setLayout(main_grid_layout)
print(5)


return subcategories_groupbox

Expand Down