vibefpmgui.references_panel

The "References" tab: every use of a name, from Find References.

Results are grouped by file (project files first, then dependencies), shown like the Search tab's (vibefpmgui.result_tree): each file with its icon, each use with its line in the editor's syntax colors and the name highlighted. Click one to open the file there.

 1"""The "References" tab: every use of a name, from Find References.
 2
 3Results are grouped by file (project files first, then dependencies), shown
 4like the *Search* tab's (`vibefpmgui.result_tree`): each file with its icon,
 5each use with its line in the editor's syntax colors and the name
 6highlighted. Click one to open the file there.
 7"""
 8
 9from __future__ import annotations
10
11from pathlib import Path
12
13from qtpy.QtCore import Signal
14from qtpy.QtWidgets import QLabel, QVBoxLayout, QWidget
15
16from .result_tree import ResultTree, Root, file_labels, make_match, root_for
17
18
19def short_path(path: Path, project_dir: Path | None) -> str:
20    if project_dir is not None:
21        try:
22            return str(path.relative_to(project_dir.resolve()))
23        except ValueError:
24            pass
25    return str(path)
26
27
28class ReferencesPanel(QWidget):
29    open_requested = Signal(str, int, int, int, int)  # file, line, column, end line, end column
30    keep_requested = Signal(str)  # a file to keep open (a result double-clicked)
31    HINT = "Use Find References (⇧F12) on a name in the editor to list its uses here."
32
33    def __init__(self, parent=None):
34        super().__init__(parent)
35        self.title = QLabel(self.HINT)
36        self.title.setWordWrap(True)
37        self.title.setContentsMargins(8, 6, 8, 2)
38        self.tree = ResultTree()
39        self.tree.open_requested.connect(self.open_requested)
40        self.tree.keep_requested.connect(self.keep_requested)
41        layout = QVBoxLayout(self)
42        layout.setContentsMargins(0, 0, 0, 0)
43        layout.setSpacing(2)
44        layout.addWidget(self.title)
45        layout.addWidget(self.tree, 1)
46
47    def reset(self):
48        """Another project was opened: no results."""
49        self.tree.clear_results()
50        self.title.setText(self.HINT)
51
52    def show_results(self, name: str, results: list[tuple[Path, int, int, int]], roots: list[Root],
53                     project_dir: Path | None):
54        """``results``: (file, 1-based line, start column, end column);
55        ``roots``: the packages, to label the dependencies' files."""
56        self.tree.clear_results()
57        files: dict[Path, list[tuple[int, int, int]]] = {}
58        for path, line, start, end in results:
59            files.setdefault(Path(path).resolve(), []).append((line, start, end))
60        if not results:
61            self.title.setText(f"No references to <b>{name}</b> found.")
62            return
63        self.title.setText(f"<b>{name}</b>: {len(results)} reference{'s' * (len(results) != 1)} "
64                           f"in {len(files)} file{'s' * (len(files) != 1)}")
65        rows = []
66        for path, places in files.items():
67            root = root_for(path, roots)
68            folder, package = file_labels(path, root, project_dir)
69            lines = self.tree.file_lines(path)
70            matches = [make_match(lines[line - 1] if 0 < line <= len(lines) else "", line, start, line, end)
71                       for line, start, end in sorted(places)]
72            outside = root is None or root.dependency  # (dependencies after the project's own files)
73            rows.append(((outside, package, folder, path.name), path, matches, folder, package))
74        for _key, path, matches, folder, package in sorted(rows, key=lambda r: r[0]):
75            self.tree.set_file(path, matches, folder, package)
def short_path(path: pathlib.Path, project_dir: pathlib.Path | None) -> str:
20def short_path(path: Path, project_dir: Path | None) -> str:
21    if project_dir is not None:
22        try:
23            return str(path.relative_to(project_dir.resolve()))
24        except ValueError:
25            pass
26    return str(path)
class ReferencesPanel(PySide6.QtWidgets.QWidget):
29class ReferencesPanel(QWidget):
30    open_requested = Signal(str, int, int, int, int)  # file, line, column, end line, end column
31    keep_requested = Signal(str)  # a file to keep open (a result double-clicked)
32    HINT = "Use Find References (⇧F12) on a name in the editor to list its uses here."
33
34    def __init__(self, parent=None):
35        super().__init__(parent)
36        self.title = QLabel(self.HINT)
37        self.title.setWordWrap(True)
38        self.title.setContentsMargins(8, 6, 8, 2)
39        self.tree = ResultTree()
40        self.tree.open_requested.connect(self.open_requested)
41        self.tree.keep_requested.connect(self.keep_requested)
42        layout = QVBoxLayout(self)
43        layout.setContentsMargins(0, 0, 0, 0)
44        layout.setSpacing(2)
45        layout.addWidget(self.title)
46        layout.addWidget(self.tree, 1)
47
48    def reset(self):
49        """Another project was opened: no results."""
50        self.tree.clear_results()
51        self.title.setText(self.HINT)
52
53    def show_results(self, name: str, results: list[tuple[Path, int, int, int]], roots: list[Root],
54                     project_dir: Path | None):
55        """``results``: (file, 1-based line, start column, end column);
56        ``roots``: the packages, to label the dependencies' files."""
57        self.tree.clear_results()
58        files: dict[Path, list[tuple[int, int, int]]] = {}
59        for path, line, start, end in results:
60            files.setdefault(Path(path).resolve(), []).append((line, start, end))
61        if not results:
62            self.title.setText(f"No references to <b>{name}</b> found.")
63            return
64        self.title.setText(f"<b>{name}</b>: {len(results)} reference{'s' * (len(results) != 1)} "
65                           f"in {len(files)} file{'s' * (len(files) != 1)}")
66        rows = []
67        for path, places in files.items():
68            root = root_for(path, roots)
69            folder, package = file_labels(path, root, project_dir)
70            lines = self.tree.file_lines(path)
71            matches = [make_match(lines[line - 1] if 0 < line <= len(lines) else "", line, start, line, end)
72                       for line, start, end in sorted(places)]
73            outside = root is None or root.dependency  # (dependencies after the project's own files)
74            rows.append(((outside, package, folder, path.name), path, matches, folder, package))
75        for _key, path, matches, folder, package in sorted(rows, key=lambda r: r[0]):
76            self.tree.set_file(path, matches, folder, package)

