From 2e7417e419c0cac149e8426815bf760776f09cdb Mon Sep 17 00:00:00 2001 From: JE-Chen <33644111+JE-Chen@users.noreply.github.com> Date: Sun, 8 Sep 2024 18:16:32 +0800 Subject: [PATCH 1/4] Add gui init Add gui init --- automation_file/gui/__init__.py | 0 automation_file/gui/main_widget.py | 20 ++++++++++++++ automation_file/gui/main_window.py | 44 ++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 automation_file/gui/__init__.py create mode 100644 automation_file/gui/main_widget.py create mode 100644 automation_file/gui/main_window.py diff --git a/automation_file/gui/__init__.py b/automation_file/gui/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/automation_file/gui/main_widget.py b/automation_file/gui/main_widget.py new file mode 100644 index 0000000..999b0e7 --- /dev/null +++ b/automation_file/gui/main_widget.py @@ -0,0 +1,20 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from je_auto_control.gui.main_window import AutoControlGUI + +from PySide6.QtWidgets import QWidget, QGridLayout + + +class AutoControlWidget(QWidget): + + def __init__(self, main_ui: AutoControlGUI): + super().__init__() + # Variable + self.main_ui = main_ui + # UI component + # Grid layout + self.grid_layout = QGridLayout() + self.setLayout(self.grid_layout) diff --git a/automation_file/gui/main_window.py b/automation_file/gui/main_window.py new file mode 100644 index 0000000..791490f --- /dev/null +++ b/automation_file/gui/main_window.py @@ -0,0 +1,44 @@ +import os +import sys +from pathlib import Path + +from PySide6.QtCore import QCoreApplication, QTimer +from PySide6.QtGui import QIcon +from PySide6.QtWidgets import QMainWindow, QApplication +from qt_material import apply_stylesheet + +from je_auto_control.gui.main_widget import AutoControlWidget + + +class AutoControlGUI(QMainWindow): + + def __init__(self, debug_mode: bool = False): + super().__init__() + self.debug_mode = debug_mode + self.central_widget = AutoControlWidget(self) + self.setCentralWidget(self.central_widget) + self.setWindowTitle("AutoControlGUI") + # Set Icon + self.icon_path = Path(os.getcwd() + "/je_driver_icon.ico") + self.icon = QIcon(str(self.icon_path)) + if self.icon.isNull() is False: + self.setWindowIcon(self.icon) + if self.debug_mode: + close_timer = QTimer(self) + close_timer.setInterval(10000) + close_timer.timeout.connect(self.debug_close) + close_timer.start() + + @classmethod + def debug_close(cls): + sys.exit(0) + + +def start_autocontrol_gui(debug_mode: bool = False) -> None: + autocontrol_gui = QCoreApplication.instance() + if autocontrol_gui is None: + autocontrol_gui = QApplication(sys.argv) + window = AutoControlGUI(debug_mode) + apply_stylesheet(autocontrol_gui, theme='dark_amber.xml') + window.showMaximized() + sys.exit(autocontrol_gui.exec()) From 2ff46e291712deb50d28d28ea3979b1e3959cd0f Mon Sep 17 00:00:00 2001 From: JE-Chen <33644111+JE-Chen@users.noreply.github.com> Date: Sun, 8 Dec 2024 01:27:36 +0800 Subject: [PATCH 2/4] Update dev version Update dev version * Update logging --- .idea/misc.xml | 2 +- automation_file/local/file/file_process.py | 14 +++++++--- .../utils/logging/loggin_instance.py | 27 +++++++++++++------ pyproject.toml | 4 +-- dev.toml => stable.toml | 4 +-- 5 files changed, 34 insertions(+), 17 deletions(-) rename dev.toml => stable.toml (95%) diff --git a/.idea/misc.xml b/.idea/misc.xml index 35233d5..2cefeb6 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/automation_file/local/file/file_process.py b/automation_file/local/file/file_process.py index 2acfcef..c6a1081 100644 --- a/automation_file/local/file/file_process.py +++ b/automation_file/local/file/file_process.py @@ -6,16 +6,20 @@ from automation_file.utils.logging.loggin_instance import file_automation_logger -def copy_file(file_path: str, target_path: str) -> bool: +def copy_file(file_path: str, target_path: str, copy_metadata: bool = True) -> bool: """ :param file_path: which file do we want to copy (str path) :param target_path: put copy file on target path + :param copy_metadata: copy file metadata or not :return: True if success else False """ file_path = Path(file_path) if file_path.is_file() and file_path.exists(): try: - shutil.copy2(file_path, target_path) + if copy_metadata: + shutil.copy2(file_path, target_path) + else: + shutil.copy(file_path, target_path) file_automation_logger.info(f"Copy file origin path: {file_path}, target path : {target_path}") return True except shutil.Error as error: @@ -25,17 +29,19 @@ def copy_file(file_path: str, target_path: str) -> bool: return False -def copy_specify_extension_file(file_dir_path: str, target_extension: str, target_path: str) -> bool: +def copy_specify_extension_file( + file_dir_path: str, target_extension: str, target_path: str, copy_metadata: bool = True) -> bool: """ :param file_dir_path: which dir do we want to search :param target_extension: what extension we will search :param target_path: copy file to target path + :param copy_metadata: copy file metadata or not :return: True if success else False """ file_dir_path = Path(file_dir_path) if file_dir_path.exists() and file_dir_path.is_dir(): for file in file_dir_path.glob(f"**/*.{target_extension}"): - copy_file(str(file), target_path) + copy_file(str(file), target_path, copy_metadata=copy_metadata) file_automation_logger.info( f"Copy specify extension file on dir" f"origin dir path: {file_dir_path}, target extension: {target_extension}, " diff --git a/automation_file/utils/logging/loggin_instance.py b/automation_file/utils/logging/loggin_instance.py index 63b5da1..9a3782f 100644 --- a/automation_file/utils/logging/loggin_instance.py +++ b/automation_file/utils/logging/loggin_instance.py @@ -1,16 +1,27 @@ import logging -import sys +logging.root.setLevel(logging.DEBUG) file_automation_logger = logging.getLogger("File Automation") -file_automation_logger.setLevel(logging.INFO) formatter = logging.Formatter('%(asctime)s | %(name)s | %(levelname)s | %(message)s') -# Stream handler -stream_handler = logging.StreamHandler(stream=sys.stderr) -stream_handler.setFormatter(formatter) -stream_handler.setLevel(logging.WARNING) -file_automation_logger.addHandler(stream_handler) # File handler -file_handler = logging.FileHandler(filename="FileAutomation.log", mode="w+") +file_handler = logging.FileHandler(filename="AutoControlGUI.log", mode="w") file_handler.setFormatter(formatter) file_automation_logger.addHandler(file_handler) +class APITestkaLoggingHandler(logging.Handler): + + # redirect logging stderr output to queue + + def __init__(self): + super().__init__() + self.formatter = formatter + self.setLevel(logging.DEBUG) + + def emit(self, record: logging.LogRecord) -> None: + print(self.format(record)) + + +# Stream handler +file_automation_logger.addHandler(APITestkaLoggingHandler()) + + diff --git a/pyproject.toml b/pyproject.toml index 6fe95f2..1a453dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,8 +5,8 @@ requires = ["setuptools>=61.0"] build-backend = "setuptools.build_meta" [project] -name = "automation_file" -version = "0.0.21" +name = "automation_file_dev" +version = "0.0.24" authors = [ { name = "JE-Chen", email = "zenmailman@gmail.com" }, ] diff --git a/dev.toml b/stable.toml similarity index 95% rename from dev.toml rename to stable.toml index 874e4c3..6fe95f2 100644 --- a/dev.toml +++ b/stable.toml @@ -5,8 +5,8 @@ requires = ["setuptools>=61.0"] build-backend = "setuptools.build_meta" [project] -name = "automation_file_dev" -version = "0.0.23" +name = "automation_file" +version = "0.0.21" authors = [ { name = "JE-Chen", email = "zenmailman@gmail.com" }, ] From dbc099faf5c6670703e3f6f0c19c8f764131b7a6 Mon Sep 17 00:00:00 2001 From: JE-Chen <33644111+JE-Chen@users.noreply.github.com> Date: Sun, 8 Dec 2024 01:36:16 +0800 Subject: [PATCH 3/4] Update dev version Update dev version * Fix logger use wrong name "AutoControl" --- automation_file/utils/logging/loggin_instance.py | 6 +++--- pyproject.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/automation_file/utils/logging/loggin_instance.py b/automation_file/utils/logging/loggin_instance.py index 9a3782f..6887b04 100644 --- a/automation_file/utils/logging/loggin_instance.py +++ b/automation_file/utils/logging/loggin_instance.py @@ -4,11 +4,11 @@ file_automation_logger = logging.getLogger("File Automation") formatter = logging.Formatter('%(asctime)s | %(name)s | %(levelname)s | %(message)s') # File handler -file_handler = logging.FileHandler(filename="AutoControlGUI.log", mode="w") +file_handler = logging.FileHandler(filename="FileAutomation.log", mode="w") file_handler.setFormatter(formatter) file_automation_logger.addHandler(file_handler) -class APITestkaLoggingHandler(logging.Handler): +class FileAutomationLoggingHandler(logging.Handler): # redirect logging stderr output to queue @@ -22,6 +22,6 @@ def emit(self, record: logging.LogRecord) -> None: # Stream handler -file_automation_logger.addHandler(APITestkaLoggingHandler()) +file_automation_logger.addHandler(FileAutomationLoggingHandler()) diff --git a/pyproject.toml b/pyproject.toml index 1a453dc..1c0f0e1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" [project] name = "automation_file_dev" -version = "0.0.24" +version = "0.0.25" authors = [ { name = "JE-Chen", email = "zenmailman@gmail.com" }, ] From b78aef2d347cbaf005e1c541b51118bd4f85d48f Mon Sep 17 00:00:00 2001 From: JE-Chen <33644111+JE-Chen@users.noreply.github.com> Date: Sun, 8 Dec 2024 01:45:13 +0800 Subject: [PATCH 4/4] Update stable version --- stable.toml => dev.toml | 4 ++-- pyproject.toml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename stable.toml => dev.toml (95%) diff --git a/stable.toml b/dev.toml similarity index 95% rename from stable.toml rename to dev.toml index 6fe95f2..1c0f0e1 100644 --- a/stable.toml +++ b/dev.toml @@ -5,8 +5,8 @@ requires = ["setuptools>=61.0"] build-backend = "setuptools.build_meta" [project] -name = "automation_file" -version = "0.0.21" +name = "automation_file_dev" +version = "0.0.25" authors = [ { name = "JE-Chen", email = "zenmailman@gmail.com" }, ] diff --git a/pyproject.toml b/pyproject.toml index 1c0f0e1..94a2b80 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,8 +5,8 @@ requires = ["setuptools>=61.0"] build-backend = "setuptools.build_meta" [project] -name = "automation_file_dev" -version = "0.0.25" +name = "automation_file" +version = "0.0.23" authors = [ { name = "JE-Chen", email = "zenmailman@gmail.com" }, ]