Skip to content

[FIX] ScoringSheetViewer slider style and tooltip #7024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
53 changes: 48 additions & 5 deletions Orange/widgets/visualize/owscoringsheetviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
QHBoxLayout,
QWidget,
QStyle,
QProxyStyle,
QToolTip,
QStyleOptionSlider,
)
from AnyQt.QtCore import Qt, QRect
from AnyQt.QtGui import QPainter, QFontMetrics
from AnyQt.QtCore import Qt, QRect, pyqtSignal as Signal
from AnyQt.QtGui import QPainter, QFontMetrics, QPalette

from Orange.widgets import gui
from Orange.widgets.settings import ContextSetting
Expand All @@ -30,6 +31,8 @@


class ScoringSheetTable(QTableWidget):
state_changed = Signal(int)

def __init__(self, main_widget, parent=None):
"""
Initialize the ScoringSheetTable.
Expand Down Expand Up @@ -87,7 +90,44 @@
It updates the slider value depending on the collected points.
"""
if item.column() == 2:
self.main_widget._update_slider_value()
self.state_changed.emit(item.row())


class CustomSliderStyle(QProxyStyle):
"""
A custom slider handle style.

It draws a 2px wide black rectangle to replace the default handle.
This is done to suggest to the user that the slider is not interactive.
"""

def drawComplexControl(self, cc, opt, painter, widget=None):
if cc != QStyle.CC_Slider:
super().drawComplexControl(cc, opt, painter, widget)
return

# Make a copy of the style option and remove the handle subcontrol.
slider_opt = QStyleOptionSlider(opt)
slider_opt.subControls &= ~QStyle.SC_SliderHandle

Check warning on line 111 in Orange/widgets/visualize/owscoringsheetviewer.py

View check run for this annotation

Codecov / codecov/patch

Orange/widgets/visualize/owscoringsheetviewer.py#L109-L111

Added lines #L109 - L111 were not covered by tests
super().drawComplexControl(cc, slider_opt, painter, widget)

# Get the rectangle for the slider handle.
handle_rect = self.subControlRect(cc, opt, QStyle.SC_SliderHandle, widget)

Check warning on line 116 in Orange/widgets/visualize/owscoringsheetviewer.py

View check run for this annotation

Codecov / codecov/patch

Orange/widgets/visualize/owscoringsheetviewer.py#L114-L116

Added lines #L114 - L116 were not covered by tests
# Draw a simple 2px wide black rectangle as the custom handle.
painter.save()
painter.setPen(Qt.NoPen)

Check warning on line 119 in Orange/widgets/visualize/owscoringsheetviewer.py

View check run for this annotation

Codecov / codecov/patch

Orange/widgets/visualize/owscoringsheetviewer.py#L119

Added line #L119 was not covered by tests
painter.setBrush(QPalette().color(QPalette.WindowText))
h = handle_rect.height()
painter.drawRoundedRect(
QRect(
handle_rect.center().x() - 2, handle_rect.y() + int(0.2 * h),
4, int(0.6 * h)
),

Check warning on line 126 in Orange/widgets/visualize/owscoringsheetviewer.py

View check run for this annotation

Codecov / codecov/patch

Orange/widgets/visualize/owscoringsheetviewer.py#L122-L126

Added lines #L122 - L126 were not covered by tests
3,
3,
)
painter.restore()


class RiskSlider(QWidget):
Expand All @@ -103,12 +143,13 @@
self.layout.setContentsMargins(
self.leftMargin, self.topMargin, self.rightMargin, self.bottomMargin
)
self.setMouseTracking(True)

# Setup the labels
self.setup_labels()

# Create the slider
self.slider = QSlider(Qt.Horizontal, self)
self.slider.setStyle(CustomSliderStyle())
self.slider.setEnabled(False)
self.layout.addWidget(self.slider)

Expand Down Expand Up @@ -267,7 +308,8 @@
probability = self.probabilities[value]
tooltip = str(
f"<b>{self.target_class}</b>\n "
f"<hr style='margin: 0px; padding: 0px; border: 0px; height: 1px; background-color: #000000'>"
"<hr style='margin: 0px; padding: 0px; border: 0px; "
"height: 1px; background-color: #000000'>"

Check warning on line 312 in Orange/widgets/visualize/owscoringsheetviewer.py

View check run for this annotation

Codecov / codecov/patch

Orange/widgets/visualize/owscoringsheetviewer.py#L311-L312

Added lines #L311 - L312 were not covered by tests
f"<b>Points:</b> {int(points)}<br>"
f"<b>Probability:</b> {probability:.1f}%"
)
Expand Down Expand Up @@ -366,6 +408,7 @@

self.coefficient_table = ScoringSheetTable(main_widget=self, parent=self)
gui.widgetBox(self.mainArea).layout().addWidget(self.coefficient_table)
self.coefficient_table.state_changed.connect(self._update_slider_value)

self.risk_slider = RiskSlider([], [], self)
gui.widgetBox(self.mainArea).layout().addWidget(self.risk_slider)
Expand Down
3 changes: 2 additions & 1 deletion i18n/si/msgs.jaml
Original file line number Diff line number Diff line change
Expand Up @@ -14834,7 +14834,8 @@ widgets/visualize/owscoringsheetviewer.py:
%: false
def `handle_hover_event`:
'<b>{self.target_class}</b>\n ': false
"<hr style='margin: 0px; padding: 0px; border: 0px; height: 1px; background-color: #000000'>": false
"<hr style='margin: 0px; padding: 0px; border: 0px; ": false
"height: 1px; background-color: #000000'>": false
<b>Points:</b> {int(points)}<br>: <b>Točke:</b> {int(points)}<br>
<b>Probability:</b> {probability:.1f}%: <b>Verjetnost:</b> {probability:.1f}%
class `OWScoringSheetViewer`:
Expand Down
Loading