@@ -76,6 +76,9 @@ class VizRankDialog(QDialog, ProgressBarMixin, WidgetMessagesMixin):
7676 messageDeactivated = Signal (Msg )
7777 selectionChanged = Signal (object )
7878
79+ class Information (WidgetMessagesMixin .Information ):
80+ nothing_to_rank = Msg ("There is nothing to rank." )
81+
7982 def __init__ (self , master ):
8083 """Initialize the attributes and set up the interface"""
8184 QDialog .__init__ (self , windowTitle = self .captionTitle )
@@ -268,6 +271,56 @@ def toggle(self):
268271 self .button .setText ("Continue" )
269272
270273
274+ class VizRankDialogAttr (VizRankDialog ):
275+ """
276+ VizRank dialog for single attributes. The class provides most of the
277+ needed methods, except for `initialize` which is expected to store a
278+ list of `Variable` instances to `self.attrs`, and method
279+ `compute_score(state)` for scoring the combinations.
280+
281+ The state is an attribute index.
282+
283+ When the user selects an attribute, the dialog emits signal
284+ `selectionChanged` with the attribute as parameter.
285+ """
286+
287+ attrSelected = Signal (Variable , Variable )
288+ _AttrRole = next (gui .OrangeUserRole )
289+
290+ def __init__ (self , master ):
291+ super ().__init__ (master )
292+ self .attrs = []
293+
294+ def sizeHint (self ):
295+ """Assuming a single columns in the table, return `QSize(160, 512)` as
296+ a reasonable default size."""
297+ return QSize (160 , 512 )
298+
299+ def check_preconditions (self ):
300+ """Refuse ranking if there are no features or instances."""
301+ can_rank = self .master .data is not None and \
302+ self .master .data .domain .attributes and \
303+ len (self .master .data ) != 0
304+ self .Information .nothing_to_rank (shown = not can_rank )
305+ return can_rank
306+
307+ def on_selection_changed (self , selected , deselected ):
308+ attr = selected .indexes ()[0 ].data (self ._AttrRole )
309+ self .attrSelected .emit (attr )
310+
311+ def state_count (self ):
312+ return len (self .attrs )
313+
314+ def iterate_states (self , initial_state ):
315+ yield from range (initial_state or 0 , len (self .attrs ))
316+
317+ def row_for_state (self , score , state ):
318+ attr = self .attrs [state ]
319+ item = QStandardItem (attr .name )
320+ item .setData (attr , self ._AttrRole )
321+ return [item ]
322+
323+
271324class VizRankDialogAttrPair (VizRankDialog ):
272325 """
273326 VizRank dialog for pairs of attributes. The class provides most of the
@@ -284,9 +337,6 @@ class VizRankDialogAttrPair(VizRankDialog):
284337 pairSelected = Signal (Variable , Variable )
285338 _AttrRole = next (gui .OrangeUserRole )
286339
287- class Information (VizRankDialog .Information ):
288- nothing_to_rank = Msg ("There is nothing to rank." )
289-
290340 def __init__ (self , master ):
291341 VizRankDialog .__init__ (self , master )
292342 self .resize (320 , 512 )
0 commit comments