QWidget(self, /, parent: PySide6.QtWidgets.QWidget | None = None, f: PySide6.QtCore.Qt.WindowType = Default(Qt.WindowFlags), *, modal: bool | None = None, windowModality: PySide6.QtCore.Qt.WindowModality | None = None, enabled: bool | None = None, geometry: PySide6.QtCore.QRect | None = None, frameGeometry: PySide6.QtCore.QRect | None = None, normalGeometry: PySide6.QtCore.QRect | None = None, x: int | None = None, y: int | None = None, pos: PySide6.QtCore.QPoint | None = None, frameSize: PySide6.QtCore.QSize | None = None, size: PySide6.QtCore.QSize | None = None, width: int | None = None, height: int | None = None, rect: PySide6.QtCore.QRect | None = None, childrenRect: PySide6.QtCore.QRect | None = None, childrenRegion: PySide6.QtGui.QRegion | None = None, sizePolicy: PySide6.QtWidgets.QSizePolicy | None = None, minimumSize: PySide6.QtCore.QSize | None = None, maximumSize: PySide6.QtCore.QSize | None = None, minimumWidth: int | None = None, minimumHeight: int | None = None, maximumWidth: int | None = None, maximumHeight: int | None = None, sizeIncrement: PySide6.QtCore.QSize | None = None, baseSize: PySide6.QtCore.QSize | None = None, palette: PySide6.QtGui.QPalette | None = None, font: PySide6.QtGui.QFont | None = None, cursor: PySide6.QtGui.QCursor | None = None, mouseTracking: bool | None = None, tabletTracking: bool | None = None, isActiveWindow: bool | None = None, focusPolicy: PySide6.QtCore.Qt.FocusPolicy | None = None, focus: bool | None = None, contextMenuPolicy: PySide6.QtCore.Qt.ContextMenuPolicy | None = None, updatesEnabled: bool | None = None, visible: bool | None = None, minimized: bool | None = None, maximized: bool | None = None, fullScreen: bool | None = None, sizeHint: PySide6.QtCore.QSize | None = None, minimumSizeHint: PySide6.QtCore.QSize | None = None, acceptDrops: bool | None = None, windowTitle: str | None = None, windowIcon: PySide6.QtGui.QIcon | None = None, windowIconText: str | None = None, windowOpacity: float | None = None, windowModified: bool | None = None, toolTip: str | None = None, toolTipDuration: int | None = None, statusTip: str | None = None, whatsThis: str | None = None, accessibleName: str | None = None, accessibleDescription: str | None = None, accessibleIdentifier: str | None = None, layoutDirection: PySide6.QtCore.Qt.LayoutDirection | None = None, autoFillBackground: bool | None = None, styleSheet: str | None = None, locale: PySide6.QtCore.QLocale | None = None, windowFilePath: str | None = None, inputMethodHints: PySide6.QtCore.Qt.InputMethodHint | None = None) -> None

ReferencesPanel(parent=None)
34    def __init__(self, parent=None):
35        super().__init__(parent)
36        self.title = QLabel(self.HINT)
37        self.title.setWordWrap(True)
38        self.title.setContentsMargins(8, 6, 8, 2)
39        self.tree = ResultTree()
40        self.tree.open_requested.connect(self.open_requested)
41        self.tree.keep_requested.connect(self.keep_requested)
42        layout = QVBoxLayout(self)
43        layout.setContentsMargins(0, 0, 0, 0)
44        layout.setSpacing(2)
45        layout.addWidget(self.title)
46        layout.addWidget(self.tree, 1)

