68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
from __future__ import annotations
|
|
|
|
from collections.abc import Iterable
|
|
|
|
from PySide6.QtGui import QAction
|
|
from PySide6.QtWidgets import (
|
|
QFrame,
|
|
QLineEdit,
|
|
QListWidget,
|
|
QPushButton,
|
|
QScrollArea,
|
|
QSizePolicy,
|
|
QVBoxLayout,
|
|
QWidget,
|
|
)
|
|
|
|
|
|
class ToolSection(QFrame):
|
|
def __init__(self, title: str, actions: Iterable[QAction]) -> None:
|
|
super().__init__()
|
|
self.setObjectName("toolSection")
|
|
|
|
layout = QVBoxLayout(self)
|
|
layout.setContentsMargins(8, 8, 8, 8)
|
|
layout.setSpacing(6)
|
|
|
|
title_button = QPushButton(title)
|
|
title_button.setObjectName("toolSectionTitle")
|
|
title_button.setEnabled(False)
|
|
layout.addWidget(title_button)
|
|
|
|
for action in actions:
|
|
button = QPushButton(action.text())
|
|
button.setToolTip(action.toolTip() or action.text())
|
|
button.clicked.connect(action.trigger)
|
|
button.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed)
|
|
layout.addWidget(button)
|
|
|
|
|
|
class RightToolsPanel(QWidget):
|
|
def __init__(self, search_box: QLineEdit, search_results: QListWidget) -> None:
|
|
super().__init__()
|
|
self.search_box = search_box
|
|
self.search_results = search_results
|
|
self.sections_container = QWidget()
|
|
self.sections_layout = QVBoxLayout(self.sections_container)
|
|
self.sections_layout.setContentsMargins(0, 0, 0, 0)
|
|
self.sections_layout.setSpacing(8)
|
|
|
|
scroll = QScrollArea()
|
|
scroll.setWidgetResizable(True)
|
|
scroll.setFrameShape(QFrame.Shape.NoFrame)
|
|
scroll.setWidget(self.sections_container)
|
|
|
|
layout = QVBoxLayout(self)
|
|
layout.setContentsMargins(8, 8, 8, 8)
|
|
layout.setSpacing(8)
|
|
layout.addWidget(search_box)
|
|
layout.addWidget(search_results, 1)
|
|
layout.addWidget(scroll, 2)
|
|
self.setMinimumWidth(300)
|
|
|
|
def add_section(self, title: str, actions: Iterable[QAction]) -> None:
|
|
self.sections_layout.addWidget(ToolSection(title, actions))
|
|
|
|
def finish(self) -> None:
|
|
self.sections_layout.addStretch(1)
|