From d53ead84b6b374150458560abca5edd0210d40fd Mon Sep 17 00:00:00 2001 From: karastoyanov on vivobook Date: Tue, 23 May 2023 23:04:49 +0300 Subject: [PATCH 01/11] Subcatgories branch added --- food_subcategory.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 food_subcategory.py diff --git a/food_subcategory.py b/food_subcategory.py new file mode 100644 index 0000000..e69de29 From c83e7a683aeb9060c745c6d05af0ac6c5d1bca04 Mon Sep 17 00:00:00 2001 From: karastoyanov on vivobook Date: Tue, 23 May 2023 23:05:42 +0300 Subject: [PATCH 02/11] Food Subcategory Added --- food_subcategory.py => pyqt5-gui/food_subcategory.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename food_subcategory.py => pyqt5-gui/food_subcategory.py (100%) diff --git a/food_subcategory.py b/pyqt5-gui/food_subcategory.py similarity index 100% rename from food_subcategory.py rename to pyqt5-gui/food_subcategory.py From 915328f497da1d94ae05cd8be39773f7bcf595a9 Mon Sep 17 00:00:00 2001 From: karastoyanov on vivobook Date: Thu, 25 May 2023 03:59:41 +0300 Subject: [PATCH 03/11] Food Subcategory Menu --- pyqt5-gui/food_subcategory.py | 68 +++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/pyqt5-gui/food_subcategory.py b/pyqt5-gui/food_subcategory.py index e69de29..12599e9 100644 --- a/pyqt5-gui/food_subcategory.py +++ b/pyqt5-gui/food_subcategory.py @@ -0,0 +1,68 @@ +#!/usr/bin/python3 +import sys +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'..') + +class FoodSubCategory(QWidget): + def __init__(self): + super().__init__() + self.setWindowTitle("Food Sub Category") + self.setWindowIcon(QIcon(r'../img/market.png')) + self.setGeometry(200, 150, 1500, 700) + self.setMaximumWidth(1500) + self.setMaximumHeight(700) + + """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) + + """CREATE THE USER INFO VERTICAL LAYOUT""" + user_info_groupbox = QGroupBox('User Information') + user_info_groupbox.setFont(QFont(fonts[0], 12)) + first_name = QLabel('First Name') + first_name.setFont(QFont(fonts[0], 12)) + last_name = QLabel('Last Name') + last_name.setFont(QFont(fonts[0], 12)) + user_info_layout = QVBoxLayout() + + user_info_layout.addWidget(first_name) + user_info_layout.addWidget(last_name) + user_info_layout.addStretch(0) + user_info_layout.addSpacing(100) + user_info_groupbox.setLayout(user_info_layout) + + + """INIT THE MAIN LAYOUT""" + main_layout = QGridLayout() + main_layout.addWidget(user_info_groupbox, 0, 0) + + + """EXAMINE BELOW TWO LINES HOW EXACTLY THEY APPLY THE LOGIC IN THE UI""" + main_layout.setRowStretch(1, 1) + main_layout.setColumnStretch(1, 1) + self.setLayout(main_layout) + self.show() + + +app = QApplication(sys.argv) +global food_subcategory_window +food_subcategory_window = FoodSubCategory() +food_subcategory_window.show() +app.exec() \ No newline at end of file From 3d87f58fcb32e9b41186504261cb81aec1160248 Mon Sep 17 00:00:00 2001 From: karastoyanov on vivobook Date: Fri, 26 May 2023 22:05:40 +0300 Subject: [PATCH 04/11] Food Subcategory Menu Update --- pyqt5-gui/food_subcategory.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 pyqt5-gui/food_subcategory.py diff --git a/pyqt5-gui/food_subcategory.py b/pyqt5-gui/food_subcategory.py old mode 100644 new mode 100755 From c3779eeefdc93e093e9e585edbeb12aa59d12b25 Mon Sep 17 00:00:00 2001 From: karastoyanov on vivobook Date: Fri, 26 May 2023 22:47:13 +0300 Subject: [PATCH 05/11] Food Subcategory moved to experimental folder --- pyqt5-gui/food_subcategory.py | 68 ----------------------------------- 1 file changed, 68 deletions(-) delete mode 100755 pyqt5-gui/food_subcategory.py diff --git a/pyqt5-gui/food_subcategory.py b/pyqt5-gui/food_subcategory.py deleted file mode 100755 index 12599e9..0000000 --- a/pyqt5-gui/food_subcategory.py +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/python3 -import sys -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'..') - -class FoodSubCategory(QWidget): - def __init__(self): - super().__init__() - self.setWindowTitle("Food Sub Category") - self.setWindowIcon(QIcon(r'../img/market.png')) - self.setGeometry(200, 150, 1500, 700) - self.setMaximumWidth(1500) - self.setMaximumHeight(700) - - """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) - - """CREATE THE USER INFO VERTICAL LAYOUT""" - user_info_groupbox = QGroupBox('User Information') - user_info_groupbox.setFont(QFont(fonts[0], 12)) - first_name = QLabel('First Name') - first_name.setFont(QFont(fonts[0], 12)) - last_name = QLabel('Last Name') - last_name.setFont(QFont(fonts[0], 12)) - user_info_layout = QVBoxLayout() - - user_info_layout.addWidget(first_name) - user_info_layout.addWidget(last_name) - user_info_layout.addStretch(0) - user_info_layout.addSpacing(100) - user_info_groupbox.setLayout(user_info_layout) - - - """INIT THE MAIN LAYOUT""" - main_layout = QGridLayout() - main_layout.addWidget(user_info_groupbox, 0, 0) - - - """EXAMINE BELOW TWO LINES HOW EXACTLY THEY APPLY THE LOGIC IN THE UI""" - main_layout.setRowStretch(1, 1) - main_layout.setColumnStretch(1, 1) - self.setLayout(main_layout) - self.show() - - -app = QApplication(sys.argv) -global food_subcategory_window -food_subcategory_window = FoodSubCategory() -food_subcategory_window.show() -app.exec() \ No newline at end of file From 954b773abf0d801cc9cc72eb29d5d035ea540069 Mon Sep 17 00:00:00 2001 From: karastoyanov on vivobook Date: Fri, 26 May 2023 22:47:35 +0300 Subject: [PATCH 06/11] Food Subcategory moved to experimental folder --- experimental/food_subcategory.py | 68 ++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 experimental/food_subcategory.py diff --git a/experimental/food_subcategory.py b/experimental/food_subcategory.py new file mode 100755 index 0000000..12599e9 --- /dev/null +++ b/experimental/food_subcategory.py @@ -0,0 +1,68 @@ +#!/usr/bin/python3 +import sys +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'..') + +class FoodSubCategory(QWidget): + def __init__(self): + super().__init__() + self.setWindowTitle("Food Sub Category") + self.setWindowIcon(QIcon(r'../img/market.png')) + self.setGeometry(200, 150, 1500, 700) + self.setMaximumWidth(1500) + self.setMaximumHeight(700) + + """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) + + """CREATE THE USER INFO VERTICAL LAYOUT""" + user_info_groupbox = QGroupBox('User Information') + user_info_groupbox.setFont(QFont(fonts[0], 12)) + first_name = QLabel('First Name') + first_name.setFont(QFont(fonts[0], 12)) + last_name = QLabel('Last Name') + last_name.setFont(QFont(fonts[0], 12)) + user_info_layout = QVBoxLayout() + + user_info_layout.addWidget(first_name) + user_info_layout.addWidget(last_name) + user_info_layout.addStretch(0) + user_info_layout.addSpacing(100) + user_info_groupbox.setLayout(user_info_layout) + + + """INIT THE MAIN LAYOUT""" + main_layout = QGridLayout() + main_layout.addWidget(user_info_groupbox, 0, 0) + + + """EXAMINE BELOW TWO LINES HOW EXACTLY THEY APPLY THE LOGIC IN THE UI""" + main_layout.setRowStretch(1, 1) + main_layout.setColumnStretch(1, 1) + self.setLayout(main_layout) + self.show() + + +app = QApplication(sys.argv) +global food_subcategory_window +food_subcategory_window = FoodSubCategory() +food_subcategory_window.show() +app.exec() \ No newline at end of file From 7b7f3b3b7d38921d9bb6c0b88d883b3d06cc63a1 Mon Sep 17 00:00:00 2001 From: Raya Petkova <122923696+rayapetkova@users.noreply.github.com> Date: Sat, 27 May 2023 21:42:40 +0300 Subject: [PATCH 07/11] Update names in subcategories - Query needs to be fixed --- pyqt5-gui/main_menu_dev.py | 215 +++++++++++++++++++++++++++++++++++++ pyqt5-gui/subcategories.py | 202 ++++++++++++++++++++++++++++++++++ 2 files changed, 417 insertions(+) create mode 100644 pyqt5-gui/main_menu_dev.py create mode 100644 pyqt5-gui/subcategories.py diff --git a/pyqt5-gui/main_menu_dev.py b/pyqt5-gui/main_menu_dev.py new file mode 100644 index 0000000..2c2c9ab --- /dev/null +++ b/pyqt5-gui/main_menu_dev.py @@ -0,0 +1,215 @@ +#!/usr/bin/python3 +import sys +import requests +# 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'..') +from collections import deque +from db_handle import postgres_conn + + +class MainMenu(QWidget): + def __init__(self): + super().__init__() + self.setWindowTitle("Main Menu") + self.setWindowIcon(QIcon(r'../img/market.png')) + self.setGeometry(200, 150, 1500, 700) + self.setMaximumWidth(1500) + self.setMaximumHeight(700) + + """INIT CONNECTION TO THE DATABASE""" + postgres_conn.admin_client() + + def food_open(): + print("I am eating some food") + + def books_open(): + print("I am reading books") + + def drinks_open(): + print("I am drinking some drinks") + + functions_dict = { + 'food_open': lambda: food_open(), + 'books_open': lambda: books_open(), + 'drinks_open': lambda: drinks_open(), + } + + """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) + + """CREATE THE USER INFO VERTICAL LAYOUT""" + user_info_groupbox = QGroupBox('User Information') + postgres_conn.POSTGRES_CURSOR.execute("SELECT current_user;") + current_user = postgres_conn.POSTGRES_CURSOR.fetchone() + # The query below should be modified once we implement the main_menu window with rest of the application. WHERE username = {current_user} + postgres_conn.POSTGRES_CURSOR.execute( + f"SELECT customer_id, first_name, last_name, total_orders FROM customers WHERE username = 'pesho'") + user_info = postgres_conn.POSTGRES_CURSOR.fetchone() + + user_name = QLabel(f"Hello, {user_info[1]} {user_info[2]}") + user_name.setFont(QFont(fonts[0], 12)) + + user_id = QLabel(f"Your ID is {user_info[0]}") + user_id.setFont(QFont(fonts[0], 12)) + user_info_layout = QVBoxLayout() + + user_total_orders = QLabel(f"Total orders: {user_info[3]}") + user_total_orders.setFont(QFont(fonts[0], 12)) + + user_info_layout.addWidget(user_name) + user_info_layout.addWidget(user_id) + user_info_layout.addWidget(user_total_orders) + user_info_layout.addStretch(0) + user_info_layout.addSpacing(100) + user_info_groupbox.setLayout(user_info_layout) + + """CREATE THE LEFT BUTTONS LAYOUT""" + left_buttons_groupbox = QGroupBox('User Actions') + left_buttons_layout = QVBoxLayout() + + buttons_text = deque(['Edit Account', 'View My Orders', 'Payment Options', 'Fourth', 'Fifth']) + while buttons_text: + button = QPushButton() + button.setText(buttons_text.popleft()) + button.setFont(QFont(fonts[0], 12)) + button.setFixedWidth(250) + button.setFixedHeight(30) + # button.setStyleSheet("background-color: rgb(51, 153, 255)") + left_buttons_layout.addWidget(button) + + left_buttons_layout.addStretch(0) + left_buttons_layout.addSpacing(100) + left_buttons_groupbox.setLayout(left_buttons_layout) + + """CREATE THE TOP LAYOUT""" + top_buttons_groupbox = QGroupBox("Top menu") + top_buttons_layout = QHBoxLayout() + + favourites_button = QPushButton() + favourites_button.setText("Favourites") + favourites_button.setFont(QFont(fonts[0], 9)) + favourites_button.setFixedWidth(120) + favourites_button.setFixedHeight(23) + + log_out_button = QPushButton() + log_out_button.setText("Log Out") + log_out_button.setFont(QFont(fonts[0], 9)) + log_out_button.setFixedWidth(100) + log_out_button.setFixedHeight(23) + + top_buttons_layout.addStretch(0) + top_buttons_layout.addSpacing(1000) + + top_buttons_layout.addWidget(favourites_button) + top_buttons_layout.addWidget(log_out_button) + + top_buttons_groupbox.setLayout(top_buttons_layout) + + """CREATE THE CATEGORIES LAYOUT""" + categories_groupbox = QGroupBox("Categories") + + categories_grid_layout = QGridLayout() + + postgres_conn.POSTGRES_CURSOR.execute( + f"SELECT category_name, category_description, category_function, image_url FROM categories ORDER BY category_name ASC;") + result = postgres_conn.POSTGRES_CURSOR.fetchmany(12) + categories = deque([x[0] for x in result[0:12]]) + categories_description = deque([x[1] for x in result[0:12]]) + categories_functions = deque([x[2] for x in result[0:12]]) + + for row in range(3): + for col in range(4): + if categories: + current_groupbox = QGroupBox() + current_groupbox.setStyleSheet("border: 2px solid red") + current_groupbox.setMaximumWidth(300) + + current_vertical_layout = QVBoxLayout() + + category_name = QLabel(categories.popleft()) + category_name.setFont(QFont(fonts[0], 9)) + cat_name_shadow_effect = QGraphicsDropShadowEffect() + cat_name_shadow_effect.setBlurRadius(2) + cat_name_shadow_effect.setOffset(1, 1) + cat_name_shadow_effect.setColor(QColor("blue")) + category_name.setGraphicsEffect(cat_name_shadow_effect) + category_name.setAlignment(Qt.AlignCenter) + category_name.setStyleSheet("background-color: rgba(255, 255, 255, 255);" \ + "border-radius: 10px;") + + image = f"../img/categories/{category_name.text()}.png" + groupbox_stylesheet = f"QGroupBox {{ background-image: url({image});" \ + f"border-radius: 10px;" \ + f"}}" + current_groupbox.setStyleSheet(groupbox_stylesheet) + + category_description = QLabel("background-color: #FFFAFF;") + category_description.setText(f"{categories_description.popleft()}") + category_description.setFont(QFont(fonts[0], 11)) + category_description.setStyleSheet("color: rgb(0, 0, 0);") + cat_desc_shadow_effect = QGraphicsDropShadowEffect() + cat_desc_shadow_effect.setBlurRadius(2) + cat_desc_shadow_effect.setOffset(2, 1) + cat_desc_shadow_effect.setColor(QColor("white")) + category_description.setGraphicsEffect(cat_desc_shadow_effect) + + category_button = QPushButton() + category_button.setText(category_name.text()) + category_button.setFont(QFont(fonts[0], 11)) + category_button.setMaximumWidth(150) + get_button_name(category_button) + + # current_function_name = categories_functions.popleft() + # print(current_function_name) + # category_button.clicked.connect(functions_dict[current_function_name]) + + # current_vertical_layout.addWidget(category_name) + # current_vertical_layout.addWidget(category_description) + current_vertical_layout.addWidget(category_button) + + current_groupbox.setLayout(current_vertical_layout) + categories_grid_layout.addWidget(current_groupbox, row, col) + + categories_groupbox.setLayout(categories_grid_layout) + + """INIT THE MAIN LAYOUT""" + main_layout = QGridLayout() + main_layout.addWidget(user_info_groupbox, 0, 0) + main_layout.addWidget(left_buttons_groupbox, 1, 0) + main_layout.addWidget(top_buttons_groupbox, 0, 1) + main_layout.addWidget(categories_groupbox, 1, 1) + + """EXAMINE BELOW TWO LINES HOW EXACTLY THEY APPLY THE LOGIC IN THE UI""" + main_layout.setRowStretch(1, 1) + main_layout.setColumnStretch(1, 1) + self.setLayout(main_layout) + self.show() + + +app = QApplication(sys.argv) +global login_window +login_window = MainMenu() +login_window.show() +app.exec() \ No newline at end of file diff --git a/pyqt5-gui/subcategories.py b/pyqt5-gui/subcategories.py new file mode 100644 index 0000000..8f2c2f8 --- /dev/null +++ b/pyqt5-gui/subcategories.py @@ -0,0 +1,202 @@ +#!/usr/bin/python3 +import sys +import requests +# 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'..') +from collections import deque +from db_handle import postgres_conn + +from main_menu_dev import button_text_main_menu + +class SubcategoriesMenu(QWidget): + def __init__(self): + super().__init__() + self.setWindowTitle("Subcategories Menu") + self.setWindowIcon(QIcon(r'../img/market.png')) + self.setGeometry(200, 150, 1500, 700) + self.setMaximumWidth(1500) + self.setMaximumHeight(700) + + """INIT CONNECTION TO THE DATABASE""" + postgres_conn.admin_client() + + def food_open(): + print("I am eating some food") + + def books_open(): + print("I am reading books") + + def drinks_open(): + print("I am drinking some drinks") + + functions_dict = { + 'food_open': lambda: food_open(), + 'books_open': lambda: books_open(), + 'drinks_open': lambda: drinks_open(), + } + + """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) + + """CREATE THE USER INFO VERTICAL LAYOUT""" + user_info_groupbox = QGroupBox('User Information') + postgres_conn.POSTGRES_CURSOR.execute("SELECT current_user;") + current_user = postgres_conn.POSTGRES_CURSOR.fetchone() + # The query below should be modified once we implement the main_menu window with rest of the application. WHERE username = {current_user} + postgres_conn.POSTGRES_CURSOR.execute( + f"SELECT customer_id, first_name, last_name, total_orders FROM customers WHERE username = 'pesho'") + user_info = postgres_conn.POSTGRES_CURSOR.fetchone() + + user_name = QLabel(f"Hello, {user_info[1]} {user_info[2]}") + user_name.setFont(QFont(fonts[0], 12)) + + user_id = QLabel(f"Your ID is {user_info[0]}") + user_id.setFont(QFont(fonts[0], 12)) + user_info_layout = QVBoxLayout() + + user_total_orders = QLabel(f"Total orders: {user_info[3]}") + user_total_orders.setFont(QFont(fonts[0], 12)) + + user_info_layout.addWidget(user_name) + user_info_layout.addWidget(user_id) + user_info_layout.addWidget(user_total_orders) + user_info_layout.addStretch(0) + user_info_layout.addSpacing(100) + user_info_groupbox.setLayout(user_info_layout) + + """CREATE THE LEFT BUTTONS LAYOUT""" + left_buttons_groupbox = QGroupBox('User Actions') + left_buttons_layout = QVBoxLayout() + + buttons_text = deque(['Edit Account', 'View My Orders', 'Payment Options', 'Fourth', 'Fifth']) + while buttons_text: + button = QPushButton() + button.setText(buttons_text.popleft()) + button.setFont(QFont(fonts[0], 12)) + button.setFixedWidth(250) + button.setFixedHeight(30) + # button.setStyleSheet("background-color: rgb(51, 153, 255)") + left_buttons_layout.addWidget(button) + + left_buttons_layout.addStretch(0) + left_buttons_layout.addSpacing(100) + left_buttons_groupbox.setLayout(left_buttons_layout) + + """CREATE THE TOP LAYOUT""" + top_buttons_groupbox = QGroupBox("Top menu") + top_buttons_layout = QHBoxLayout() + + favourites_button = QPushButton() + favourites_button.setText("Favourites") + favourites_button.setFont(QFont(fonts[0], 9)) + favourites_button.setFixedWidth(120) + favourites_button.setFixedHeight(23) + + log_out_button = QPushButton() + log_out_button.setText("Log Out") + log_out_button.setFont(QFont(fonts[0], 9)) + log_out_button.setFixedWidth(100) + log_out_button.setFixedHeight(23) + + top_buttons_layout.addStretch(0) + top_buttons_layout.addSpacing(1000) + + top_buttons_layout.addWidget(favourites_button) + top_buttons_layout.addWidget(log_out_button) + + top_buttons_groupbox.setLayout(top_buttons_layout) + + """CREATE THE CATEGORIES LAYOUT""" + subcategories_groupbox = QGroupBox("Categories") + + subcategories_grid_layout = QGridLayout() + + postgres_conn.POSTGRES_CURSOR.execute( + f"SELECT subcategory_name FROM subcategories where parent_category = {button_text_main_menu} ORDER BY subcategory_name ASC;") + result = postgres_conn.POSTGRES_CURSOR.fetchmany(12) + subcategories = deque([x[0] for x in result[0:12]]) + + for row in range(3): + for col in range(4): + if subcategories: + current_groupbox = QGroupBox() + current_groupbox.setStyleSheet("border: 2px solid red") + current_groupbox.setMaximumWidth(300) + + current_vertical_layout = QVBoxLayout() + + subcategory_name = QLabel(subcategories.popleft()) + subcategory_name.setFont(QFont(fonts[0], 9)) + subcat_name_shadow_effect = QGraphicsDropShadowEffect() + subcat_name_shadow_effect.setBlurRadius(2) + subcat_name_shadow_effect.setOffset(1, 1) + subcat_name_shadow_effect.setColor(QColor("blue")) + subcategory_name.setGraphicsEffect(subcat_name_shadow_effect) + subcategory_name.setAlignment(Qt.AlignCenter) + subcategory_name.setStyleSheet("background-color: rgba(255, 255, 255, 255);" + "border-radius: 10px;") + + # IMPORTANTE !!!!!!!! + # image = f"../img/categories/{category_name.text()}.png" + # groupbox_stylesheet = f"QGroupBox {{ background-image: url({image});" \ + # f"border-radius: 10px;" \ + # f"}}" + # current_groupbox.setStyleSheet(groupbox_stylesheet) + + subcategory_button = QPushButton() + subcategory_button.setText(subcategory_name.text()) + subcategory_button.setFont(QFont(fonts[0], 11)) + subcategory_button.setMaximumWidth(150) + + # current_function_name = categories_functions.popleft() + # print(current_function_name) + # category_button.clicked.connect(functions_dict[current_function_name]) + + current_vertical_layout.addWidget(subcategory_button) + + current_groupbox.setLayout(current_vertical_layout) + subcategories_grid_layout.addWidget(current_groupbox, row, col) + + subcategories_groupbox.setLayout(subcategories_grid_layout) + + """INIT THE MAIN LAYOUT""" + main_layout = QGridLayout() + main_layout.addWidget(user_info_groupbox, 0, 0) + main_layout.addWidget(left_buttons_groupbox, 1, 0) + main_layout.addWidget(top_buttons_groupbox, 0, 1) + main_layout.addWidget(subcategories_groupbox, 1, 1) + + """EXAMINE BELOW TWO LINES HOW EXACTLY THEY APPLY THE LOGIC IN THE UI""" + main_layout.setRowStretch(1, 1) + main_layout.setColumnStretch(1, 1) + self.setLayout(main_layout) + self.show() + + +app = QApplication(sys.argv) +global subcategories_window +subcategories_window = SubcategoriesMenu() +subcategories_window.show() +app.exec() From d96042ab8e73c434b71ebb17743fa358b2da19bb Mon Sep 17 00:00:00 2001 From: karastoyanov on vivobook Date: Sat, 27 May 2023 22:49:45 +0300 Subject: [PATCH 08/11] Subcategories Menu Update --- pyqt5-gui/main_menu_dev.py | 69 +++++++++++++++++++++++++++++++++----- pyqt5-gui/subcategories.py | 37 +++++++++++++------- 2 files changed, 84 insertions(+), 22 deletions(-) mode change 100644 => 100755 pyqt5-gui/main_menu_dev.py mode change 100644 => 100755 pyqt5-gui/subcategories.py diff --git a/pyqt5-gui/main_menu_dev.py b/pyqt5-gui/main_menu_dev.py old mode 100644 new mode 100755 index 2c2c9ab..432161b --- a/pyqt5-gui/main_menu_dev.py +++ b/pyqt5-gui/main_menu_dev.py @@ -21,10 +21,14 @@ 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 +import subcategories +# This global variable should be modified to accept it's value dynamically, based on the cattegory button clicked +SUBCATEGORY_NAME = 'Accessories' class MainMenu(QWidget): def __init__(self): @@ -46,11 +50,50 @@ def books_open(): def drinks_open(): print("I am drinking some drinks") + + def accessories_open(): + print("Accessories") + global SUBCATEGORY_NAME + SUBCATEGORY_NAME = 'Accessories' + open_subcategories() + + def homeandliving_open(): + print("Home and Living") + + def hair_open(): + print("Hair") + + def sports_open(): + print("Sports") + + def beachwear_open(): + print("Beachwear") + + def shoes_open(): + print("Shoes") + + def electronics_open(): + print("Electronics") + + def cosmetics_open(): + print("Cosmetics") + + def clothes_open(): + print("Clothes") functions_dict = { 'food_open': lambda: food_open(), 'books_open': lambda: books_open(), 'drinks_open': lambda: drinks_open(), + 'accessories_open': lambda: accessories_open(), + 'homeandliving_open': lambda: homeandliving_open(), + 'hair_open': lambda: hair_open(), + 'sports_open': lambda: sports_open(), + 'beachwear_open': lambda: beachwear_open(), + 'shoes_open': lambda: shoes_open(), + 'electronics_open': lambda: electronics_open(), + 'cosmetics_open': lambda: cosmetics_open(), + 'clothes_open': lambda: clothes_open(), } """ADD CUSTOM FONT TO ARRAY READY TO BE LOADED TO ANY TEXT OBJECT""" @@ -179,11 +222,11 @@ def drinks_open(): category_button.setText(category_name.text()) category_button.setFont(QFont(fonts[0], 11)) category_button.setMaximumWidth(150) - get_button_name(category_button) + # get_button_name(category_button) - # current_function_name = categories_functions.popleft() - # print(current_function_name) - # category_button.clicked.connect(functions_dict[current_function_name]) + current_function_name = categories_functions.popleft() + "_open" + print(current_function_name) + category_button.clicked.connect(functions_dict[current_function_name]) # current_vertical_layout.addWidget(category_name) # current_vertical_layout.addWidget(category_description) @@ -206,10 +249,18 @@ def drinks_open(): main_layout.setColumnStretch(1, 1) self.setLayout(main_layout) self.show() + + def open_subcategories(): + subcategories.start_window() + main_window.hide() +def open_app(): + app = QApplication(sys.argv) + global main_window + main_window = MainMenu() + main_window.show() + app.exec() -app = QApplication(sys.argv) -global login_window -login_window = MainMenu() -login_window.show() -app.exec() \ No newline at end of file + +if __name__ == '__main__': + open_app() \ No newline at end of file diff --git a/pyqt5-gui/subcategories.py b/pyqt5-gui/subcategories.py old mode 100644 new mode 100755 index 8f2c2f8..e8f8975 --- a/pyqt5-gui/subcategories.py +++ b/pyqt5-gui/subcategories.py @@ -21,11 +21,13 @@ 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 +from main_menu_dev import SUBCATEGORY_NAME -from main_menu_dev import button_text_main_menu +# from main_menu_dev import button_text_main_menu class SubcategoriesMenu(QWidget): def __init__(self): @@ -133,10 +135,10 @@ def drinks_open(): subcategories_grid_layout = QGridLayout() - postgres_conn.POSTGRES_CURSOR.execute( - f"SELECT subcategory_name FROM subcategories where parent_category = {button_text_main_menu} ORDER BY subcategory_name ASC;") - result = postgres_conn.POSTGRES_CURSOR.fetchmany(12) - subcategories = deque([x[0] for x in result[0:12]]) + postgres_conn.POSTGRES_CURSOR.execute(f"SELECT subcategory_name FROM subcategories where parent_category = '{SUBCATEGORY_NAME}' ORDER BY subcategory_name ASC;") + result = postgres_conn.POSTGRES_CURSOR.fetchall() + subcategories = deque([x[0] for x in result]) + print(subcategories) for row in range(3): for col in range(4): @@ -147,7 +149,7 @@ def drinks_open(): current_vertical_layout = QVBoxLayout() - subcategory_name = QLabel(subcategories.popleft()) + subcategory_name = QLabel(f"{subcategories.popleft()}") subcategory_name.setFont(QFont(fonts[0], 9)) subcat_name_shadow_effect = QGraphicsDropShadowEffect() subcat_name_shadow_effect.setBlurRadius(2) @@ -193,10 +195,19 @@ def drinks_open(): main_layout.setColumnStretch(1, 1) self.setLayout(main_layout) self.show() - - -app = QApplication(sys.argv) -global subcategories_window -subcategories_window = SubcategoriesMenu() -subcategories_window.show() -app.exec() + + + + +def start_subcategories(): + app = QApplication(sys.argv) + global subcategories_window + subcategories_window = SubcategoriesMenu() + subcategories_window.show() + app.exec() + +def start_window(): + global subcategories_window + subcategories_window = SubcategoriesMenu() + subcategories_window.show() + \ No newline at end of file From df5a25c257f21f01814772578f63e9fa6089941c Mon Sep 17 00:00:00 2001 From: karastoyanov on vivobook Date: Sun, 28 May 2023 22:28:40 +0300 Subject: [PATCH 09/11] Categories-Subcategories relationship fixed --- pyqt5-gui/main_menu_dev.py | 18 ++++++++++++------ pyqt5-gui/subcategories.py | 19 ++++++++++++------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/pyqt5-gui/main_menu_dev.py b/pyqt5-gui/main_menu_dev.py index 432161b..2fd6a7d 100755 --- a/pyqt5-gui/main_menu_dev.py +++ b/pyqt5-gui/main_menu_dev.py @@ -28,9 +28,10 @@ import subcategories # This global variable should be modified to accept it's value dynamically, based on the cattegory button clicked -SUBCATEGORY_NAME = 'Accessories' +global subcategory_name +subcategory_name = '' -class MainMenu(QWidget): +class MainMenu(QWidget): def __init__(self): super().__init__() self.setWindowTitle("Main Menu") @@ -38,12 +39,17 @@ def __init__(self): self.setGeometry(200, 150, 1500, 700) self.setMaximumWidth(1500) self.setMaximumHeight(700) + + """INIT CONNECTION TO THE DATABASE""" postgres_conn.admin_client() def food_open(): print("I am eating some food") + global subcategory_name + subcategory_name = "Food" + open_subcategories() def books_open(): print("I am reading books") @@ -52,9 +58,9 @@ def drinks_open(): print("I am drinking some drinks") def accessories_open(): - print("Accessories") - global SUBCATEGORY_NAME - SUBCATEGORY_NAME = 'Accessories' + print("I will open Accessories") + global subcategory_name + subcategory_name = 'Accessories' open_subcategories() def homeandliving_open(): @@ -251,7 +257,7 @@ def clothes_open(): self.show() def open_subcategories(): - subcategories.start_window() + subcategories.start_window(subcategory_name) main_window.hide() def open_app(): diff --git a/pyqt5-gui/subcategories.py b/pyqt5-gui/subcategories.py index e8f8975..b723ccb 100755 --- a/pyqt5-gui/subcategories.py +++ b/pyqt5-gui/subcategories.py @@ -25,9 +25,11 @@ sys.path.append(r'..') from collections import deque from db_handle import postgres_conn -from main_menu_dev import SUBCATEGORY_NAME +# from main_menu_dev import subcategory_name + +# global subcategory_name +subcategory_name = '' -# from main_menu_dev import button_text_main_menu class SubcategoriesMenu(QWidget): def __init__(self): @@ -135,7 +137,8 @@ def drinks_open(): subcategories_grid_layout = QGridLayout() - postgres_conn.POSTGRES_CURSOR.execute(f"SELECT subcategory_name FROM subcategories where parent_category = '{SUBCATEGORY_NAME}' ORDER BY subcategory_name ASC;") + global subcategory_name + postgres_conn.POSTGRES_CURSOR.execute(f"SELECT subcategory_name FROM subcategories where parent_category = '{subcategory_name}' ORDER BY subcategory_name ASC;") result = postgres_conn.POSTGRES_CURSOR.fetchall() subcategories = deque([x[0] for x in result]) print(subcategories) @@ -144,7 +147,7 @@ def drinks_open(): for col in range(4): if subcategories: current_groupbox = QGroupBox() - current_groupbox.setStyleSheet("border: 2px solid red") + # current_groupbox.setStyleSheet("border: 2px solid red") current_groupbox.setMaximumWidth(300) current_vertical_layout = QVBoxLayout() @@ -171,6 +174,7 @@ def drinks_open(): subcategory_button.setText(subcategory_name.text()) subcategory_button.setFont(QFont(fonts[0], 11)) subcategory_button.setMaximumWidth(150) + subcategory_button.setStyleSheet("background-color: rgba(255, 255, 0)") # current_function_name = categories_functions.popleft() # print(current_function_name) @@ -195,9 +199,8 @@ def drinks_open(): main_layout.setColumnStretch(1, 1) self.setLayout(main_layout) self.show() - - + def start_subcategories(): app = QApplication(sys.argv) @@ -206,8 +209,10 @@ def start_subcategories(): subcategories_window.show() app.exec() -def start_window(): +def start_window(sub_cat_name): global subcategories_window + global subcategory_name + subcategory_name = sub_cat_name subcategories_window = SubcategoriesMenu() subcategories_window.show() \ No newline at end of file From 60178c31e07371b0f5763574eaabd6ff670bc45b Mon Sep 17 00:00:00 2001 From: karastoyanov on vivobook Date: Sun, 28 May 2023 22:37:18 +0300 Subject: [PATCH 10/11] subcategories/main_menu relationship fixed --- pyqt5-gui/main_menu_dev.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyqt5-gui/main_menu_dev.py b/pyqt5-gui/main_menu_dev.py index 2fd6a7d..cf5f625 100755 --- a/pyqt5-gui/main_menu_dev.py +++ b/pyqt5-gui/main_menu_dev.py @@ -192,7 +192,7 @@ def clothes_open(): for col in range(4): if categories: current_groupbox = QGroupBox() - current_groupbox.setStyleSheet("border: 2px solid red") + # current_groupbox.setStyleSheet("border: 2px solid red") current_groupbox.setMaximumWidth(300) current_vertical_layout = QVBoxLayout() From bce9c03a7fe0314b4a22206fa54b5aed4dca50c7 Mon Sep 17 00:00:00 2001 From: karastoyanov on vivobook Date: Sun, 28 May 2023 23:13:38 +0300 Subject: [PATCH 11/11] Minor subcategories changes --- pyqt5-gui/subcategories.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyqt5-gui/subcategories.py b/pyqt5-gui/subcategories.py index b723ccb..19166c9 100755 --- a/pyqt5-gui/subcategories.py +++ b/pyqt5-gui/subcategories.py @@ -147,8 +147,8 @@ def drinks_open(): for col in range(4): if subcategories: current_groupbox = QGroupBox() - # current_groupbox.setStyleSheet("border: 2px solid red") - current_groupbox.setMaximumWidth(300) + current_groupbox.setMaximumWidth(400) + current_groupbox.setMaximumHeight(150) current_vertical_layout = QVBoxLayout() @@ -174,7 +174,7 @@ def drinks_open(): subcategory_button.setText(subcategory_name.text()) subcategory_button.setFont(QFont(fonts[0], 11)) subcategory_button.setMaximumWidth(150) - subcategory_button.setStyleSheet("background-color: rgba(255, 255, 0)") + # subcategory_button.setStyleSheet("background-color: rgba(255, 255, 0)") # current_function_name = categories_functions.popleft() # print(current_function_name)