__init__(self, /, parent: PySide6.QtWidgets.QWidget | None = None, f: PySide6.QtCore.Qt.WindowType = Default(Qt.WindowFlags), *, modal: bool | None = None, windowModality: PySide6.QtCore.Qt.WindowModality | None = None, enabled: bool | None = None, geometry: PySide6.QtCore.QRect | None = None, frameGeometry: PySide6.QtCore.QRect | None = None, normalGeometry: PySide6.QtCore.QRect | None = None, x: int | None = None, y: int | None = None, pos: PySide6.QtCore.QPoint | None = None, frameSize: PySide6.QtCore.QSize | None = None, size: PySide6.QtCore.QSize | None = None, width: int | None = None, height: int | None = None, rect: PySide6.QtCore.QRect | None = None, childrenRect: PySide6.QtCore.QRect | None = None, childrenRegion: PySide6.QtGui.QRegion | None = None, sizePolicy: PySide6.QtWidgets.QSizePolicy | None = None, minimumSize: PySide6.QtCore.QSize | None = None, maximumSize: PySide6.QtCore.QSize | None = None, minimumWidth: int | None = None, minimumHeight: int | None = None, maximumWidth: int | None = None, maximumHeight: int | None = None, sizeIncrement: PySide6.QtCore.QSize | None = None, baseSize: PySide6.QtCore.QSize | None = None, palette: PySide6.QtGui.QPalette | None = None, font: PySide6.QtGui.QFont | None = None, cursor: PySide6.QtGui.QCursor | None = None, mouseTracking: bool | None = None, tabletTracking: bool | None = None, isActiveWindow: bool | None = None, focusPolicy: PySide6.QtCore.Qt.FocusPolicy | None = None, focus: bool | None = None, contextMenuPolicy: PySide6.QtCore.Qt.ContextMenuPolicy | None = None, updatesEnabled: bool | None = None, visible: bool | None = None, minimized: bool | None = None, maximized: bool | None = None, fullScreen: bool | None = None, sizeHint: PySide6.QtCore.QSize | None = None, minimumSizeHint: PySide6.QtCore.QSize | None = None, acceptDrops: bool | None = None, windowTitle: str | None = None, windowIcon: PySide6.QtGui.QIcon | None = None, windowIconText: str | None = None, windowOpacity: float | None = None, windowModified: bool | None = None, toolTip: str | None = None, toolTipDuration: int | None = None, statusTip: str | None = None, whatsThis: str | None = None, accessibleName: str | None = None, accessibleDescription: str | None = None, accessibleIdentifier: str | None = None, layoutDirection: PySide6.QtCore.Qt.LayoutDirection | None = None, autoFillBackground: bool | None = None, styleSheet: str | None = None, locale: PySide6.QtCore.QLocale | None = None, windowFilePath: str | None = None, inputMethodHints: PySide6.QtCore.Qt.InputMethodHint | None = None) -> None

Initialize self. See help(type(self)) for accurate signature.

def open_requested(unknown):

The type of the None singleton.

def keep_requested(unknown):

The type of the None singleton.

HINT = 'Use Find References (⇧F12) on a name in the editor to list its uses here.'
title
tree
def reset(self):
48    def reset(self):
49        """Another project was opened: no results."""
50        self.tree.clear_results()
51        self.title.setText(self.HINT)

Another project was opened: no results.

def show_results( self, name: str, results: list[tuple[pathlib.Path, int, int, int]], roots: list[vibefpmgui.result_tree.Root], project_dir: pathlib.Path | None):
53    def show_results(self, name: str, results: list[tuple[Path, int, int, int]], roots: list[Root],
54                     project_dir: Path | None):
55        """``results``: (file, 1-based line, start column, end column);
56        ``roots``: the packages, to label the dependencies' files."""
57        self.tree.clear_results()
58        files: dict[Path, list[tuple[int, int, int]]] = {}
59        for path, line, start, end in results:
60            files.setdefault(Path(path).resolve(), []).append((line, start, end))
61        if not results:
62            self.title.setText(f"No references to <b>{name}</b> found.")
63            return
64        self.title.setText(f"<b>{name}</b>: {len(results)} reference{'s' * (len(results) != 1)} "
65                           f"in {len(files)} file{'s' * (len(files) != 1)}")
66        rows = []
67        for path, places in files.items():
68            root = root_for(path, roots)
69            folder, package = file_labels(path, root, project_dir)
70            lines = self.tree.file_lines(path)
71            matches = [make_match(lines[line - 1] if 0 < line <= len(lines) else "", line, start, line, end)
72                       for line, start, end in sorted(places)]
73            outside = root is None or root.dependency  # (dependencies after the project's own files)
74            rows.append(((outside, package, folder, path.name), path, matches, folder, package))
75        for _key, path, matches, folder, package in sorted(rows, key=lambda r: r[0]):
76            self.tree.set_file(path, matches, folder, package)

results: (file, 1-based line, start column, end column); roots: the packages, to label the dependencies' files.

staticMetaObject = PySide6.QtCore.QMetaObject("ReferencesPanel" inherits "QWidget": Methods: #33 type=Signal, signature=open_requested(QString,int,int,int,int), parameters=QString, int, int, int, int #34 type=Signal, signature=keep_requested(QString), parameters=QString )