feat: add chrome path picker
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from contextlib import contextmanager
|
||||
import os
|
||||
|
||||
from ... import ai as ai_module
|
||||
from ..widgets import *
|
||||
@@ -165,6 +166,15 @@ class SettingsTab(QWidget):
|
||||
self.jpg_quality_spin.setRange(1, 100)
|
||||
self.chrome_path_edit = QLineEdit()
|
||||
self.chrome_path_edit.setObjectName("chromePathEdit")
|
||||
self.chrome_path_browse_button = QPushButton("选择...")
|
||||
self.chrome_path_browse_button.setObjectName("chromePathBrowseButton")
|
||||
self.chrome_path_widget = QWidget()
|
||||
self.chrome_path_widget.setObjectName("chromePathWidget")
|
||||
chrome_path_layout = QHBoxLayout(self.chrome_path_widget)
|
||||
chrome_path_layout.setContentsMargins(0, 0, 0, 0)
|
||||
chrome_path_layout.setSpacing(8)
|
||||
chrome_path_layout.addWidget(self.chrome_path_edit, 1)
|
||||
chrome_path_layout.addWidget(self.chrome_path_browse_button)
|
||||
self.user_data_root_edit = QLineEdit()
|
||||
self.user_data_root_edit.setObjectName("userDataRootEdit")
|
||||
self.user_data_root_edit.setEnabled(False)
|
||||
@@ -271,7 +281,7 @@ class SettingsTab(QWidget):
|
||||
|
||||
path_form = self._three_column_form(
|
||||
[
|
||||
("Chrome路径", self.chrome_path_edit, True),
|
||||
("Chrome路径", self.chrome_path_widget, True),
|
||||
("默认调试端口", self.default_debug_port_spin),
|
||||
("调试端口范围", port_range_widget),
|
||||
("CDP就绪超时(秒)", self.cdp_ready_timeout_spin),
|
||||
@@ -403,6 +413,7 @@ class SettingsTab(QWidget):
|
||||
self.resolution_combo.currentIndexChanged.connect(
|
||||
self._update_response_timeout_label
|
||||
)
|
||||
self.chrome_path_browse_button.clicked.connect(self.browse_chrome_path)
|
||||
self.save_config_button.clicked.connect(self.save_app_settings)
|
||||
self._connect_dirty_signals()
|
||||
|
||||
@@ -533,6 +544,23 @@ class SettingsTab(QWidget):
|
||||
def is_dirty(self):
|
||||
return self._dirty
|
||||
|
||||
def browse_chrome_path(self, checked=False):
|
||||
current = self.chrome_path_edit.text().strip()
|
||||
initial_dir = ""
|
||||
if current:
|
||||
parent_dir = os.path.dirname(os.path.expanduser(current))
|
||||
if parent_dir and os.path.isdir(parent_dir):
|
||||
initial_dir = parent_dir
|
||||
path, _selected_filter = QFileDialog.getOpenFileName(
|
||||
self,
|
||||
"选择 Chrome 程序",
|
||||
initial_dir,
|
||||
"Chrome 程序 (chrome.exe);;可执行文件 (*.exe);;所有文件 (*)",
|
||||
)
|
||||
if not path:
|
||||
return
|
||||
self.chrome_path_edit.setText(path)
|
||||
|
||||
def discard_unsaved_changes(self):
|
||||
try:
|
||||
saved = appconfig.load_config(self.config_path)
|
||||
|
||||
Reference in New Issue
Block a user