Skip to content

Commit 7f51775

Browse files
committed
Update stable version
* Add logger * New Icon
1 parent 3c0d118 commit 7f51775

File tree

6 files changed

+85
-20
lines changed

6 files changed

+85
-20
lines changed

automation_ide/automation_editor_ui/editor_main/main_ui.py

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from pathlib import Path
55
from typing import List, Dict, Type
66

7+
from automation_ide.utils.logging.logger import automation_ide_logger
8+
79
environ["LOCUST_SKIP_MONKEY_PATCH"] = "1"
810

911
from PySide6.QtCore import QTimer, QCoreApplication
@@ -24,33 +26,46 @@
2426

2527
class AutomationEditor(EditorMain):
2628

27-
def __init__(self, debug_mode: bool = False, show_system_tray_ray: bool = False):
28-
super().__init__(debug_mode, show_system_tray_ray)
29+
def __init__(self, debug_mode: bool = False, show_system_tray_ray: bool = False, extend: bool = False) -> None:
30+
super().__init__(debug_mode, show_system_tray_ray, extend=True)
31+
2932
self.current_run_code_window: List[QWidget] = list()
3033
# Project compiler if user not choose this will use which to find
3134
self.python_compiler = None
3235
# Delete JEditor help
3336
if self.help_menu:
3437
self.help_menu.deleteLater()
35-
# System tray change
36-
if self.show_system_tray_ray:
37-
self.system_tray.main_window = self
38-
self.system_tray.setToolTip(language_wrapper.language_word_dict.get("automation_editor_application_name"))
38+
3939
# Update language_dict
4040
update_language_dict()
41+
42+
# Title
43+
self.setWindowTitle(language_wrapper.language_word_dict.get("automation_editor_application_name"))
44+
self.setToolTip(language_wrapper.language_word_dict.get("automation_editor_application_name"))
45+
46+
# Windows 系統專用:設定應用程式 ID
47+
# Windows only: set application ID
48+
if not extend:
49+
self.id = language_wrapper.language_word_dict.get("automation_editor_application_name")
50+
if sys.platform in ["win32", "cygwin", "msys"]:
51+
from ctypes import windll
52+
windll.shell32.SetCurrentProcessExplicitAppUserModelID(self.id)
53+
54+
# Icon
55+
if not extend:
56+
self.icon_path = Path(os.getcwd() + "/automation_ide.ico")
57+
self.icon = QIcon(str(self.icon_path))
58+
if not self.icon.isNull():
59+
self.setWindowIcon(self.icon)
60+
4161
# Menu
4262
add_menu_to_menubar(self)
4363
syntax_extend_package(self)
64+
4465
# Tab
4566
for widget_name, widget in EDITOR_EXTEND_TAB.items():
4667
self.tab_widget.addTab(widget(), widget_name)
47-
# Icon
48-
self.icon_path = Path(os.getcwd() + "/AutomationIDE_Icon.ico")
49-
self.icon = QIcon(str(self.icon_path))
50-
self.system_tray = QSystemTrayIcon()
51-
self.system_tray.setIcon(self.icon)
52-
# Title
53-
self.setWindowTitle(language_wrapper.language_word_dict.get("automation_editor_application_name"))
68+
5469
if debug_mode:
5570
close_timer = QTimer(self)
5671
close_timer.setInterval(10000)
@@ -76,14 +91,14 @@ def start_editor(debug_mode: bool = False, **kwargs) -> None:
7691
Start editor instance
7792
:return: None
7893
"""
79-
new_editor = QCoreApplication.instance()
80-
if new_editor is None:
81-
new_editor = QApplication(sys.argv)
94+
new_ide = QCoreApplication.instance()
95+
if new_ide is None:
96+
new_ide = QApplication(sys.argv)
8297
window = AutomationEditor(debug_mode=debug_mode, **kwargs)
83-
apply_stylesheet(new_editor, theme="dark_amber.xml")
98+
apply_stylesheet(new_ide, theme="dark_amber.xml")
8499
window.showMaximized()
85100
try:
86101
window.startup_setting()
87102
except Exception as error:
88103
print(repr(error))
89-
sys.exit(new_editor.exec())
104+
sys.exit(new_ide.exec())

automation_ide/utils/logging/__init__.py

Whitespace-only changes.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import logging
2+
from logging.handlers import RotatingFileHandler
3+
4+
# 設定 root logger 等級 Set root logger level
5+
logging.root.setLevel(logging.DEBUG)
6+
7+
# 建立 AutoControlGUI 專用 logger Create dedicated logger
8+
automation_ide_logger = logging.getLogger("AutomationIDE")
9+
10+
# 日誌格式 Formatter
11+
formatter = logging.Formatter(
12+
"%(asctime)s | %(name)s | %(levelname)s | %(message)s"
13+
)
14+
15+
16+
class AutomationIDELogger(RotatingFileHandler):
17+
"""
18+
AutoControlGUILoggingHandler
19+
自訂日誌處理器,繼承 RotatingFileHandler
20+
- 支援檔案大小輪替
21+
- 預設輸出到 AutoControlGUI.log
22+
"""
23+
24+
def __init__(
25+
self,
26+
filename: str = "AutomationIDE.log",
27+
mode: str = "w",
28+
max_bytes: int = 1073741824, # 1GB
29+
backup_count: int = 0,
30+
):
31+
super().__init__(
32+
filename=filename,
33+
mode=mode,
34+
maxBytes=max_bytes,
35+
backupCount=backup_count,
36+
)
37+
self.setFormatter(formatter) # 設定格式器
38+
self.setLevel(logging.DEBUG) # 設定等級
39+
40+
def emit(self, record: logging.LogRecord) -> None:
41+
"""
42+
Emit log record.
43+
輸出日誌紀錄
44+
"""
45+
super().emit(record)
46+
47+
48+
# 建立並加入檔案處理器 Add file handler to logger
49+
file_handler = AutomationIDELogger()
50+
automation_ide_logger.addHandler(file_handler)

exe/auto_py_to_exe_setting.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
{
2121
"optionDest": "icon_file",
22-
"value": "C:/CodeWorkspace/Python/AutomationIDE/exe/AutomationIDE_Icon.ico"
22+
"value": "C:/CodeWorkspace/Python/AutomationIDE/exe/automation_ide.ico"
2323
},
2424
{
2525
"optionDest": "name",

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
66

77
[project]
88
name = "automation_ide"
9-
version = "0.0.55"
9+
version = "0.0.58"
1010
authors = [
1111
{ name = "JE-Chen", email = "jechenmailman@gmail.com" },
1212
]

0 commit comments

Comments
 (0)