adbsshdeck 0.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,122 @@
1
+ from pathlib import Path
2
+
3
+ from PyQt5.QtWidgets import (
4
+ QApplication,
5
+ QDialog,
6
+ QDialogButtonBox,
7
+ QFileDialog,
8
+ QFormLayout,
9
+ QGroupBox,
10
+ QHBoxLayout,
11
+ QLabel,
12
+ QLineEdit,
13
+ QMessageBox,
14
+ QPushButton,
15
+ QTextEdit,
16
+ QVBoxLayout,
17
+ )
18
+
19
+ from ..config import AppConfig
20
+
21
+
22
+ class PreferencesDialog(QDialog):
23
+ """Paths, SSH quick commands — stored in your profile."""
24
+
25
+ def __init__(self, config: AppConfig, parent=None):
26
+ super().__init__(parent)
27
+ self._config = config
28
+ self.setWindowTitle("Preferences")
29
+ self.setModal(True)
30
+ app = QApplication.instance()
31
+ if app is not None:
32
+ self.setWindowIcon(app.windowIcon())
33
+ self.resize(560, 480)
34
+ self._build_ui()
35
+
36
+ def _build_ui(self):
37
+ root = QVBoxLayout(self)
38
+ root.addWidget(QLabel("Leave tool paths empty to use the programs on your PATH (adb, scrcpy)."))
39
+
40
+ paths = QGroupBox("Executables")
41
+ pf = QFormLayout(paths)
42
+ row_adb = QHBoxLayout()
43
+ self.adb_edit = QLineEdit(self._config.adb_path)
44
+ self.adb_edit.setPlaceholderText("adb — or full path")
45
+ btn_adb = QPushButton("Browse…")
46
+ btn_adb.clicked.connect(self._browse_adb)
47
+ row_adb.addWidget(self.adb_edit, 1)
48
+ row_adb.addWidget(btn_adb)
49
+ pf.addRow("ADB:", row_adb)
50
+
51
+ row_sc = QHBoxLayout()
52
+ self.scrcpy_edit = QLineEdit(self._config.scrcpy_path)
53
+ self.scrcpy_edit.setPlaceholderText("scrcpy — or full path")
54
+ btn_sc = QPushButton("Browse…")
55
+ btn_sc.clicked.connect(self._browse_scrcpy)
56
+ row_sc.addWidget(self.scrcpy_edit, 1)
57
+ row_sc.addWidget(btn_sc)
58
+ pf.addRow("scrcpy:", row_sc)
59
+ root.addWidget(paths)
60
+
61
+ ssh = QGroupBox("SSH (terminal)")
62
+ sf = QVBoxLayout(ssh)
63
+ ssh_intro = QLabel(
64
+ "Custom commands for Commands → SSH (one per line). "
65
+ "Each line: Label | shell command — sent to the active terminal when chosen."
66
+ )
67
+ ssh_intro.setWordWrap(True)
68
+ sf.addWidget(ssh_intro)
69
+ self.quick_edit = QTextEdit()
70
+ lines = []
71
+ for x in getattr(self._config, "ssh_quick_commands", None) or []:
72
+ if isinstance(x, dict):
73
+ lab = str(x.get("label", "")).strip()
74
+ cmd = str(x.get("command", "")).strip()
75
+ if lab or cmd:
76
+ lines.append(f"{lab} | {cmd}")
77
+ self.quick_edit.setPlainText("\n".join(lines))
78
+ self.quick_edit.setPlaceholderText("Example:\nList disks | lsblk\nEdit fstab | sudo nano /etc/fstab")
79
+ self.quick_edit.setMinimumHeight(120)
80
+ sf.addWidget(self.quick_edit)
81
+ root.addWidget(ssh)
82
+
83
+ buttons = QDialogButtonBox(QDialogButtonBox.Save | QDialogButtonBox.Cancel)
84
+ buttons.accepted.connect(self._save)
85
+ buttons.rejected.connect(self.reject)
86
+ root.addWidget(buttons)
87
+
88
+ def _browse_adb(self):
89
+ path, _ = QFileDialog.getOpenFileName(self, "Select adb", str(Path.home()))
90
+ if path:
91
+ self.adb_edit.setText(path)
92
+
93
+ def _browse_scrcpy(self):
94
+ path, _ = QFileDialog.getOpenFileName(self, "Select scrcpy", str(Path.home()))
95
+ if path:
96
+ self.scrcpy_edit.setText(path)
97
+
98
+ def _parse_quick_commands(self) -> list:
99
+ out = []
100
+ for line in self.quick_edit.toPlainText().splitlines():
101
+ line = line.strip()
102
+ if not line or line.startswith("#"):
103
+ continue
104
+ if "|" not in line:
105
+ continue
106
+ lab, _, cmd = line.partition("|")
107
+ lab = lab.strip()
108
+ cmd = cmd.strip()
109
+ if lab or cmd:
110
+ out.append({"label": lab or "Run", "command": cmd})
111
+ return out
112
+
113
+ def _save(self):
114
+ self._config.adb_path = self.adb_edit.text().strip()
115
+ self._config.scrcpy_path = self.scrcpy_edit.text().strip()
116
+ self._config.ssh_quick_commands = self._parse_quick_commands()
117
+ try:
118
+ self._config.save()
119
+ except Exception as exc:
120
+ QMessageBox.warning(self, "Save failed", str(exc))
121
+ return
122
+ self.accept()