Skip to content

Dev #38

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

Merged
merged 4 commits into from
Dec 7, 2024
Merged

Dev #38

Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added automation_file/gui/__init__.py
Empty file.
20 changes: 20 additions & 0 deletions automation_file/gui/main_widget.py
Original file line number Diff line number Diff line change
@@ -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)
44 changes: 44 additions & 0 deletions automation_file/gui/main_window.py
Original file line number Diff line number Diff line change
@@ -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())
14 changes: 10 additions & 4 deletions automation_file/local/file/file_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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}, "
Expand Down
27 changes: 19 additions & 8 deletions automation_file/utils/logging/loggin_instance.py
Original file line number Diff line number Diff line change
@@ -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="FileAutomation.log", mode="w")
file_handler.setFormatter(formatter)
file_automation_logger.addHandler(file_handler)

class FileAutomationLoggingHandler(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(FileAutomationLoggingHandler())


2 changes: 1 addition & 1 deletion dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "automation_file_dev"
version = "0.0.23"
version = "0.0.25"
authors = [
{ name = "JE-Chen", email = "zenmailman@gmail.com" },
]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "automation_file"
version = "0.0.21"
version = "0.0.23"
authors = [
{ name = "JE-Chen", email = "zenmailman@gmail.com" },
]
Expand Down