-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeps_dialog.py
More file actions
162 lines (127 loc) · 5.3 KB
/
Copy pathdeps_dialog.py
File metadata and controls
162 lines (127 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env python3
"""
Dependencies Configuration Dialog per PyQt6
Configurazione percorsi personalizzati per le dipendenze/tool esterni
Portato dalla versione GTK3
"""
import shutil
from PyQt6.QtWidgets import (
QDialog, QVBoxLayout, QHBoxLayout, QLabel, QTreeWidget, QTreeWidgetItem,
QPushButton, QScrollArea, QHeaderView, QLineEdit, QFileDialog, QDialogButtonBox
)
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QFont
import config_manager
from translations import t
class DepsConfigDialog(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle(t("deps.title"))
self.setModal(True)
self.resize(600, 400)
self._settings = config_manager.load_settings()
self._custom_paths = self._settings.get("tool_paths", {})
self._tools = {
"ssh": "SSH client", "scp": "SCP", "sftp": "SFTP client",
"telnet": "Telnet", "ftp": "FTP client", "xfreerdp3": "FreeRDP 3.x",
"xtigervncviewer": "TigerVNC", "xdotool": "xdotool", "wol": "Wake-on-LAN"
}
self._init_ui()
def _init_ui(self):
layout = QVBoxLayout(self)
layout.setContentsMargins(10, 10, 10, 10)
# Tabella dipendenze
self._tree = QTreeWidget()
self._tree.setHeaderLabels([t("deps.col_status"), t("deps.col_component"), t("deps.col_default"), t("deps.col_custom_qt")])
self._tree.setRootIsDecorated(False)
self._tree.setAlternatingRowColors(True)
# Configura colonne
header = self._tree.header()
header.setSectionResizeMode(0, QHeaderView.ResizeMode.ResizeToContents)
header.setSectionResizeMode(1, QHeaderView.ResizeMode.ResizeToContents)
header.setSectionResizeMode(2, QHeaderView.ResizeMode.ResizeToContents)
header.setSectionResizeMode(3, QHeaderView.ResizeMode.Stretch)
self._reload_list()
layout.addWidget(self._tree)
# Pulsanti azione
btn_layout = QHBoxLayout()
btn_browse = QPushButton(t("deps.btn_browse"))
btn_browse.clicked.connect(self._browse_path)
btn_layout.addWidget(btn_browse)
btn_reset = QPushButton(t("deps.btn_reset"))
btn_reset.clicked.connect(self._reset_path)
btn_layout.addWidget(btn_reset)
btn_layout.addStretch()
layout.addLayout(btn_layout)
# Pulsanti dialog
dialog_layout = QHBoxLayout()
dialog_layout.addStretch()
btn_cancel = QPushButton(t("sd.cancel"))
btn_cancel.clicked.connect(self.reject)
dialog_layout.addWidget(btn_cancel)
btn_ok = QPushButton("OK")
btn_ok.setDefault(True)
btn_ok.clicked.connect(self._save_and_accept)
dialog_layout.addWidget(btn_ok)
layout.addLayout(dialog_layout)
def _reload_list(self):
"""Ricarica la lista delle dipendenze."""
self._tree.clear()
for tool_id, description in self._tools.items():
# Controlla se il tool è disponibile
detected_path = shutil.which(tool_id)
custom_path = self._custom_paths.get(tool_id, "")
# Determina lo status
if custom_path and shutil.which(custom_path):
status = "✅"
effective_path = custom_path
elif detected_path:
status = "✅"
effective_path = detected_path
else:
status = "❌"
effective_path = t("deps.not_found")
item = QTreeWidgetItem([
status,
description,
tool_id,
custom_path
])
# Memorizza l'ID del tool nell'item
item.setData(0, Qt.ItemDataRole.UserRole, tool_id)
self._tree.addTopLevelItem(item)
def _browse_path(self):
"""Apre un dialog per selezionare il percorso di un tool."""
current = self._tree.currentItem()
if not current:
return
tool_id = current.data(0, Qt.ItemDataRole.UserRole)
if not tool_id:
return
file_path, _ = QFileDialog.getOpenFileName(
self,
t("deps.browse_title").format(tool=tool_id),
"",
"Eseguibili (*)"
)
if file_path:
current.setText(3, file_path)
def _reset_path(self):
"""Resetta il percorso personalizzato per il tool selezionato."""
current = self._tree.currentItem()
if current:
current.setText(3, "")
def _save_and_accept(self):
"""Salva le configurazioni e chiude il dialog."""
# Raccoglie tutti i percorsi personalizzati
tool_paths = {}
for i in range(self._tree.topLevelItemCount()):
item = self._tree.topLevelItem(i)
tool_id = item.data(0, Qt.ItemDataRole.UserRole)
custom_path = item.text(3).strip()
if tool_id and custom_path:
tool_paths[tool_id] = custom_path
# Salva nei settings
self._settings["tool_paths"] = tool_paths
config_manager.save_settings(self._settings)
self.accept()