robotframework-mind 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.
- robot_mind.py +442 -0
- robot_mind_app/__init__.py +2 -0
- robot_mind_app/__main__.py +105 -0
- robot_mind_app/community_panel.py +106 -0
- robot_mind_app/editors.py +59 -0
- robot_mind_app/engine.py +24 -0
- robot_mind_app/folders.py +52 -0
- robot_mind_app/graph.py +140 -0
- robot_mind_app/graph_layout.py +97 -0
- robot_mind_app/graph_view.py +244 -0
- robot_mind_app/icons.py +141 -0
- robot_mind_app/lucide.py +71 -0
- robot_mind_app/settings.py +84 -0
- robot_mind_app/theme.py +204 -0
- robot_mind_app/widgets.py +157 -0
- robot_mind_app/window.py +621 -0
- robot_mind_app/worker.py +100 -0
- robotframework_mind-0.1.1.dist-info/METADATA +123 -0
- robotframework_mind-0.1.1.dist-info/RECORD +23 -0
- robotframework_mind-0.1.1.dist-info/WHEEL +5 -0
- robotframework_mind-0.1.1.dist-info/entry_points.txt +2 -0
- robotframework_mind-0.1.1.dist-info/licenses/NOTICE +9 -0
- robotframework_mind-0.1.1.dist-info/top_level.txt +2 -0
robot_mind_app/window.py
ADDED
|
@@ -0,0 +1,621 @@
|
|
|
1
|
+
"""Main window: a sidebar (repo + saved + folders + recent), a query bar, and a styled results table."""
|
|
2
|
+
import shutil
|
|
3
|
+
import subprocess
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from PySide6.QtCore import QSettings, QSize, Qt, QUrl
|
|
8
|
+
from PySide6.QtGui import QAction, QActionGroup, QColor, QDesktopServices
|
|
9
|
+
from PySide6.QtWidgets import (QAbstractItemView, QApplication, QFileDialog, QFrame,
|
|
10
|
+
QHBoxLayout, QHeaderView, QLineEdit, QListWidget, QListWidgetItem,
|
|
11
|
+
QMainWindow, QMenu, QPushButton, QSizePolicy, QSpinBox, QStackedWidget,
|
|
12
|
+
QTableWidget, QTableWidgetItem, QToolButton, QVBoxLayout, QWidget)
|
|
13
|
+
|
|
14
|
+
from robot_mind import strip_controls
|
|
15
|
+
|
|
16
|
+
from . import editors, engine
|
|
17
|
+
from .folders import FolderTree
|
|
18
|
+
from .graph_layout import Drawing, plan
|
|
19
|
+
from .graph_view import GraphView
|
|
20
|
+
from .icons import ICON_SIZE, app_icon, icon
|
|
21
|
+
from .settings import AppSettings, check_program, editor_url, open_in_editor
|
|
22
|
+
from .theme import THEME_ICONS, THEME_MODES, apply_theme
|
|
23
|
+
from .widgets import EmptyState, card, plain_label, segmented, shade
|
|
24
|
+
from .worker import Worker
|
|
25
|
+
|
|
26
|
+
APP_NAME = "Robot Framework Mind"
|
|
27
|
+
ORG = "robotframework-mind"
|
|
28
|
+
# command key: (button label, what it finds, search box hint)
|
|
29
|
+
COMMAND_INFO = {
|
|
30
|
+
"ticket": ("Ticket", "Tests and keywords whose tags, name or docs mention it", "ticket key or word, e.g. PROJ-2120"),
|
|
31
|
+
"kw": ("Keyword", "Where a keyword is defined", "keyword name, e.g. Open Cases Page"),
|
|
32
|
+
"callers": ("Who calls it", "Every place a keyword is called, with the line", "keyword name"),
|
|
33
|
+
"tag": ("Tag", "Tests and keywords with this exact tag; end with * for a prefix", "tag, e.g. smoke or role:*"),
|
|
34
|
+
"find": ("Anything", "Any name, tag, doc, argument or value that contains it", "any text, e.g. /api/items"),
|
|
35
|
+
}
|
|
36
|
+
COMMANDS = tuple(COMMAND_INFO)
|
|
37
|
+
KIND_TOKENS = {"test": "accent_text", "keyword": "ok", "var": "warn", "json": "ink2"}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@dataclass(frozen=True)
|
|
41
|
+
class FoundRepos:
|
|
42
|
+
"""The worker's answer to "which repos does this folder hold?"."""
|
|
43
|
+
root: str
|
|
44
|
+
repos: list[str]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def hit_detail(hit) -> str:
|
|
48
|
+
"""The detail column: tags for a test, signature and doc for a keyword, value otherwise."""
|
|
49
|
+
if hit.kind == "test":
|
|
50
|
+
return " ".join(hit.tags)
|
|
51
|
+
if hit.kind == "keyword":
|
|
52
|
+
args = f"({hit.args})" if hit.args else ""
|
|
53
|
+
doc = f" - {hit.doc}" if hit.doc else ""
|
|
54
|
+
return args + doc
|
|
55
|
+
return hit.value
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class MainWindow(QMainWindow):
|
|
59
|
+
DISPLAY_LIMIT = 500
|
|
60
|
+
GRAPH_LIMIT = 80 # nodes drawn at most; more than that stops reading as a picture
|
|
61
|
+
|
|
62
|
+
def __init__(self, worker=None, settings=None, targets=(), task=None, cache_dir=None):
|
|
63
|
+
super().__init__()
|
|
64
|
+
self.worker = worker or Worker()
|
|
65
|
+
self.settings = settings if settings is not None else QSettings(ORG, APP_NAME)
|
|
66
|
+
self.saved = AppSettings(self.settings)
|
|
67
|
+
mode = self.settings.value("theme", "system")
|
|
68
|
+
self.theme_mode = mode if mode in THEME_MODES else "system"
|
|
69
|
+
self.t = apply_theme(QApplication.instance(), self.theme_mode)
|
|
70
|
+
self.cache_dir = cache_dir
|
|
71
|
+
self.repo = None
|
|
72
|
+
self.repo_list = [] # repos inside the chosen folder, when it holds several
|
|
73
|
+
self.mode = "table"
|
|
74
|
+
self._status_base = ""
|
|
75
|
+
self.setWindowTitle(APP_NAME)
|
|
76
|
+
self.setWindowIcon(app_icon())
|
|
77
|
+
self._build()
|
|
78
|
+
self.set_command(COMMANDS[0])
|
|
79
|
+
self.refresh_repos()
|
|
80
|
+
self.refresh_history()
|
|
81
|
+
self.worker.finished.connect(self._finished)
|
|
82
|
+
self.worker.failed.connect(self._failed)
|
|
83
|
+
if hasattr(self.worker, "timed"):
|
|
84
|
+
self.worker.timed.connect(self._timed)
|
|
85
|
+
self.resize(1180, 760)
|
|
86
|
+
|
|
87
|
+
# ---------------------------------------------------------------- layout
|
|
88
|
+
def _build(self):
|
|
89
|
+
central = QWidget()
|
|
90
|
+
central.setObjectName("app")
|
|
91
|
+
row = QHBoxLayout(central)
|
|
92
|
+
row.setContentsMargins(0, 0, 0, 0)
|
|
93
|
+
row.setSpacing(0)
|
|
94
|
+
row.addWidget(self._sidebar())
|
|
95
|
+
row.addWidget(self._main(), 1)
|
|
96
|
+
self.setCentralWidget(central)
|
|
97
|
+
|
|
98
|
+
def _sidebar(self):
|
|
99
|
+
sidebar = QFrame()
|
|
100
|
+
sidebar.setObjectName("sidebar")
|
|
101
|
+
sidebar.setFixedWidth(280)
|
|
102
|
+
col = QVBoxLayout(sidebar)
|
|
103
|
+
col.setContentsMargins(16, 18, 16, 14)
|
|
104
|
+
col.setSpacing(10)
|
|
105
|
+
|
|
106
|
+
brand = QHBoxLayout()
|
|
107
|
+
brand.setSpacing(10)
|
|
108
|
+
self.brand_mark = plain_label()
|
|
109
|
+
self.brand_mark.setFixedSize(24, 24)
|
|
110
|
+
self.brand_mark.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
111
|
+
self._brand_icon()
|
|
112
|
+
brand.addWidget(self.brand_mark)
|
|
113
|
+
brand.addWidget(plain_label("Robot Framework Mind", "brand"), 1)
|
|
114
|
+
col.addLayout(brand)
|
|
115
|
+
col.addWidget(plain_label("Exact lookups, one file:line per hit", "hint"))
|
|
116
|
+
col.addSpacing(6)
|
|
117
|
+
|
|
118
|
+
self.choose_button = QPushButton("Choose repo")
|
|
119
|
+
self.choose_button.setObjectName("primary")
|
|
120
|
+
self.choose_button.clicked.connect(self.choose_repo)
|
|
121
|
+
col.addWidget(self.choose_button)
|
|
122
|
+
col.addSpacing(6)
|
|
123
|
+
|
|
124
|
+
col.addWidget(plain_label("Saved repos", "label"))
|
|
125
|
+
self.repos_hint = plain_label("No saved repos yet", "hint")
|
|
126
|
+
col.addWidget(self.repos_hint)
|
|
127
|
+
self.repos_list = QListWidget()
|
|
128
|
+
self.repos_list.setObjectName("nav")
|
|
129
|
+
self.repos_list.itemClicked.connect(lambda item: self.set_repo(item.data(Qt.ItemDataRole.UserRole)))
|
|
130
|
+
col.addWidget(self.repos_list, 2)
|
|
131
|
+
|
|
132
|
+
self.folders_toggle = QToolButton() # shown only when the folder holds two repos or more
|
|
133
|
+
self.folders_toggle.setObjectName("folders_toggle")
|
|
134
|
+
self.folders_toggle.setCheckable(True)
|
|
135
|
+
self.folders_toggle.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon)
|
|
136
|
+
self.folders_toggle.setToolTip("Untick a repo to leave it out of the search")
|
|
137
|
+
self.folders_toggle.toggled.connect(self._folders_look)
|
|
138
|
+
self.folders_toggle.setHidden(True)
|
|
139
|
+
self.folders = FolderTree()
|
|
140
|
+
self.folders.itemChanged.connect(lambda *_: self._folders_look())
|
|
141
|
+
col.addWidget(self.folders_toggle)
|
|
142
|
+
col.addWidget(self.folders, 3)
|
|
143
|
+
|
|
144
|
+
col.addWidget(plain_label("Recent", "label"))
|
|
145
|
+
self.history_hint = plain_label("No recent queries", "hint")
|
|
146
|
+
col.addWidget(self.history_hint)
|
|
147
|
+
self.history_list = QListWidget()
|
|
148
|
+
self.history_list.setObjectName("nav")
|
|
149
|
+
self.history_list.itemClicked.connect(
|
|
150
|
+
lambda item: self.run_history(*item.data(Qt.ItemDataRole.UserRole)))
|
|
151
|
+
col.addWidget(self.history_list, 2)
|
|
152
|
+
|
|
153
|
+
col.addStretch(1)
|
|
154
|
+
bottom = QHBoxLayout()
|
|
155
|
+
bottom.setSpacing(6)
|
|
156
|
+
self.theme_action = QAction("Theme", self)
|
|
157
|
+
self.theme_action.triggered.connect(self.next_theme)
|
|
158
|
+
self.theme_button = QToolButton()
|
|
159
|
+
self.theme_button.setObjectName("theme")
|
|
160
|
+
self.theme_button.setDefaultAction(self.theme_action)
|
|
161
|
+
self.theme_button.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonIconOnly)
|
|
162
|
+
self.theme_button.setIconSize(ICON_SIZE)
|
|
163
|
+
self.theme_button.setAccessibleName("Theme")
|
|
164
|
+
self.editor_button = QPushButton("Editor")
|
|
165
|
+
self.editor_button.setToolTip("Which program Open uses to show a result")
|
|
166
|
+
self._editor_menu()
|
|
167
|
+
bottom.addWidget(self.theme_button)
|
|
168
|
+
bottom.addWidget(self.editor_button)
|
|
169
|
+
bottom.addStretch(1)
|
|
170
|
+
col.addLayout(bottom)
|
|
171
|
+
self._theme_look()
|
|
172
|
+
return sidebar
|
|
173
|
+
|
|
174
|
+
def _main(self):
|
|
175
|
+
ground = QWidget()
|
|
176
|
+
ground.setObjectName("ground")
|
|
177
|
+
outer = QVBoxLayout(ground)
|
|
178
|
+
outer.setContentsMargins(22, 18, 22, 12)
|
|
179
|
+
outer.setSpacing(12)
|
|
180
|
+
|
|
181
|
+
top = QWidget()
|
|
182
|
+
top_col = QVBoxLayout(top)
|
|
183
|
+
top_col.setContentsMargins(14, 0, 14, 0)
|
|
184
|
+
top_col.setSpacing(12)
|
|
185
|
+
self.page_title = plain_label("No repo selected", "pagetitle")
|
|
186
|
+
self.page_sub = plain_label("Choose a repo to index its tests, keywords and docs", "hint")
|
|
187
|
+
top_col.addWidget(self.page_title)
|
|
188
|
+
top_col.addWidget(self.page_sub)
|
|
189
|
+
top_col.addWidget(self._query_bar())
|
|
190
|
+
self.command_hint = plain_label("", "hint")
|
|
191
|
+
top_col.addWidget(self.command_hint)
|
|
192
|
+
outer.addWidget(top)
|
|
193
|
+
|
|
194
|
+
self.empty_state = EmptyState(self.t, "scan-search", "Ready when you are",
|
|
195
|
+
"Choose a repo on the left, then search a ticket, keyword, tag or endpoint.")
|
|
196
|
+
self.results = QTableWidget(0, 4)
|
|
197
|
+
self.results.setHorizontalHeaderLabels(["Kind", "Name", "Location", "Detail"])
|
|
198
|
+
self.results.verticalHeader().setVisible(False)
|
|
199
|
+
self.results.setShowGrid(False)
|
|
200
|
+
self.results.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
|
|
201
|
+
self.results.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers)
|
|
202
|
+
self.results.setWordWrap(False)
|
|
203
|
+
self.results.setIconSize(QSize(12, 12))
|
|
204
|
+
self.results.verticalHeader().setDefaultSectionSize(34)
|
|
205
|
+
header = self.results.horizontalHeader()
|
|
206
|
+
header.setSectionResizeMode(0, QHeaderView.ResizeMode.ResizeToContents)
|
|
207
|
+
header.setSectionResizeMode(1, QHeaderView.ResizeMode.Interactive)
|
|
208
|
+
header.setSectionResizeMode(2, QHeaderView.ResizeMode.Interactive)
|
|
209
|
+
header.setSectionResizeMode(3, QHeaderView.ResizeMode.Stretch)
|
|
210
|
+
header.setFixedHeight(34)
|
|
211
|
+
self.results.setColumnWidth(1, 250)
|
|
212
|
+
self.results.setColumnWidth(2, 300)
|
|
213
|
+
self.graph_view = GraphView(self.t)
|
|
214
|
+
self.graph_view.activated.connect(lambda _node: self.open_selected())
|
|
215
|
+
self.stack = QStackedWidget()
|
|
216
|
+
self.stack.addWidget(self.empty_state)
|
|
217
|
+
self.stack.addWidget(self.results)
|
|
218
|
+
self.stack.addWidget(self.graph_view)
|
|
219
|
+
self.results_holder = card(self._results_pane(), self.t)
|
|
220
|
+
self.cards = [self.results_holder]
|
|
221
|
+
outer.addWidget(self.results_holder, 1)
|
|
222
|
+
self.status = plain_label("", "hint")
|
|
223
|
+
status_wrap = QWidget()
|
|
224
|
+
status_col = QVBoxLayout(status_wrap)
|
|
225
|
+
status_col.setContentsMargins(14, 0, 14, 0)
|
|
226
|
+
status_col.addWidget(self.status)
|
|
227
|
+
outer.addWidget(status_wrap)
|
|
228
|
+
return ground
|
|
229
|
+
|
|
230
|
+
def _query_bar(self):
|
|
231
|
+
box = QFrame()
|
|
232
|
+
box.setObjectName("bar")
|
|
233
|
+
self.query_bar = box
|
|
234
|
+
row = QHBoxLayout(box)
|
|
235
|
+
row.setContentsMargins(10, 8, 10, 8)
|
|
236
|
+
row.setSpacing(8)
|
|
237
|
+
self.command = QPushButton()
|
|
238
|
+
self.command.setObjectName("command")
|
|
239
|
+
self.command.setFixedWidth(140)
|
|
240
|
+
self.command.setToolTip("What to search for")
|
|
241
|
+
self.command_menu = QMenu(self.command)
|
|
242
|
+
for key, (label, what, _hint) in COMMAND_INFO.items():
|
|
243
|
+
action = self.command_menu.addAction(f"{label}\t{what}") # the tab puts the description right
|
|
244
|
+
action.setData(key)
|
|
245
|
+
action.triggered.connect(lambda _=False, k=key: self.set_command(k))
|
|
246
|
+
self.command.setMenu(self.command_menu)
|
|
247
|
+
self.term = QLineEdit()
|
|
248
|
+
self.term.returnPressed.connect(self.search)
|
|
249
|
+
self.limit = QSpinBox()
|
|
250
|
+
self.limit.setRange(1, self.DISPLAY_LIMIT)
|
|
251
|
+
self.limit.setValue(self.DISPLAY_LIMIT)
|
|
252
|
+
self.limit.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
253
|
+
self.limit.setFixedWidth(76)
|
|
254
|
+
self.limit.setToolTip("Most rows to show")
|
|
255
|
+
self.search_button = QPushButton("Search")
|
|
256
|
+
self.search_button.setObjectName("primary")
|
|
257
|
+
self.search_button.clicked.connect(self.search)
|
|
258
|
+
row.addWidget(self.command)
|
|
259
|
+
row.addWidget(self.term, 1)
|
|
260
|
+
self.rows_label = plain_label("rows", "hint")
|
|
261
|
+
row.addWidget(self.rows_label)
|
|
262
|
+
row.addWidget(self.limit)
|
|
263
|
+
row.addWidget(self.search_button)
|
|
264
|
+
return box
|
|
265
|
+
|
|
266
|
+
def _results_pane(self):
|
|
267
|
+
pane = QWidget()
|
|
268
|
+
column = QVBoxLayout(pane)
|
|
269
|
+
column.setContentsMargins(12, 10, 12, 10)
|
|
270
|
+
column.setSpacing(8)
|
|
271
|
+
head = QHBoxLayout()
|
|
272
|
+
head.setSpacing(8)
|
|
273
|
+
self.count_chip = plain_label("0 hits", "hint") # a caption under the header, not a pill inside it
|
|
274
|
+
self.filter = QLineEdit()
|
|
275
|
+
self.filter.setPlaceholderText("filter by tag, name or text")
|
|
276
|
+
self.filter.textChanged.connect(self._apply_filter)
|
|
277
|
+
self.copy_button = QPushButton("Copy")
|
|
278
|
+
self.copy_button.setToolTip("Copy the selected hit")
|
|
279
|
+
self.copy_button.clicked.connect(self.copy_selected)
|
|
280
|
+
self.open_button = QPushButton("Open")
|
|
281
|
+
self.open_button.setToolTip("Open the selected hit at its line in the editor")
|
|
282
|
+
self.open_button.clicked.connect(self.open_selected)
|
|
283
|
+
self.modes = QActionGroup(self)
|
|
284
|
+
for name in ("Table", "Graph"):
|
|
285
|
+
action = self.modes.addAction(name)
|
|
286
|
+
action.setCheckable(True)
|
|
287
|
+
action.setChecked(name == "Table")
|
|
288
|
+
action.triggered.connect(lambda _=False, n=name.lower(): self.set_mode(n))
|
|
289
|
+
head.addWidget(segmented(self.modes.actions()))
|
|
290
|
+
head.addWidget(self.filter, 1)
|
|
291
|
+
head.addStretch(0) # takes the filter's room when Graph mode hides it
|
|
292
|
+
head.addWidget(self.copy_button)
|
|
293
|
+
head.addWidget(self.open_button)
|
|
294
|
+
column.addLayout(head)
|
|
295
|
+
column.addWidget(self.count_chip)
|
|
296
|
+
self.banner = plain_label("", "banner") # a failure shows here, where the eyes are
|
|
297
|
+
self.banner.setWordWrap(True)
|
|
298
|
+
self.banner.setHidden(True)
|
|
299
|
+
column.addWidget(self.banner)
|
|
300
|
+
column.addWidget(self.stack, 1)
|
|
301
|
+
return pane
|
|
302
|
+
|
|
303
|
+
def show_error(self, text):
|
|
304
|
+
self.banner.setText(strip_controls(text[:300]))
|
|
305
|
+
self.banner.setHidden(False)
|
|
306
|
+
|
|
307
|
+
# ---------------------------------------------------------------- repo and theme
|
|
308
|
+
def choose_repo(self):
|
|
309
|
+
path = QFileDialog.getExistingDirectory(self, "Choose a robot repo", self.repo or "")
|
|
310
|
+
if path:
|
|
311
|
+
self.set_repo(path)
|
|
312
|
+
self.saved.add_repo(self.repo)
|
|
313
|
+
self.refresh_repos()
|
|
314
|
+
|
|
315
|
+
def set_repo(self, path):
|
|
316
|
+
self.repo = str(path)
|
|
317
|
+
name = Path(self.repo).name or self.repo
|
|
318
|
+
self.page_title.setText(name)
|
|
319
|
+
self.page_title.setToolTip(self.repo)
|
|
320
|
+
self.page_sub.setText(self.repo)
|
|
321
|
+
self._brand_icon()
|
|
322
|
+
self.results.setRowCount(0)
|
|
323
|
+
self.count_chip.setText("0 hits")
|
|
324
|
+
self._status_base = f"Ready - {name}"
|
|
325
|
+
self.status.setText(self._status_base)
|
|
326
|
+
self.empty_state.show_text("Ready when you are",
|
|
327
|
+
f"Search {name} for a ticket, keyword, tag or endpoint.")
|
|
328
|
+
self.stack.setCurrentWidget(self.empty_state)
|
|
329
|
+
self.banner.setHidden(True)
|
|
330
|
+
self.repo_list = []
|
|
331
|
+
self.folders.set_repos([])
|
|
332
|
+
self.folders_toggle.setChecked(False)
|
|
333
|
+
self.folders_toggle.setHidden(True)
|
|
334
|
+
self._folders_look()
|
|
335
|
+
root = self.repo # which repos it holds is a folder walk: worker thread
|
|
336
|
+
self.worker.submit(lambda: FoundRepos(root, engine.repos(root)), self.worker.reserve())
|
|
337
|
+
|
|
338
|
+
def show_folders(self, found):
|
|
339
|
+
if found.root != self.repo: # an answer for a folder the user has already left
|
|
340
|
+
return
|
|
341
|
+
self.repo_list = found.repos
|
|
342
|
+
self.folders.set_repos(found.repos)
|
|
343
|
+
self.folders_toggle.setHidden(len(found.repos) < 2)
|
|
344
|
+
self._folders_look()
|
|
345
|
+
|
|
346
|
+
def _folders_look(self):
|
|
347
|
+
"""Collapsed by default: a count and an arrow; open, the tree of repos to untick."""
|
|
348
|
+
shown = self.folders_toggle.isChecked() and not self.folders_toggle.isHidden()
|
|
349
|
+
self.folders.setHidden(not shown)
|
|
350
|
+
self.folders_toggle.setArrowType(Qt.ArrowType.DownArrow if shown else Qt.ArrowType.RightArrow)
|
|
351
|
+
picked = self.folders.scope()
|
|
352
|
+
count = len(self.repo_list) if picked is None else f"{len(picked)} of {len(self.repo_list)}"
|
|
353
|
+
self.folders_toggle.setText(f"Folders ({count} repos)")
|
|
354
|
+
|
|
355
|
+
def scope(self):
|
|
356
|
+
return self.folders.scope()
|
|
357
|
+
|
|
358
|
+
def refresh_repos(self):
|
|
359
|
+
self.repos_list.clear()
|
|
360
|
+
repos = self.saved.repos()
|
|
361
|
+
for repo in repos:
|
|
362
|
+
item = QListWidgetItem(Path(repo).name or repo)
|
|
363
|
+
item.setData(Qt.ItemDataRole.UserRole, repo)
|
|
364
|
+
item.setToolTip(repo)
|
|
365
|
+
self.repos_list.addItem(item)
|
|
366
|
+
self.repos_list.setVisible(bool(repos))
|
|
367
|
+
self.repos_hint.setVisible(not repos)
|
|
368
|
+
|
|
369
|
+
def _editor_menu(self):
|
|
370
|
+
"""Editors found on this machine, the system default, and any other program picked from disk."""
|
|
371
|
+
self.editor_menu = QMenu(self.editor_button)
|
|
372
|
+
self.editor_menu.setToolTipsVisible(True)
|
|
373
|
+
self.editor_menu.aboutToShow.connect(self._fill_editor_menu)
|
|
374
|
+
self.editor_button.setMenu(self.editor_menu)
|
|
375
|
+
self._fill_editor_menu()
|
|
376
|
+
self._editor_look()
|
|
377
|
+
|
|
378
|
+
def _fill_editor_menu(self):
|
|
379
|
+
self.editor_menu.clear()
|
|
380
|
+
current = self.saved.editor_command()
|
|
381
|
+
for editor in editors.available():
|
|
382
|
+
action = self.editor_menu.addAction(editor.label)
|
|
383
|
+
action.setCheckable(True)
|
|
384
|
+
action.setChecked(editor.command == current)
|
|
385
|
+
action.triggered.connect(lambda _=False, c=editor.command: self.set_editor(c))
|
|
386
|
+
self.editor_menu.addSeparator()
|
|
387
|
+
other = self.editor_menu.addAction("Other program...")
|
|
388
|
+
other.setToolTip("Pick an .exe; it gets the file (no jump to the line)")
|
|
389
|
+
other.triggered.connect(self.pick_editor_program)
|
|
390
|
+
|
|
391
|
+
def pick_editor_program(self):
|
|
392
|
+
path, _ = QFileDialog.getOpenFileName(self, "Program to open files with", "", "Programs (*.exe);;All files (*)")
|
|
393
|
+
if path:
|
|
394
|
+
self.set_editor(editors.program_command(path))
|
|
395
|
+
|
|
396
|
+
def set_editor(self, command):
|
|
397
|
+
self.saved.set_editor_command(command)
|
|
398
|
+
self._editor_look()
|
|
399
|
+
|
|
400
|
+
def _editor_look(self):
|
|
401
|
+
self.editor_button.setText(f"Editor: {editors.label_for(self.saved.editor_command())}")
|
|
402
|
+
|
|
403
|
+
def set_theme(self, mode, save=True):
|
|
404
|
+
self.theme_mode = mode if mode in THEME_MODES else "system"
|
|
405
|
+
if save:
|
|
406
|
+
self.settings.setValue("theme", self.theme_mode)
|
|
407
|
+
self.t = apply_theme(QApplication.instance(), self.theme_mode)
|
|
408
|
+
self.empty_state.retheme(self.t)
|
|
409
|
+
self.graph_view.retheme(self.t)
|
|
410
|
+
for holder in self.cards:
|
|
411
|
+
shade(holder.frame, self.t)
|
|
412
|
+
self._theme_look()
|
|
413
|
+
self._brand_icon()
|
|
414
|
+
self._recolor_kinds()
|
|
415
|
+
|
|
416
|
+
def next_theme(self):
|
|
417
|
+
self.set_theme(THEME_MODES[(THEME_MODES.index(self.theme_mode) + 1) % len(THEME_MODES)])
|
|
418
|
+
|
|
419
|
+
def _theme_look(self):
|
|
420
|
+
self.theme_action.setIcon(icon(THEME_ICONS[self.theme_mode], self.t["ink2"]))
|
|
421
|
+
self.theme_action.setToolTip(f"Theme: {self.theme_mode.title()} (click to change)")
|
|
422
|
+
|
|
423
|
+
def _brand_icon(self):
|
|
424
|
+
ratio = self.devicePixelRatioF()
|
|
425
|
+
self.brand_mark.setPixmap(icon("target", self.t["accent"]).pixmap(QSize(20, 20), ratio))
|
|
426
|
+
|
|
427
|
+
# ---------------------------------------------------------------- work
|
|
428
|
+
def search(self):
|
|
429
|
+
if not self.repo:
|
|
430
|
+
self._status_base = "Please pick a repo first"
|
|
431
|
+
self.status.setText(self._status_base)
|
|
432
|
+
self.empty_state.show_text("Please pick a repo first",
|
|
433
|
+
"Click Choose repo on the left (or a saved repo), then search again.")
|
|
434
|
+
self.stack.setCurrentWidget(self.empty_state)
|
|
435
|
+
return None
|
|
436
|
+
command, term = self.command_key, self.term.text()
|
|
437
|
+
self.saved.add_history(command, term)
|
|
438
|
+
self.refresh_history()
|
|
439
|
+
job = self.worker.reserve()
|
|
440
|
+
self._status_base = f"Searching {COMMAND_INFO[command][0].lower()} {term}..."
|
|
441
|
+
self.status.setText(self._status_base)
|
|
442
|
+
self.banner.setHidden(True)
|
|
443
|
+
self.empty_state.show_text("Searching...", "Reading the index; results show when it finishes.")
|
|
444
|
+
self.stack.setCurrentWidget(self.empty_state)
|
|
445
|
+
repo, cache, scope, limit = self.repo, self.cache_dir, self.scope(), self.GRAPH_LIMIT
|
|
446
|
+
repos = list(self.repo_list)
|
|
447
|
+
if self.mode == "graph": # the layout is computed on the worker too, never on the UI thread
|
|
448
|
+
return self.worker.submit(
|
|
449
|
+
lambda: plan(engine.graph(repo, command, term, cache_dir=cache, scope=scope), limit, repos), job)
|
|
450
|
+
return self.worker.submit(lambda: engine.query(repo, command, term, cache_dir=cache, scope=scope), job)
|
|
451
|
+
|
|
452
|
+
def _finished(self, job, result):
|
|
453
|
+
if isinstance(result, FoundRepos):
|
|
454
|
+
self.show_folders(result)
|
|
455
|
+
elif isinstance(result, Drawing):
|
|
456
|
+
self.set_graph(result)
|
|
457
|
+
else:
|
|
458
|
+
self.set_results(result)
|
|
459
|
+
|
|
460
|
+
def set_mode(self, mode):
|
|
461
|
+
"""table or graph; a search already typed runs again in the new mode."""
|
|
462
|
+
self.mode = mode
|
|
463
|
+
next(a for a in self.modes.actions() if a.text().lower() == mode).setChecked(True)
|
|
464
|
+
for widget in (self.filter, self.rows_label, self.limit): # table-only controls
|
|
465
|
+
widget.setHidden(mode == "graph")
|
|
466
|
+
if self.repo and self.term.text().strip():
|
|
467
|
+
self.search()
|
|
468
|
+
|
|
469
|
+
def set_graph(self, drawing):
|
|
470
|
+
shown = drawing.graph
|
|
471
|
+
if not shown.nodes:
|
|
472
|
+
self.set_results([])
|
|
473
|
+
return
|
|
474
|
+
self.graph_view.show_graph(drawing)
|
|
475
|
+
self.stack.setCurrentWidget(self.graph_view)
|
|
476
|
+
self.count_chip.setText(f"{len(shown.nodes)} of {drawing.total} nodes")
|
|
477
|
+
capped = " - the nearest to your search; narrow it to see the rest" if len(shown.nodes) < drawing.total else ""
|
|
478
|
+
self._status_base = f"{len(shown.nodes)} nodes, {len(shown.edges)} links{capped}"
|
|
479
|
+
self.status.setText(self._status_base)
|
|
480
|
+
|
|
481
|
+
def _failed(self, job, text):
|
|
482
|
+
self._status_base = strip_controls(text[:200])
|
|
483
|
+
self.status.setText(self._status_base)
|
|
484
|
+
self.show_error(f"Something went wrong: {text}")
|
|
485
|
+
if self.stack.currentWidget() is self.empty_state:
|
|
486
|
+
self.empty_state.show_text("No results", "The search stopped; see the message above.")
|
|
487
|
+
|
|
488
|
+
def _timed(self, job, seconds):
|
|
489
|
+
if self._status_base:
|
|
490
|
+
self.status.setText(f"{self._status_base} in {round(seconds * 1000)} ms")
|
|
491
|
+
|
|
492
|
+
def refresh_history(self):
|
|
493
|
+
self.history_list.clear()
|
|
494
|
+
history = self.saved.history()
|
|
495
|
+
for command, term in history:
|
|
496
|
+
item = QListWidgetItem(f"{COMMAND_INFO.get(command, (command,))[0]}: {term}")
|
|
497
|
+
item.setData(Qt.ItemDataRole.UserRole, (command, term))
|
|
498
|
+
self.history_list.addItem(item)
|
|
499
|
+
self.history_list.setVisible(bool(history))
|
|
500
|
+
self.history_hint.setVisible(not history)
|
|
501
|
+
|
|
502
|
+
def run_history(self, command, term):
|
|
503
|
+
self.set_command(command)
|
|
504
|
+
self.term.setText(term)
|
|
505
|
+
self.search()
|
|
506
|
+
|
|
507
|
+
def set_command(self, key):
|
|
508
|
+
if key not in COMMAND_INFO:
|
|
509
|
+
return
|
|
510
|
+
label, what, hint = COMMAND_INFO[key]
|
|
511
|
+
self.command_key = key
|
|
512
|
+
self.command.setText(label)
|
|
513
|
+
self.term.setPlaceholderText(hint)
|
|
514
|
+
self.command_hint.setText(f"{label}: {what}")
|
|
515
|
+
|
|
516
|
+
def _kind_color(self, kind):
|
|
517
|
+
return self.t.get(KIND_TOKENS.get(kind, "ink2"), self.t["ink2"])
|
|
518
|
+
|
|
519
|
+
def set_results(self, hits):
|
|
520
|
+
self.results.setRowCount(0)
|
|
521
|
+
self.filter.clear()
|
|
522
|
+
shown = hits[: self.limit.value()]
|
|
523
|
+
for hit in shown:
|
|
524
|
+
row = self.results.rowCount()
|
|
525
|
+
self.results.insertRow(row)
|
|
526
|
+
for column, text in enumerate((hit.kind.capitalize(), hit.name, self._location(hit), hit_detail(hit))):
|
|
527
|
+
clean = strip_controls(str(text))
|
|
528
|
+
item = QTableWidgetItem(clean)
|
|
529
|
+
item.setToolTip(clean)
|
|
530
|
+
if column == 0:
|
|
531
|
+
item.setData(Qt.ItemDataRole.UserRole, hit)
|
|
532
|
+
item.setForeground(QColor(self._kind_color(hit.kind)))
|
|
533
|
+
item.setIcon(icon("circle-dot", self._kind_color(hit.kind)))
|
|
534
|
+
self.results.setItem(row, column, item)
|
|
535
|
+
if hits:
|
|
536
|
+
self.stack.setCurrentWidget(self.results)
|
|
537
|
+
extra = len(hits) - len(shown)
|
|
538
|
+
self.count_chip.setText(f"{len(hits)} hit" + ("" if len(hits) == 1 else "s"))
|
|
539
|
+
self._status_base = f"{len(shown)} shown" + (f" of {len(hits)}" if extra > 0 else "")
|
|
540
|
+
self.status.setText(self._status_base)
|
|
541
|
+
else:
|
|
542
|
+
self.empty_state.show_text("No match", "Nothing in this repo matched that lookup.")
|
|
543
|
+
self.stack.setCurrentWidget(self.empty_state)
|
|
544
|
+
self.count_chip.setText("0 hits")
|
|
545
|
+
self._status_base = "No match"
|
|
546
|
+
self.status.setText(self._status_base)
|
|
547
|
+
|
|
548
|
+
def _recolor_kinds(self):
|
|
549
|
+
for row in range(self.results.rowCount()):
|
|
550
|
+
item = self.results.item(row, 0)
|
|
551
|
+
hit = item.data(Qt.ItemDataRole.UserRole) if item else None
|
|
552
|
+
if hit is not None:
|
|
553
|
+
item.setForeground(QColor(self._kind_color(hit.kind)))
|
|
554
|
+
item.setIcon(icon("circle-dot", self._kind_color(hit.kind)))
|
|
555
|
+
|
|
556
|
+
def _apply_filter(self, term=""):
|
|
557
|
+
needle = term.strip().lower()
|
|
558
|
+
for row in range(self.results.rowCount()):
|
|
559
|
+
text = " ".join(self.results.item(row, c).text() if self.results.item(row, c) else ""
|
|
560
|
+
for c in range(self.results.columnCount())).lower()
|
|
561
|
+
self.results.setRowHidden(row, bool(needle) and needle not in text)
|
|
562
|
+
|
|
563
|
+
def _selected_hit(self):
|
|
564
|
+
row = self.results.currentRow()
|
|
565
|
+
if row < 0:
|
|
566
|
+
return None
|
|
567
|
+
item = self.results.item(row, 0)
|
|
568
|
+
return item.data(Qt.ItemDataRole.UserRole) if item else None
|
|
569
|
+
|
|
570
|
+
def _selected(self):
|
|
571
|
+
"""(kind, name, file, line) of the selected table row or graph node, or None."""
|
|
572
|
+
if self.stack.currentWidget() is self.graph_view:
|
|
573
|
+
node = self.graph_view.selected_node()
|
|
574
|
+
return (node.kind, node.label, node.file, node.line) if node else None
|
|
575
|
+
hit = self._selected_hit()
|
|
576
|
+
return (hit.kind, hit.name, hit.file, hit.call_line or hit.line) if hit else None
|
|
577
|
+
|
|
578
|
+
def copy_selected(self):
|
|
579
|
+
chosen = self._selected()
|
|
580
|
+
if chosen is None:
|
|
581
|
+
return
|
|
582
|
+
kind, name, file, line = chosen
|
|
583
|
+
QApplication.clipboard().setText(" ".join(part for part in (kind, name, where(file, line)) if part))
|
|
584
|
+
self.status.setText("Copied to clipboard")
|
|
585
|
+
|
|
586
|
+
def open_selected(self):
|
|
587
|
+
chosen = self._selected()
|
|
588
|
+
if chosen is None or not self.repo:
|
|
589
|
+
self.status.setText("Select a result first, then Open")
|
|
590
|
+
return
|
|
591
|
+
_kind, _name, file, line = chosen
|
|
592
|
+
if not file:
|
|
593
|
+
self.status.setText("An endpoint has no file to open")
|
|
594
|
+
return
|
|
595
|
+
try:
|
|
596
|
+
self._launch(file, line)
|
|
597
|
+
self.status.setText(f"Opened {where(file, line)}")
|
|
598
|
+
except (OSError, ValueError) as err:
|
|
599
|
+
self.show_error(f"Could not open the editor: {err}. Pick another with the Editor button, bottom left.")
|
|
600
|
+
|
|
601
|
+
def _launch(self, file, line):
|
|
602
|
+
command = self.saved.editor_command()
|
|
603
|
+
if command in editors.URL_EDITORS:
|
|
604
|
+
if not QDesktopServices.openUrl(QUrl(editor_url(self.repo, file, line, command))):
|
|
605
|
+
raise OSError(f"{editors.label_for(command)} is not installed")
|
|
606
|
+
return
|
|
607
|
+
if command == editors.DEFAULT_APP:
|
|
608
|
+
if not QDesktopServices.openUrl(QUrl.fromLocalFile(str(Path(self.repo) / file))):
|
|
609
|
+
raise OSError("no app is set for this kind of file")
|
|
610
|
+
return
|
|
611
|
+
argv = open_in_editor(file, line, command)
|
|
612
|
+
argv[0] = check_program(shutil.which(argv[0]) or argv[0])
|
|
613
|
+
subprocess.Popen(argv, cwd=self.repo)
|
|
614
|
+
|
|
615
|
+
@staticmethod
|
|
616
|
+
def _location(hit):
|
|
617
|
+
return where(hit.file, hit.call_line or hit.line)
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
def where(file, line):
|
|
621
|
+
return f"{file}:{line}" if line else file
|