diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..197837b --- /dev/null +++ b/.gitignore @@ -0,0 +1,143 @@ +### Python template +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# JetBrains idea folder +.idea + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/Pattern Builder.iml b/.idea/Pattern Builder.iml deleted file mode 100644 index 9a323b0..0000000 --- a/.idea/Pattern Builder.iml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 1c3e090..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index dc9ea49..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index ca68723..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/sonarlint/issuestore/1/e/1ed903fc02ba93edd480826414f531add48b5bbd b/.idea/sonarlint/issuestore/1/e/1ed903fc02ba93edd480826414f531add48b5bbd deleted file mode 100644 index e69de29..0000000 diff --git a/.idea/sonarlint/issuestore/5/0/502167feb8191c9abdaf85957a184430bf7dcb7d b/.idea/sonarlint/issuestore/5/0/502167feb8191c9abdaf85957a184430bf7dcb7d deleted file mode 100644 index e69de29..0000000 diff --git a/.idea/sonarlint/issuestore/9/0/90479d8bc9f8dfa7116261e4ed6ed71a98437648 b/.idea/sonarlint/issuestore/9/0/90479d8bc9f8dfa7116261e4ed6ed71a98437648 deleted file mode 100644 index e69de29..0000000 diff --git a/.idea/sonarlint/issuestore/index.pb b/.idea/sonarlint/issuestore/index.pb deleted file mode 100644 index f8113b9..0000000 --- a/.idea/sonarlint/issuestore/index.pb +++ /dev/null @@ -1,8 +0,0 @@ - -T -$src/app/ui/MainWindow/main_window.ui,1\e\1ed903fc02ba93edd480826414f531add48b5bbd -Y -)src/app/ui/TableView/table_widget_form.ui,5\0\502167feb8191c9abdaf85957a184430bf7dcb7d -: - -test.ipynb,9\0\90479d8bc9f8dfa7116261e4ed6ed71a98437648 \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/app/Main.py b/Main.py similarity index 51% rename from src/app/Main.py rename to Main.py index 88f193d..4434ff8 100644 --- a/src/app/Main.py +++ b/Main.py @@ -1,20 +1,17 @@ # This script is the main function of this application. +import sys + +from PyQt5 import QtWidgets +from src.app.ui.MainWindow.UiMainWindow import UiMainWindow def main(): - print("Main function launched!") - """ - src = QtWidgets.QApplication(sys.argv) - # create window + app = QtWidgets.QApplication(sys.argv) window = QtWidgets.QMainWindow() - ui = UiMainWindow(window) - # fill window - # ui.setupUi(window) - window.show() - sys.exit(src.exec_()) - """ + sys.exit(app.exec_()) + if __name__ == '__main__': main() diff --git a/Old app/Pattern_Builder_v1.2.py b/Old app/Pattern_Builder_v1.2.py deleted file mode 100644 index 5c777b5..0000000 --- a/Old app/Pattern_Builder_v1.2.py +++ /dev/null @@ -1,297 +0,0 @@ -# -*- coding: utf-8 -*- - -# This program was meant to return a matrix from your chosen custom pattern - -from PyQt5 import QtCore, QtGui, QtWidgets - - -class Ui_MainWindow(object): - def setupUi(self, MainWindow): - MainWindow.setObjectName("MainWindow") - MainWindow.resize(480, 640) - self.centralwidget = QtWidgets.QWidget(MainWindow) - self.centralwidget.setObjectName("centralwidget") - self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget) - self.verticalLayout.setObjectName("verticalLayout") - self.stackedWidget = QtWidgets.QStackedWidget(self.centralwidget) - self.stackedWidget.setObjectName("stackedWidget") - -############################################################################## -#PAGE 1 - - self.page_1 = QtWidgets.QWidget() - self.page_1.setObjectName("page_1") - - # message "Set your matrix size" - self.sizeMessageLabel = QtWidgets.QLabel(self.page_1) - self.sizeMessageLabel.setGeometry(QtCore.QRect(10, 30, 151, 31)) - font = QtGui.QFont() - font.setPointSize(12) - self.sizeMessageLabel.setFont(font) - self.sizeMessageLabel.setObjectName("sizeMessageLabel") - - # spin box for the x size of the matrix - self.spinBox_x = QtWidgets.QSpinBox(self.page_1) - self.spinBox_x.setGeometry(QtCore.QRect(90, 180, 111, 51)) - font = QtGui.QFont() - font.setPointSize(36) - self.spinBox_x.setFont(font) - self.spinBox_x.setAlignment(QtCore.Qt.AlignCenter) - self.spinBox_x.setMaximum(40) - self.spinBox_x.setProperty("value", 0) - self.spinBox_x.setObjectName("spinBox_x") - - # label for x spin box - self.widthLabel = QtWidgets.QLabel(self.page_1) - self.widthLabel.setGeometry(QtCore.QRect(100, 240, 91, 31)) - self.widthLabel.setObjectName("widthLabel") - - # spin box for the y size of the matrix - self.spinBox_y = QtWidgets.QSpinBox(self.page_1) - self.spinBox_y.setGeometry(QtCore.QRect(250, 180, 111, 51)) - font = QtGui.QFont() - font.setPointSize(36) - self.spinBox_y.setFont(font) - self.spinBox_y.setAlignment(QtCore.Qt.AlignCenter) - self.spinBox_y.setMaximum(40) - self.spinBox_y.setProperty("value", 0) - self.spinBox_y.setObjectName("spinBox_y") - - # label for y spin box - self.heightLabel = QtWidgets.QLabel(self.page_1) - self.heightLabel.setGeometry(QtCore.QRect(270, 240, 91, 31)) - self.heightLabel.setObjectName("heightLabel") - - # line on the first page - self.lineSizePage = QtWidgets.QFrame(self.page_1) - self.lineSizePage.setGeometry(QtCore.QRect(10, 540, 441, 20)) - self.lineSizePage.setFrameShape(QtWidgets.QFrame.HLine) - self.lineSizePage.setFrameShadow(QtWidgets.QFrame.Sunken) - self.lineSizePage.setObjectName("lineSizePage") - - # horizontal layout for the ok button - self.horizontalLayoutWidget_1 = QtWidgets.QWidget(self.page_1) - self.horizontalLayoutWidget_1.setGeometry(QtCore.QRect(350, 560, 101, 51)) - self.horizontalLayoutWidget_1.setObjectName("horizontalLayoutWidget_1") - - self.hLayout_1 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_1) - self.hLayout_1.setContentsMargins(0, 0, 0, 0) - self.hLayout_1.setObjectName("hLayout_1") - - # creating the ok button - self.okButton_1 = QtWidgets.QPushButton(self.horizontalLayoutWidget_1) - self.okButton_1.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) - self.okButton_1.setDefault(True) - self.okButton_1.setObjectName("okButton_1") - - - self.hLayout_1.addWidget(self.okButton_1) - - # label in between the spin box - self.xLabel = QtWidgets.QLabel(self.page_1) - self.xLabel.setGeometry(QtCore.QRect(210, 180, 31, 51)) - self.xLabel.setBaseSize(QtCore.QSize(0, 0)) - font = QtGui.QFont() - font.setPointSize(28) - self.xLabel.setFont(font) - self.xLabel.setLayoutDirection(QtCore.Qt.LeftToRight) - self.xLabel.setAlignment(QtCore.Qt.AlignCenter) - self.xLabel.setObjectName("xLabel") - - self.stackedWidget.addWidget(self.page_1) - -############################################################################## - -#PAGE 2 - - self.page_2 = QtWidgets.QWidget() - self.page_2.setObjectName("page_2") - - # travel to second page - self.okButton_1.clicked.connect(lambda: self.stackedWidget.setCurrentWidget(self.page_2)) - - - # message "Set your matrix pattern :" - self.patternMessageLabel = QtWidgets.QLabel(self.page_2) - self.patternMessageLabel.setGeometry(QtCore.QRect(10, 30, 181, 31)) - font = QtGui.QFont() - font.setPointSize(12) - self.patternMessageLabel.setFont(font) - self.patternMessageLabel.setObjectName("patternMessageLabel") - - - - # grid layout for the matrix button - self.gridLayoutWidget = QtWidgets.QWidget(self.page_2) - self.gridLayoutWidget.setGeometry(QtCore.QRect(-40, 0, 550, 550)) - sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) - sizePolicy.setHorizontalStretch(0) - sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.gridLayoutWidget.sizePolicy().hasHeightForWidth()) - self.gridLayoutWidget.setSizePolicy(sizePolicy) - self.gridLayoutWidget.setObjectName("gridLayoutWidget") - - self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget) - self.gridLayout.setSizeConstraint(QtWidgets.QLayout.SetNoConstraint) - self.gridLayout.setContentsMargins(75, 75, 75, 75) - self.gridLayout.setSpacing(0) - self.gridLayout.setObjectName("gridLayout") - - # ok button for matrix function - self.okButton_1.clicked.connect(self.matrix) - - - # horizontal layout for back and ok buttons - self.horizontalLayoutWidget_2 = QtWidgets.QWidget(self.page_2) - self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(240, 560, 211, 51)) - self.horizontalLayoutWidget_2.setObjectName("horizontalLayoutWidget_2") - - self.hLayout_2 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_2) - self.hLayout_2.setContentsMargins(0, 0, 0, 0) - self.hLayout_2.setObjectName("hLayout_2") - - # creating and setting back button - self.backButton_2 = QtWidgets.QPushButton(self.horizontalLayoutWidget_2) - self.backButton_2.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) - self.backButton_2.setAutoDefault(False) - self.backButton_2.setDefault(False) - self.backButton_2.setFlat(False) - self.backButton_2.setObjectName("backButton_2") - self.hLayout_2.addWidget(self.backButton_2) - self.backButton_2.clicked.connect(lambda: self.stackedWidget.setCurrentWidget(self.page_1)) - self.backButton_2.clicked.connect(self.deleteGrid) - - # creating and setting final ok button - self.okButton_2 = QtWidgets.QPushButton(self.horizontalLayoutWidget_2) - self.okButton_2.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) - self.okButton_2.setDefault(True) - self.okButton_2.setObjectName("okButton_2") - self.okButton_2.clicked.connect(self.finalMatrix) - self.hLayout_2.addWidget(self.okButton_2) - - - # line on the second page - self.linePatternPage = QtWidgets.QFrame(self.page_2) - self.linePatternPage.setGeometry(QtCore.QRect(10, 540, 441, 20)) - self.linePatternPage.setFrameShape(QtWidgets.QFrame.HLine) - self.linePatternPage.setFrameShadow(QtWidgets.QFrame.Sunken) - self.linePatternPage.setObjectName("linePatternPage") - - self.stackedWidget.addWidget(self.page_2) - -############################################################################## - - self.verticalLayout.addWidget(self.stackedWidget) - MainWindow.setCentralWidget(self.centralwidget) - - self.retranslateUi(MainWindow) - self.stackedWidget.setCurrentIndex(0) - QtCore.QMetaObject.connectSlotsByName(MainWindow) - - - def matrix(self): - """ - Generate a matrix - - """ - print("Matrix loading...") - x = self.spinBox_x.value() - y = self.spinBox_y.value() - for i in range(int(x)): - for j in range(int(y)): - self.button = QtWidgets.QPushButton(self.gridLayoutWidget) - sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred) - sizePolicy.setHeightForWidth(self.button.sizePolicy().hasHeightForWidth()) - self.button.setSizePolicy(sizePolicy) - self.button.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) - self.button.setObjectName("button") - self.button.setText("0") - self.button.setStyleSheet("background-color : red") - self.button.clicked.connect(self.clicked) - self.button.setObjectName("button{}{}".format(i, j)) - self.gridLayout.addWidget(self.button, i, j) - - - def deleteGrid(self): - """ - Delete the matrix grid - - """ - x = self.spinBox_x.value() - y = self.spinBox_y.value() - for i in range(int(x)): - for j in range(int(y)): - removeButton = MainWindow.findChild(QtWidgets.QPushButton, "button{}{}".format(i, j)) - removeButton.deleteLater() - - - def clicked(QMainWindow): - """ - Change button color and ID when pressed - - Returns - ------- - bool - True when button is red and turned to blue. - False when button is blue and turned to red. - - """ - button = MainWindow.sender() - namebp = button.objectName() - print("{} pressed".format(namebp)) - if button.text()=="0": - button.setText("1") - button.setStyleSheet("background-color : blue") - return True - else : - button.setText("0") - button.setStyleSheet("background-color : red") - return False - - - def finalMatrix(self): - """ - Matrix returned to python console - - Returns - ------- - matrix : list of list (array) - - """ - matrix = [] - line = [] - x = self.spinBox_x.value() - y = self.spinBox_y.value() - for i in range(x): - matrix.append([]) - line = [] - for j in range(int(y)): - button = MainWindow.findChild(QtWidgets.QPushButton, "button{}{}".format(i, j)) - line.append(int(button.text())) - matrix[i] = line - print(matrix) - return matrix - - - # method naming the elements - def retranslateUi(self, MainWindow): - _translate = QtCore.QCoreApplication.translate - MainWindow.setWindowTitle(_translate("MainWindow", "Pattern Builder")) - self.sizeMessageLabel.setText(_translate("MainWindow", "Set your matrix size :")) - self.widthLabel.setText(_translate("MainWindow", "Size x (horizontal)")) - self.heightLabel.setText(_translate("MainWindow", "Size y (vertical)")) - self.okButton_1.setText(_translate("MainWindow", "Ok")) - self.xLabel.setText(_translate("MainWindow", "X")) - self.patternMessageLabel.setText(_translate("MainWindow", "Set your matrix pattern :")) - self.backButton_2.setText(_translate("MainWindow", "Back")) - self.okButton_2.setText(_translate("MainWindow", "Ok")) - - -if __name__ == "__main__": - import sys - app = QtWidgets.QApplication(sys.argv) - MainWindow = QtWidgets.QMainWindow() - ui = Ui_MainWindow() - ui.setupUi(MainWindow) - MainWindow.show() - sys.exit(app.exec_()) diff --git a/README.MD b/README.MD index e69de29..91176ef 100644 --- a/README.MD +++ b/README.MD @@ -0,0 +1,29 @@ +# Pattern Builder by greg-ynx +Pattern Builder is a tool that graphically constructs matrix. + +## How to use Pattern Builder ? + +![Pattern Builder UI](readme/pbui.png) + +### Sizes +Select the size of your matrix with the width and eight select components. +- Width : Number of columns (max = 16). +- Eight : Number of rows (max = 16). + +### Colors +You can add up to 16 colors to your pattern. Then select your color with the select component. + +### Reset pattern +Click on the "Reset pattern" button in order to get back to the initial pattern. + +### Export +You can export your pattern into an array. +Pattern Builder currently supports : +- Text file (.txt) +- JSON file (.json) +- CSV file (.csv) +- Tabler file (.xlsx) + +## Credits +This application is built with Python programming language and QtDesigner software. +Dependencies used are PyQt5 and XlsxWriter. \ No newline at end of file diff --git a/Requirements.txt b/Requirements.txt deleted file mode 100644 index 54a5bed..0000000 --- a/Requirements.txt +++ /dev/null @@ -1,12 +0,0 @@ -This application will build a matrix of (n,m)-size with k-colors. -First we need to input our columns and rows range with number boxes. The matrix should generate on change! -There is another window with the list of usable colors, you can add color to the list with the default palette or -with a custom color that you have picked (Hexadecimal and RGB code could be used). -Then you just have to click on a color in the list and click on the matrix in order to build your pattern. - -This application can export your pattern as a : -Python Matrix in .txt, .json file or even an image (.jpg, .jpeg, .png, .svg, .pdf) -Tabler (.csv, .xls, .xlsx) -Pattern image (.jpg, .jpeg, .png with white background, .png w/out background, .svg, .pdf) - -PyQt5~=5.15.6 \ No newline at end of file diff --git a/config/definitions.py b/config/definitions.py new file mode 100644 index 0000000..fbe2a0a --- /dev/null +++ b/config/definitions.py @@ -0,0 +1,17 @@ +import os +import ctypes.wintypes + + +ROOT_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), '..')) +src_dir = os.path.join(ROOT_DIR, 'src') +app_dir = os.path.join(src_dir, 'app') +main_path = os.path.join(app_dir, 'ui', 'Main.py') +assets_dir = os.path.join(src_dir, 'assets') +img_dir = os.path.join(assets_dir, 'img') +txt_dir = os.path.join(assets_dir, 'txt') + +CSIDL_PERSONAL = 5 +SHGFP_TYPE_CURRENT = 0 +doc_array = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH) +ctypes.windll.shell32.SHGetFolderPathW(None, CSIDL_PERSONAL, None, SHGFP_TYPE_CURRENT, doc_array) +doc_dir = doc_array.value diff --git a/readme/pbui.png b/readme/pbui.png new file mode 100644 index 0000000..77f913d Binary files /dev/null and b/readme/pbui.png differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..de45104 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +PyQt5~=5.15.6 +XlsxWriter~=3.0.3 \ No newline at end of file diff --git a/src/app/exceptions/CustomException.py b/src/app/exceptions/CustomException.py index 4f1efd6..06177b6 100644 --- a/src/app/exceptions/CustomException.py +++ b/src/app/exceptions/CustomException.py @@ -23,3 +23,9 @@ class TableMaxItemError(CustomException): """ Exception raised when add attempt is made to fully load table. """ + + +class UnknownExtensionError(CustomException): + """ + Exception raised when a not valid extension is chosen. + """ diff --git a/src/app/exceptions/__pycache__/CustomException.cpython-310.pyc b/src/app/exceptions/__pycache__/CustomException.cpython-310.pyc deleted file mode 100644 index be9c2cc..0000000 Binary files a/src/app/exceptions/__pycache__/CustomException.cpython-310.pyc and /dev/null differ diff --git a/src/app/scripts/FileExport.py b/src/app/scripts/FileExport.py index e69de29..7595773 100644 --- a/src/app/scripts/FileExport.py +++ b/src/app/scripts/FileExport.py @@ -0,0 +1,58 @@ +import json +import xlsxwriter + + +def export_to_txt(matrix: list, path: str): + if path[-4:] != '.txt': + with open(path + '.txt', 'w', encoding='utf-8') as ef: + ef.write(str(matrix)) + else: + with open(path, 'w', encoding='utf-8') as ef: + ef.write(str(matrix)) + + +def export_to_json(matrix: list, path: str): + json_matrix = { + 'matrix': matrix + } + if path[-5:] != '.json': + with open(path + '.json', 'w', encoding='utf-8') as ef: + json.dump(json_matrix, ef) + else: + with open(path, 'w', encoding='utf-8') as ef: + json.dump(json_matrix, ef) + + +def format_csv(matrix: list, file): + for row in range(len(matrix)): + if row < 1: + file.write('col{}'.format(row)) + else: + file.write(',col{}'.format(row)) + for row, data in enumerate(matrix): + file.write('\n') + for i in range(len(data)): + if i < 1: + file.write(str(data[i])) + else: + file.write(',' + str(data[i])) + + +def export_to_csv(matrix: list, path: str): + if path[-4:] != '.csv': + with open(path + '.csv', 'w', encoding='utf-8') as ef: + format_csv(matrix, ef) + else: + with open(path, 'w', encoding='utf-8') as ef: + format_csv(matrix, ef) + + +def export_to_xlsx(matrix: list, path: str): + if path[-5:] != '.xlsx': + wb = xlsxwriter.Workbook(path + '.xlsx') + else: + wb = xlsxwriter.Workbook(path) + ws = wb.add_worksheet() + for row, data in enumerate(matrix): + ws.write_row(row, 0, data) + wb.close() diff --git a/src/app/ui/AboutForm/AboutForm.ui b/src/app/ui/AboutForm/AboutForm.ui deleted file mode 100644 index 26444d3..0000000 --- a/src/app/ui/AboutForm/AboutForm.ui +++ /dev/null @@ -1,84 +0,0 @@ - - - About_Form - - - - 0 - 0 - 650 - 600 - - - - - 0 - 0 - - - - - 650 - 600 - - - - - 650 - 600 - - - - About... - - - - ../../../assets/img/lyl8Lynx_logo.png../../../assets/img/lyl8Lynx_logo.png - - - - - - - - true - - - Qt::NoFocus - - - true - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Close - - - - - - - - - - diff --git a/src/app/ui/AboutForm/UiAboutForm.py b/src/app/ui/AboutForm/UiAboutForm.py index 36c4b1d..4c213ed 100644 --- a/src/app/ui/AboutForm/UiAboutForm.py +++ b/src/app/ui/AboutForm/UiAboutForm.py @@ -6,7 +6,8 @@ # # WARNING: Any manual changes made to this file will be lost when pyuic5 is # run again. Do not edit this file unless you know what you are doing. -import sys +# +# Some modifications made to this generated class by greg-ynx. from PyQt5 import QtCore, QtGui, QtWidgets @@ -68,5 +69,4 @@ def set_text(self, txt_file_path): def retranslateUi(self, about_form): _translate = QtCore.QCoreApplication.translate - #about_form.setWindowTitle(_translate("About_Form", "About...")) self.close_button.setText(_translate("About_Form", "Close")) diff --git a/src/app/ui/AboutForm/__pycache__/UiAboutForm.cpython-310.pyc b/src/app/ui/AboutForm/__pycache__/UiAboutForm.cpython-310.pyc deleted file mode 100644 index 9749150..0000000 Binary files a/src/app/ui/AboutForm/__pycache__/UiAboutForm.cpython-310.pyc and /dev/null differ diff --git a/src/app/ui/MainWindow/UiMainWindow.py b/src/app/ui/MainWindow/UiMainWindow.py index 0a756b7..94cf266 100644 --- a/src/app/ui/MainWindow/UiMainWindow.py +++ b/src/app/ui/MainWindow/UiMainWindow.py @@ -7,16 +7,21 @@ # WARNING: Any manual changes made to this file will be lost when pyuic5 is # run again. Do not edit this file unless you know what you are doing. # -# Some modifications made to this generated class by lyl-Lynx. +# Some modifications made to this generated class by greg-ynx. +import os import sys +import webbrowser + +from config.definitions import img_dir, txt_dir, doc_dir +from src.app.exceptions.CustomException import UnknownExtensionError from src.app.ui.TableView.UiTableViewForm import UiTableViewForm from src.app.ui.AboutForm.UiAboutForm import UiAboutForm -import webbrowser +from src.app.scripts.FileExport import * from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtGui import QStandardItem, QColor -from PyQt5.QtWidgets import QPushButton +from PyQt5.QtWidgets import QPushButton, QFileDialog, QWidget class UiMainWindow(object): @@ -31,7 +36,7 @@ def __init__(self, main_window): size_policy.setHeightForWidth(main_window.sizePolicy().hasHeightForWidth()) main_window.setSizePolicy(size_policy) icon = QtGui.QIcon() - icon.addPixmap(QtGui.QPixmap("../../../assets/img/pattern_builder_icon.ico"), QtGui.QIcon.Normal, + icon.addPixmap(QtGui.QPixmap(os.path.join(img_dir, "pattern_builder_icon.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off) main_window.setWindowIcon(icon) self.main_window = main_window @@ -39,20 +44,20 @@ def __init__(self, main_window): self.help_pattern_builder_widget = QtWidgets.QWidget() self.help_pattern_builder_form = UiAboutForm(self.help_pattern_builder_widget, "Pattern builder help", - "../../../assets/img/QuestionMark.png", - "../../../assets/txt/help_pattern_builder.txt") + os.path.join(img_dir, 'QuestionMark.png'), + os.path.join(txt_dir, 'help_pattern_builder.txt')) self.about_pattern_builder_widget = QtWidgets.QWidget() self.about_pattern_builder_form = UiAboutForm(self.about_pattern_builder_widget, "About Pattern Builder", - "../../../assets/img/pattern_builder_logo_c_800px.png", - "../../../assets/txt/about_pattern_builder.txt") + os.path.join(img_dir, "pattern_builder_logo_c_800px.png"), + os.path.join(txt_dir, "about_pattern_builder.txt")) self.about_lyl_lynx_widget = QtWidgets.QWidget() self.about_lyl_lynx_form = UiAboutForm(self.about_lyl_lynx_widget, - "About lyl-Lynx", - "../../../assets/img/lyl8Lynx_logo.png", - "../../../assets/txt/about_lyl_lynx.txt") + "About greg-ynx", + os.path.join(img_dir, "lyl8Lynx_logo.png"), + os.path.join(txt_dir, "about_lyl_lynx.txt")) self.colors_widget = QtWidgets.QWidget() self.table_view_form = UiTableViewForm(self.colors_widget) @@ -258,6 +263,7 @@ def __init__(self, main_window): size_policy.setHeightForWidth(self.export_button.sizePolicy().hasHeightForWidth()) self.export_button.setSizePolicy(size_policy) self.export_button.setObjectName("export_button") + self.export_button.clicked.connect(self.export_as) self.export_button_horizontal_layout.addWidget(self.export_button) spacerItem10 = QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) @@ -316,24 +322,15 @@ def __init__(self, main_window): self.menu_file = QtWidgets.QMenu(self.menubar) self.menu_file.setObjectName("menu_file") - self.menu_export_as = QtWidgets.QMenu(self.menu_file) + self.action_export_as = QtWidgets.QAction(self.menu_file) icon1 = QtGui.QIcon() - icon1.addPixmap(QtGui.QPixmap("../../../assets/img/Export.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) - self.menu_export_as.setIcon(icon1) - self.menu_export_as.setObjectName("menu_export_as") + icon1.addPixmap(QtGui.QPixmap(os.path.join(img_dir, "Export.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) + self.action_export_as.setIcon(icon1) + self.action_export_as.setObjectName("menu_export_as") + self.action_export_as.triggered.connect(self.export_as) - self.menu_matrix = QtWidgets.QMenu(self.menu_export_as) icon2 = QtGui.QIcon() - icon2.addPixmap(QtGui.QPixmap("../../../assets/img/matrix.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) - self.menu_matrix.setIcon(icon2) - self.menu_matrix.setObjectName("menu_matrix") - - self.menu_pattern = QtWidgets.QMenu(self.menu_export_as) - icon3 = QtGui.QIcon() - icon3.addPixmap(QtGui.QPixmap("../../../assets/img/pattern_builder_logo_c_800px.png"), QtGui.QIcon.Normal, - QtGui.QIcon.Off) - self.menu_pattern.setIcon(icon3) - self.menu_pattern.setObjectName("menu_pattern") + icon2.addPixmap(QtGui.QPixmap(os.path.join(img_dir, "pattern_builder_logo_c_800px.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.menu_help = QtWidgets.QMenu(self.menubar) self.menu_help.setObjectName("menu_help") @@ -344,107 +341,33 @@ def __init__(self, main_window): self.statusbar.setObjectName("statusbar") main_window.setStatusBar(self.statusbar) - self.action_matrix_text_file_txt = QtWidgets.QAction(main_window) - self.action_matrix_text_file_txt.setObjectName("action_matrix_text_file_txt") - - self.action_matrix_json = QtWidgets.QAction(main_window) - self.action_matrix_json.setObjectName("action_matrix_json") - - self.action_matrix_tabler_csv = QtWidgets.QAction(main_window) - self.action_matrix_tabler_csv.setObjectName("action_matrix_tabler_csv") - - self.action_matrix_tabler_xls = QtWidgets.QAction(main_window) - self.action_matrix_tabler_xls.setObjectName("action_matrix_tabler_xls") - - self.action_matrix_tabler_xlsx = QtWidgets.QAction(main_window) - self.action_matrix_tabler_xlsx.setObjectName("action_matrix_tabler_xlsx") - - self.action_matrix_image_jpeg = QtWidgets.QAction(main_window) - self.action_matrix_image_jpeg.setObjectName("action_matrix_image") - - self.action_matrix_image_jpg = QtWidgets.QAction(main_window) - self.action_matrix_image_jpg.setObjectName("action_matrix_image_jpg") - - self.action_matrix_image_wout_bg_png = QtWidgets.QAction(main_window) - self.action_matrix_image_wout_bg_png.setObjectName("action_matrix_image_wout_bg_png") - - self.action_matrix_image_white_bg_png = QtWidgets.QAction(main_window) - self.action_matrix_image_white_bg_png.setObjectName("action_matrix_image_white_bg_png") - - self.action_matrix_vector_svg = QtWidgets.QAction(main_window) - self.action_matrix_vector_svg.setObjectName("action_matrix_vector_svg") - - self.action_matrix_pdf = QtWidgets.QAction(main_window) - self.action_matrix_pdf.setObjectName("action_matrix_pdf") - - self.action_pattern_image_jpeg = QtWidgets.QAction(main_window) - self.action_pattern_image_jpeg.setObjectName("action_pattern_image_jpeg") - - self.action_pattern_image_jpg = QtWidgets.QAction(main_window) - self.action_pattern_image_jpg.setObjectName("action_pattern_image_jpg") - - self.action_pattern_wout_bg_png = QtWidgets.QAction(main_window) - self.action_pattern_wout_bg_png.setObjectName("action_pattern_wout_bg_png") - - self.action_pattern_white_bg_png = QtWidgets.QAction(main_window) - self.action_pattern_white_bg_png.setObjectName("action_pattern_white_bg_png") - - self.action_pattern_vector = QtWidgets.QAction(main_window) - self.action_pattern_vector.setObjectName("action_pattern_vector") - - self.action_pattern_pdf = QtWidgets.QAction(main_window) - self.action_pattern_pdf.setObjectName("action_pattern_pdf") - self.action_help = QtWidgets.QAction(main_window) - icon8 = QtGui.QIcon() - icon8.addPixmap(QtGui.QPixmap("../../../assets/img/QuestionMark.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) - self.action_help.setIcon(icon8) + icon3 = QtGui.QIcon() + icon3.addPixmap(QtGui.QPixmap(os.path.join(img_dir, "QuestionMark.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) + self.action_help.setIcon(icon3) self.action_help.setObjectName("action_help") self.action_help.triggered.connect(self.help_pattern_builder_widget.show) self.action_about_pb = QtWidgets.QAction(main_window) - self.action_about_pb.setIcon(icon3) + self.action_about_pb.setIcon(icon2) self.action_about_pb.setObjectName("action_about_pb") self.action_about_pb.triggered.connect(self.about_pattern_builder_widget.show) self.action_about_author = QtWidgets.QAction(main_window) - icon9 = QtGui.QIcon() - icon9.addPixmap(QtGui.QPixmap("../../../assets/img/lyl8Lynx_logo.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) - self.action_about_author.setIcon(icon9) + icon4 = QtGui.QIcon() + icon4.addPixmap(QtGui.QPixmap(os.path.join(img_dir, "lyl8Lynx_logo.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) + self.action_about_author.setIcon(icon4) self.action_about_author.setObjectName("action_about_author") self.action_about_author.triggered.connect(self.about_lyl_lynx_widget.show) self.action_join_us = QtWidgets.QAction(main_window) - icon10 = QtGui.QIcon() - icon10.addPixmap(QtGui.QPixmap("../../../assets/img/GitHub.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) - self.action_join_us.setIcon(icon10) + icon5 = QtGui.QIcon() + icon5.addPixmap(QtGui.QPixmap(os.path.join(img_dir, "GitHub.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) + self.action_join_us.setIcon(icon5) self.action_join_us.setObjectName("action_join_us") self.action_join_us.triggered.connect(self.redirect_to_github_repo) - self.menu_matrix.addAction(self.action_matrix_text_file_txt) - self.menu_matrix.addAction(self.action_matrix_json) - self.menu_matrix.addSeparator() - self.menu_matrix.addAction(self.action_matrix_tabler_csv) - self.menu_matrix.addAction(self.action_matrix_tabler_xls) - self.menu_matrix.addAction(self.action_matrix_tabler_xlsx) - self.menu_matrix.addSeparator() - self.menu_matrix.addAction(self.action_matrix_image_jpeg) - self.menu_matrix.addAction(self.action_matrix_image_jpg) - self.menu_matrix.addAction(self.action_matrix_image_wout_bg_png) - self.menu_matrix.addAction(self.action_matrix_image_white_bg_png) - self.menu_matrix.addAction(self.action_matrix_vector_svg) - self.menu_matrix.addAction(self.action_matrix_pdf) - self.menu_export_as.addAction(self.menu_matrix.menuAction()) - - self.menu_pattern.addAction(self.action_pattern_image_jpeg) - self.menu_pattern.addAction(self.action_pattern_image_jpg) - self.menu_pattern.addAction(self.action_pattern_wout_bg_png) - self.menu_pattern.addAction(self.action_pattern_white_bg_png) - self.menu_pattern.addAction(self.action_pattern_vector) - self.menu_pattern.addAction(self.action_pattern_pdf) - self.menu_export_as.addAction(self.menu_pattern.menuAction()) - - self.menu_file.addAction(self.menu_export_as.menuAction()) + self.menu_file.addAction(self.action_export_as) self.menu_help.addAction(self.action_help) self.menu_help.addSeparator() @@ -484,7 +407,6 @@ def update_colors_select(self): def switch_button_color(self): button = self.main_window.sender() params = self.get_selected_color() - print(params) button.setText(str(params['id'])) button.setStyleSheet("background-color : " + params['Hex']) @@ -515,11 +437,39 @@ def on_change_size(self): self.update_matrix_size() def redirect_to_github_repo(self): - webbrowser.open('https://github.com/lyl-Lynx/Pattern-Builder') + webbrowser.open('https://github.com/greg-ynx/Pattern-Builder') + + def get_matrix(self): + return [[self.gridLayout.itemAt(i * self.get_width() + j).widget().text() for j in range(self.get_height())] for + i + in range(self.get_width())] + + def export_as(self): + options = QFileDialog.Options() + file_name, ext = QFileDialog.getSaveFileName(QWidget(), "Export as", doc_dir, + "Text Files (*.txt) ;; JSON Files (*.json) ;; CSV Files (*.csv) " + ";; Tabler files (*.xlsx)", + options=options) + try: + if '.txt' in ext: + export_to_txt(self.get_matrix(), file_name) + elif '.json' in ext: + export_to_json(self.get_matrix(), file_name) + elif '.csv' in ext: + export_to_csv(self.get_matrix(), file_name) + elif '.xlsx' in ext: + export_to_xlsx(self.get_matrix(), file_name) + else: + raise UnknownExtensionError + except UnknownExtensionError: + print("Not valid extension!") + if file_name: + print(file_name) + print(ext) def retranslate_ui(self, main_window): _translate = QtCore.QCoreApplication.translate - main_window.setWindowTitle(_translate("main_window", "Pattern Builder by lyl-Lynx")) + main_window.setWindowTitle(_translate("main_window", "Pattern Builder by greg-ynx")) self.toolBox_title.setText(_translate("main_window", "Tool box")) self.toolBox_sizes_title.setText(_translate("main_window", "Sizes")) self.width_label.setText(_translate("main_window", "Width")) @@ -529,30 +479,11 @@ def retranslate_ui(self, main_window): self.reset_button.setText(_translate("main_window", "Reset pattern")) self.export_button.setText(_translate("main_window", "Export")) self.menu_file.setTitle(_translate("main_window", "File")) - self.menu_export_as.setTitle(_translate("main_window", "Export as...")) - self.menu_matrix.setTitle(_translate("main_window", "Matrix")) - self.menu_pattern.setTitle(_translate("main_window", "Pattern")) + self.action_export_as.setText(_translate("main_window", "Export as...")) self.menu_help.setTitle(_translate("main_window", "Help")) - self.action_matrix_text_file_txt.setText(_translate("main_window", "Text file (.txt)")) - self.action_matrix_json.setText(_translate("main_window", "JSON (.json)")) - self.action_matrix_tabler_csv.setText(_translate("main_window", "Tabler (.csv)")) - self.action_matrix_tabler_xls.setText(_translate("main_window", "Tabler (.xls)")) - self.action_matrix_tabler_xlsx.setText(_translate("main_window", "Tabler (.xlsx)")) - self.action_matrix_image_jpeg.setText(_translate("main_window", "Image (.jpeg)")) - self.action_matrix_image_jpg.setText(_translate("main_window", "Image (.jpg)")) - self.action_matrix_image_wout_bg_png.setText(_translate("main_window", "Without background (.png)")) - self.action_matrix_image_white_bg_png.setText(_translate("main_window", "With white background (.png)")) - self.action_matrix_vector_svg.setText(_translate("main_window", "Vector (.svg)")) - self.action_matrix_pdf.setText(_translate("main_window", "PDF (.pdf)")) - self.action_pattern_image_jpeg.setText(_translate("main_window", "Image (.jpeg)")) - self.action_pattern_image_jpg.setText(_translate("main_window", "Image (.jpg)")) - self.action_pattern_wout_bg_png.setText(_translate("main_window", "Without background (.png)")) - self.action_pattern_white_bg_png.setText(_translate("main_window", "With white background (.png)")) - self.action_pattern_vector.setText(_translate("main_window", "Vector (.svg)")) - self.action_pattern_pdf.setText(_translate("main_window", "PDF (.pdf)")) self.action_help.setText(_translate("main_window", "Pattern builder help")) self.action_about_pb.setText(_translate("main_window", "About Pattern builder")) - self.action_about_author.setText(_translate("main_window", "About lyl-Lynx")) + self.action_about_author.setText(_translate("main_window", "About greg-ynx")) self.action_join_us.setText(_translate("main_window", "Join us on GitHub !")) diff --git a/src/app/ui/TableView/UiTableViewForm.py b/src/app/ui/TableView/UiTableViewForm.py index ce8277f..cd55836 100644 --- a/src/app/ui/TableView/UiTableViewForm.py +++ b/src/app/ui/TableView/UiTableViewForm.py @@ -7,9 +7,8 @@ # WARNING: Any manual changes made to this file will be lost when pyuic5 is # run again. Do not edit this file unless you know what you are doing. # -# Some modifications made to this generated class by lyl-Lynx. +# Some modifications made to this generated class by greg-ynx. -import sys from PyQt5 import QtCore, QtGui, QtWidgets from src.app.exceptions.CustomException import IdNotFound, ProtectedRowError, TableMaxItemError @@ -239,10 +238,3 @@ def retranslateUi(self, table_view_form): item.setText(_translate("table_view_form", "(0,0,255)")) self.table_widget.setSortingEnabled(__sortingEnabled) self.close_button.setText(_translate("table_view_form", "Close")) - -if __name__ == "__main__": - app = QtWidgets.QApplication(sys.argv) - widget = QtWidgets.QWidget() - ui = UiTableViewForm(widget) - widget.show() - sys.exit(app.exec_()) diff --git a/src/app/ui/TableView/__pycache__/UiTableViewForm.cpython-310.pyc b/src/app/ui/TableView/__pycache__/UiTableViewForm.cpython-310.pyc deleted file mode 100644 index a2c6170..0000000 Binary files a/src/app/ui/TableView/__pycache__/UiTableViewForm.cpython-310.pyc and /dev/null differ diff --git a/src/assets/img/pattern_builder_logo_c_800px.ico b/src/assets/img/pattern_builder_logo_c_800px.ico new file mode 100644 index 0000000..d9158df Binary files /dev/null and b/src/assets/img/pattern_builder_logo_c_800px.ico differ diff --git a/src/assets/txt/about_lyl_lynx.txt b/src/assets/txt/about_lyl_lynx.txt index 66668c3..0b0d8ec 100644 --- a/src/assets/txt/about_lyl_lynx.txt +++ b/src/assets/txt/about_lyl_lynx.txt @@ -1,7 +1,7 @@ Hello World! -I am Grégory Ployart aka lyl-Lynx an I.T. engineering student at CESI engineering school. +I am Grégory Ployart aka greg-ynx an I.T. engineering student at CESI engineering school. You can contact me on : - Email : gregory.ployartwork@gmail.com - LinkedIn : https://www.linkedin.com/in/gr%C3%A9gory-ployart/ - - GitHub : https://github.com/lyl-Lynx \ No newline at end of file + - GitHub : https://github.com/greg-ynx \ No newline at end of file diff --git a/src/assets/txt/about_pattern_builder.txt b/src/assets/txt/about_pattern_builder.txt index 1a6f54c..db21453 100644 --- a/src/assets/txt/about_pattern_builder.txt +++ b/src/assets/txt/about_pattern_builder.txt @@ -12,4 +12,4 @@ open an issue or a merge request on the GitHub repository. if you have more questions about this application, you can contact me with this email address : -lyl-Lynx \ No newline at end of file +greg-ynx \ No newline at end of file diff --git a/src/assets/txt/help_pattern_builder.txt b/src/assets/txt/help_pattern_builder.txt index 54efc87..e51577d 100644 --- a/src/assets/txt/help_pattern_builder.txt +++ b/src/assets/txt/help_pattern_builder.txt @@ -1,6 +1,6 @@ If you encounter an issue with Pattern Builder's features, please open an issue on GitHub. - -> link : https://github.com/lyl-Lynx/Pattern-Builder + -> link : https://github.com/greg-ynx/Pattern-Builder You can also directly tell me about your issue on my mail address : -lyl-Lynx \ No newline at end of file +greg-ynx \ No newline at end of file