66 QItemSelectionModel ,
77 QModelIndex ,
88 QObject ,
9- QPoint ,
9+ QRect ,
1010 QSize ,
1111 Qt ,
1212)
2323 QWidget ,
2424)
2525
26+ from ert .ensemble_evaluator .state import (
27+ REALIZATION_STATE_RUNNING ,
28+ REALIZATION_STATE_WAITING ,
29+ )
2630from ert .gui .model .real_list import RealListModel
2731from ert .gui .model .snapshot import (
2832 CallbackStatusMessageRole ,
2933 FMStepColorHint ,
3034 MemoryUsageRole ,
3135 RealIens ,
36+ StatusRole ,
3237)
3338from ert .shared .status .utils import byte_with_unit
3439
@@ -40,7 +45,7 @@ def __init__(self, it: int, parent: QWidget | None = None) -> None:
4045 super ().__init__ (parent )
4146
4247 self ._iter = it
43- self ._delegate_size = QSize (90 , 90 )
48+ self ._delegate_size = QSize (70 , 70 )
4449
4550 self ._real_view = QListView (self )
4651 self ._real_view .setViewMode (QListView .ViewMode .IconMode )
@@ -95,80 +100,96 @@ def refresh_current_selection(self) -> None:
95100
96101
97102class RealizationDelegate (QStyledItemDelegate ):
98- def __init__ (self , size : QSize , parent : QObject ) -> None :
103+ _STATUS_DOT_DIAMETER = 32
104+ _PROGRESS_RING_MARGIN = 4
105+ _PROGRESS_RING_WIDTH = 5
106+
107+ def __init__ (self , item_size : QSize , parent : QObject ) -> None :
99108 super ().__init__ (parent )
100- self ._size = size
109+ self ._item_size = item_size
101110 parent .installEventFilter (self )
102- self .adjustment_point_for_job_rect_margin = QPoint (- 20 , - 20 )
103- self ._color_black = QColor (0 , 0 , 0 , 180 )
104- self ._color_progress = QColor (50 , 173 , 230 , 200 )
105- self ._color_lightgray = QColor ("LightGray" ).lighter (120 )
106- self ._pen_black = QPen (self ._color_black , 2 , Qt .PenStyle .SolidLine )
111+ self ._progress_track_color = QColor (0 , 0 , 0 , 35 )
112+ self ._status_dot_outline_pen = QPen (
113+ QColor (0 , 0 , 0 , 45 ), 1 , Qt .PenStyle .SolidLine
114+ )
107115
108116 @override
109117 def paint (
110118 self , painter : QPainter | None , option : QStyleOptionViewItem , index : QModelIndex
111119 ) -> None :
112120 if painter is None :
113121 return
114- text = index .data (RealIens )
115- selected_color , finished_count , total_count = tuple (index .data (FMStepColorHint ))
122+ realization_label = index .data (RealIens )
123+ realization_status = index .data (StatusRole )
124+ realization_status_color , completed_step_count , total_step_count = tuple (
125+ index .data (FMStepColorHint )
126+ )
116127
117128 painter .save ()
118129 painter .setRenderHint (QPainter .RenderHint .TextAntialiasing , True )
119130 painter .setRenderHint (QPainter .RenderHint .Antialiasing , True )
120131
121- percentage_done = (
122- 100 if total_count < 1 else int ((finished_count * 100.0 ) / total_count )
123- )
124-
125- painter .setPen (self ._pen_black )
126- adjusted_rect = option .rect .adjusted (2 , 2 , - 2 , - 2 )
127-
128- painter .setBrush (
129- self ._color_progress if percentage_done == 100 else self ._color_lightgray
132+ if option .state & QStyle .StateFlag .State_Selected :
133+ selection_color = QColor (option .palette .color (QPalette .ColorRole .Highlight ))
134+ selection_color .setAlpha (60 )
135+ painter .setPen (Qt .PenStyle .NoPen )
136+ painter .setBrush (selection_color )
137+ painter .drawRoundedRect (option .rect .adjusted (2 , 2 , - 2 , - 2 ), 6 , 6 )
138+
139+ status_dot_rect = QRect (
140+ option .rect .center ().x () - self ._STATUS_DOT_DIAMETER // 2 ,
141+ option .rect .top () + 8 ,
142+ self ._STATUS_DOT_DIAMETER ,
143+ self ._STATUS_DOT_DIAMETER ,
130144 )
131- painter .drawEllipse (adjusted_rect )
132-
133- if 0 < percentage_done < 100 :
134- painter .setBrush (self ._color_progress )
135- painter .drawPie (adjusted_rect , 1440 , - int (percentage_done * 57.6 ))
136145
137- if option .state & QStyle .StateFlag .State_Selected :
138- factor : int = (
139- 125
140- if selected_color .lighter (125 ).getRgb () != (255 , 255 , 255 , 255 )
141- else 110
146+ if realization_status == REALIZATION_STATE_RUNNING and total_step_count > 0 :
147+ progress_ring_rect = status_dot_rect .adjusted (
148+ - self ._PROGRESS_RING_MARGIN ,
149+ - self ._PROGRESS_RING_MARGIN ,
150+ self ._PROGRESS_RING_MARGIN ,
151+ self ._PROGRESS_RING_MARGIN ,
152+ )
153+ painter .setBrush (Qt .BrushStyle .NoBrush )
154+ painter .setPen (QPen (self ._progress_track_color , self ._PROGRESS_RING_WIDTH ))
155+ painter .drawEllipse (progress_ring_rect )
156+ progress_arc_pen = QPen (realization_status_color , self ._PROGRESS_RING_WIDTH )
157+ progress_arc_pen .setCapStyle (Qt .PenCapStyle .RoundCap )
158+ painter .setPen (progress_arc_pen )
159+ painter .drawArc (
160+ progress_ring_rect ,
161+ 90 * 16 ,
162+ - int (360 * 16 * completed_step_count / total_step_count ),
142163 )
143- selected_color = selected_color .lighter (factor )
144-
145- painter .setBrush (selected_color )
146- adjusted_rect = option .rect .adjusted (7 , 7 , - 7 , - 7 )
147- painter .drawEllipse (adjusted_rect )
148164
149- font = painter .font ()
150- font .setBold (True )
151- painter .setFont (font )
165+ painter .setPen (self ._status_dot_outline_pen )
166+ if realization_status == REALIZATION_STATE_WAITING :
167+ painter .setBrush (Qt .BrushStyle .NoBrush )
168+ painter .setPen (QPen (realization_status_color , 2 ))
169+ painter .drawEllipse (status_dot_rect .adjusted (1 , 1 , - 1 , - 1 ))
170+ else :
171+ painter .setBrush (realization_status_color )
172+ painter .drawEllipse (status_dot_rect )
152173
153- adj_rect = option .rect .adjusted (0 , 20 , 0 , 0 )
154- painter .drawText (adj_rect , Qt .AlignmentFlag .AlignHCenter , text )
155- adj_rect = option .rect .adjusted (0 , 45 , 0 , 0 )
174+ painter .setPen (option .palette .color (QPalette .ColorRole .Text ))
156175 painter .drawText (
157- adj_rect , Qt .AlignmentFlag .AlignHCenter , f"{ finished_count } / { total_count } "
176+ option .rect .adjusted (0 , self ._STATUS_DOT_DIAMETER + 14 , 0 , 0 ),
177+ Qt .AlignmentFlag .AlignHCenter ,
178+ realization_label ,
158179 )
159180
160181 painter .restore ()
161182
162183 @override
163184 def sizeHint (self , option : QStyleOptionViewItem , index : QModelIndex ) -> QSize :
164- return self ._size
185+ return self ._item_size
165186
166187 @override
167188 def eventFilter (self , object : QObject | None , event : QEvent | None ) -> bool :
168189 if isinstance (event , QHelpEvent ) and event .type () == QEvent .Type .ToolTip :
169- mouse_pos = event .pos () + self .adjustment_point_for_job_rect_margin
170190 parent : RealizationWidget = cast (RealizationWidget , self .parent ())
171191 view = parent ._real_view
192+ mouse_pos = view .viewport ().mapFrom (parent , event .pos ())
172193 index = view .indexAt (mouse_pos )
173194 if index .isValid ():
174195 tooltip_text = ""
@@ -182,7 +203,9 @@ def eventFilter(self, object: QObject | None, event: QEvent | None) -> bool:
182203 tooltip_text += callback_error_msg
183204 if tooltip_text :
184205 parent .triggeredTooltipTextDisplay .emit (tooltip_text )
185- QToolTip .showText (view .mapToGlobal (mouse_pos ), tooltip_text )
206+ QToolTip .showText (
207+ view .viewport ().mapToGlobal (mouse_pos ), tooltip_text
208+ )
186209 return True
187210
188211 return super ().eventFilter (object , event )
0 commit comments