Skip to content

Commit 782382f

Browse files
committed
SSH适配: 1.整改utils.py (分离QtUI依赖)
2.复用driver download逻辑 Signed-off-by: wuqiongjin <suchinfinity@qq.com>
1 parent bb45df8 commit 782382f

6 files changed

Lines changed: 44 additions & 41 deletions

File tree

src/runner/runner_main.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,21 @@ def main(argv: list[str] | None = None) -> int:
7575
driver_root = str(Path(args.driver_root).expanduser().resolve())
7676
Path(driver_root).mkdir(parents=True, exist_ok=True)
7777

78-
# 1) Prefer webdriver_manager if present (保持项目既有逻辑)
78+
# 1) Prefer project existing logic (Utils.download_edge_web_driver)
7979
try:
80-
from webdriver_manager.core.driver_cache import DriverCacheManager
81-
from webdriver_manager.microsoft import EdgeChromiumDriverManager
82-
83-
cache = DriverCacheManager(root_dir=driver_root)
84-
path = EdgeChromiumDriverManager(
85-
url="https://msedgedriver.microsoft.com/",
86-
latest_release_url="https://msedgedriver.microsoft.com/LATEST_RELEASE",
87-
cache_manager=cache,
88-
).install()
89-
print(path)
90-
return 0
91-
except ModuleNotFoundError:
92-
# Fallback without extra dependencies
80+
from src.utils.utils import Utils
81+
82+
old_driver_root = AppPath.DriversRoot
83+
try:
84+
AppPath.DriversRoot = driver_root
85+
ok, result = Utils.download_edge_web_driver()
86+
finally:
87+
AppPath.DriversRoot = old_driver_root
88+
89+
if ok:
90+
print(result)
91+
return 0
92+
except Exception:
9393
pass
9494

9595
# 2) Fallback: download zip and extract to driver_root/.wdm/drivers/edgedriver/linux64/<version>/

src/ui/ui.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
from src.utils.const import Key, AppPath, WebPath
1616
from src.ui.ui_message import MessageBox
1717
from src.utils.update import VersionCheckThread
18-
from src.utils.utils import Utils, QtUI
18+
from src.utils.utils import Utils
19+
from src.utils.qt_ui import QtUI
1920
from src.core.clock_manager import ClockManager, run_clock
2021

2122
# 根据操作系统导入相应的模块

src/ui/ui_system_plan.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from src.utils.log import Log
1010
from src.utils.const import Key
1111
from src.ui.ui_calendar import Calendar, WeeklyCalendar
12-
from src.utils.utils import Utils, QtUI
12+
from src.utils.utils import Utils
13+
from src.utils.qt_ui import QtUI
1314
from src.ui.ui_message import MessageBox
1415

1516

src/utils/qt_ui.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from PyQt5.QtGui import QFont
2+
from PyQt5.QtWidgets import QLabel
3+
4+
5+
class QtUI:
6+
@staticmethod
7+
def create_label(message, size=11, length=150, family="Arial", width_policy=None, height_policy=None,
8+
alignment=None, fixed_width=None, fixed_height=None):
9+
label = QLabel(message)
10+
font = QFont()
11+
font.setFamily(family)
12+
font.setPointSize(size)
13+
label.setFont(font)
14+
label.setFixedWidth(length)
15+
if width_policy is not None and height_policy is not None:
16+
label.setSizePolicy(width_policy, height_policy)
17+
if alignment is not None:
18+
label.setAlignment(alignment)
19+
if fixed_width is not None:
20+
label.setFixedWidth(fixed_width)
21+
if fixed_height is not None:
22+
label.setFixedHeight(fixed_height)
23+
return label

src/utils/utils.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
from webdriver_manager.core.driver_cache import DriverCacheManager
1111
from webdriver_manager.microsoft import EdgeChromiumDriverManager
1212

13-
from PyQt5.QtGui import QFont
14-
from PyQt5.QtWidgets import QLabel
15-
1613
from src.utils.log import Log
1714
from src.utils.const import Key, AppPath
1815

@@ -267,24 +264,4 @@ def download_edge_web_driver(target_os: str | None = None, target_arch: str | No
267264
else:
268265
os.environ["WDM_ARCH"] = old_wdm_arch
269266

270-
return True, driver_path
271-
272-
class QtUI:
273-
@staticmethod
274-
def create_label(message, size=11, length=150, family="Arial", width_policy=None, height_policy=None,
275-
alignment=None, fixed_width=None, fixed_height=None):
276-
label = QLabel(message)
277-
font = QFont()
278-
font.setFamily(family)
279-
font.setPointSize(size)
280-
label.setFont(font)
281-
label.setFixedWidth(length)
282-
if width_policy is not None and height_policy is not None:
283-
label.setSizePolicy(width_policy, height_policy)
284-
if alignment is not None:
285-
label.setAlignment(alignment)
286-
if fixed_width is not None:
287-
label.setFixedWidth(fixed_width)
288-
if fixed_height is not None:
289-
label.setFixedHeight(fixed_height)
290-
return label
267+
return True, driver_path

ui/custom/custom_widget.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from PyQt5.QtWidgets import QLineEdit, QCheckBox, QWidget, QHBoxLayout, QPushButton, QFileDialog, QComboBox
33

44
from src.utils.const import Key
5-
from src.utils.utils import QtUI, Utils
5+
from src.utils.utils import Utils
6+
from src.utils.qt_ui import QtUI
67
from src.utils.const import AppPath
78

89

0 commit comments

Comments
 (0)