Skip to content
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 @@ def handle_item_changed(self, item):
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
super().drawComplexControl(cc, slider_opt, painter, widget)

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

# Draw a simple 2px wide black rectangle as the custom handle.
painter.save()
painter.setPen(Qt.NoPen)
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)
),
3,
3,
)
painter.restore()


class RiskSlider(QWidget):
Expand All @@ -103,12 +143,13 @@ def __init__(self, points, probabilities, parent=None):
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 @@ def handle_hover_event(self, pos):
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'>"
f"<b>Points:</b> {int(points)}<br>"
f"<b>Probability:</b> {probability:.1f}%"
)
Expand Down Expand Up @@ -366,6 +408,7 @@ def _setup_gui(self):

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