Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions napari_plugin_manager/_tests/test_qt_plugin_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,3 +561,10 @@ def test_shortcut_quit(plugin_dialog, qtbot):
)
qtbot.wait(200)
assert not plugin_dialog.isVisible()


def test_disclaimer_widget(plugin_dialog, qtbot):
assert not plugin_dialog.disclaimer_widget.isVisible()
plugin_dialog._show_disclaimer = True
plugin_dialog.exec_()
assert plugin_dialog.disclaimer_widget.isVisible()
17 changes: 14 additions & 3 deletions napari_plugin_manager/qt_plugin_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
InstallerTools,
ProcessFinishedData,
)
from napari_plugin_manager.qt_widgets import ClickableLabel
from napari_plugin_manager.qt_widgets import ClickableLabel, DisclaimerWidget
from napari_plugin_manager.utils import is_conda_package

# Scaling factor for each list widget item when expanding.
Expand Down Expand Up @@ -848,7 +848,9 @@ def filter(self, text: str, starts_with_chars: int = 1):


class QtPluginDialog(QDialog):
def __init__(self, parent=None, prefix=None) -> None:
def __init__(
self, parent=None, prefix=None, show_disclaimer=False
) -> None:
super().__init__(parent)

self._parent = parent
Expand All @@ -862,6 +864,7 @@ def __init__(self, parent=None, prefix=None) -> None:
self.available_set = set()
self._prefix = prefix
self._first_open = True
self._show_disclaimer = show_disclaimer
self._plugin_queue = [] # Store plugin data to be added
self._plugin_data = [] # Store all plugin data
self._filter_texts = []
Expand Down Expand Up @@ -1135,7 +1138,6 @@ def _setup_ui(self):
horizontal_mid_layout.addStretch()
horizontal_mid_layout.addWidget(self.refresh_button)
mid_layout.addLayout(horizontal_mid_layout)
# mid_layout.addWidget(self.packages_filter)
mid_layout.addWidget(self.installed_label)
lay.addLayout(mid_layout)

Expand All @@ -1150,6 +1152,12 @@ def _setup_ui(self):
mid_layout.addWidget(self.avail_label)
mid_layout.addStretch()
lay.addLayout(mid_layout)
self.disclaimer_widget = DisclaimerWidget(
trans._(
"DISCLAIMER: Available plugin packages are user produced content. Any use of the provided files is at your own risk."
)
)
lay.addWidget(self.disclaimer_widget)
self.available_list = QPluginList(uninstalled, self.installer)
lay.addWidget(self.available_list)

Expand Down Expand Up @@ -1217,6 +1225,8 @@ def _setup_ui(self):
self.show_status_btn.setChecked(False)
self.show_status_btn.toggled.connect(self.toggle_status)

self.disclaimer_widget.setVisible(self._show_disclaimer)

self.v_splitter.setStretchFactor(1, 2)
self.h_splitter.setStretchFactor(0, 2)

Expand Down Expand Up @@ -1400,6 +1410,7 @@ def exec_(self):
if plugin_dialog != self:
self.close()

plugin_dialog.disclaimer_widget.setVisible(self._show_disclaimer)
plugin_dialog.setModal(True)
plugin_dialog.show()

Expand Down
45 changes: 42 additions & 3 deletions napari_plugin_manager/qt_widgets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from qtpy.QtCore import Signal
from qtpy.QtGui import QMouseEvent
from qtpy.QtWidgets import QLabel
from qtpy.QtCore import Qt, Signal
from qtpy.QtGui import QMouseEvent, QPainter
from qtpy.QtWidgets import (
QHBoxLayout,
QLabel,
QPushButton,
QStyle,
QStyleOption,
QWidget,
)


class ClickableLabel(QLabel):
Expand All @@ -12,3 +19,35 @@ def __init__(self, parent=None):
def mouseReleaseEvent(self, event: QMouseEvent):
super().mouseReleaseEvent(event)
self.clicked.emit()


class DisclaimerWidget(QWidget):
def __init__(self, text, parent=None):
super().__init__(parent=parent)

# Setup widgets
disclaimer_label = QLabel(text)
disclaimer_label.setAlignment(Qt.AlignmentFlag.AlignCenter)

disclaimer_button = QPushButton("x")
disclaimer_button.setFixedSize(20, 20)
disclaimer_button.clicked.connect(self.hide)

# Setup layout
disclaimer_layout = QHBoxLayout()
disclaimer_layout.addWidget(disclaimer_label)
disclaimer_layout.addWidget(disclaimer_button)
self.setLayout(disclaimer_layout)

def paintEvent(self, paint_event):
"""
Override so `QWidget` subclass can be affect by the stylesheet.

For details you can check: https://doc.qt.io/qt-5/stylesheet-reference.html#list-of-stylable-widgets
"""
style_option = QStyleOption()
style_option.initFrom(self)
painter = QPainter(self)
self.style().drawPrimitive(
QStyle.PE_Widget, style_option, painter, self
)
10 changes: 10 additions & 0 deletions napari_plugin_manager/styles.qss
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ QPushButton#refresh_button:disabled {
font-style: italic;
}

DisclaimerWidget {
color: {{ opacity(text, 150) }};
font-size: {{ font_size }};
font-weight: bold;
background-color: {{ foreground }};
border: 1px solid {{ foreground }};
padding: 5px;
border-radius: 3px;
}

#plugin_manager_process_status{
background: {{ background }};
color: {{ opacity(text, 200) }};
Expand Down