Skip to content

Commit

Permalink
Dismissible label/custom widget option implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dalthviz committed Aug 13, 2024
1 parent 7d7e1e4 commit f27b75b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 16 deletions.
21 changes: 9 additions & 12 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 @@ -1116,13 +1116,6 @@ def _setup_ui(self):
installed = QWidget(self.v_splitter)
lay = QVBoxLayout(installed)
lay.setContentsMargins(0, 2, 0, 2)
self.disclaimer_label = QLabel(
trans._(
"DISCLAIMER: Available plugin packages are user produced content. Any use of the provided files is at your own risk."
)
)
self.disclaimer_label.setObjectName("small_bold_text")
self.disclaimer_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.installed_label = QLabel(trans._("Installed Plugins"))
self.packages_filter = QLineEdit()
self.packages_filter.setPlaceholderText(trans._("filter..."))
Expand All @@ -1144,9 +1137,7 @@ def _setup_ui(self):
horizontal_mid_layout.addWidget(self.packages_filter)
horizontal_mid_layout.addStretch()
horizontal_mid_layout.addWidget(self.refresh_button)
mid_layout.addWidget(self.disclaimer_label)
mid_layout.addLayout(horizontal_mid_layout)
# mid_layout.addWidget(self.packages_filter)
mid_layout.addWidget(self.installed_label)
lay.addLayout(mid_layout)

Expand All @@ -1161,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 @@ -1228,7 +1225,7 @@ def _setup_ui(self):
self.show_status_btn.setChecked(False)
self.show_status_btn.toggled.connect(self.toggle_status)

self.disclaimer_label.setVisible(self._show_disclaimer)
self.disclaimer_widget.setVisible(self._show_disclaimer)

self.v_splitter.setStretchFactor(1, 2)
self.h_splitter.setStretchFactor(0, 2)
Expand Down Expand Up @@ -1413,7 +1410,7 @@ def exec_(self):
if plugin_dialog != self:
self.close()

plugin_dialog.disclaimer_label.setVisible(self._show_disclaimer)
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(

Check warning on line 51 in napari_plugin_manager/qt_widgets.py

View check run for this annotation

Codecov / codecov/patch

napari_plugin_manager/qt_widgets.py#L48-L51

Added lines #L48 - L51 were not covered by tests
QStyle.PE_Widget, style_option, painter, self
)
6 changes: 5 additions & 1 deletion napari_plugin_manager/styles.qss
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,14 @@ QPushButton#refresh_button:disabled {
font-style: italic;
}

#small_bold_text {
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{
Expand Down

0 comments on commit f27b75b

Please sign in to comment.