22import sys
33from collections import deque
44from typing import TypeVar , Deque , Callable , Any , Iterable
5+ from xml .sax .saxutils import escape
56
67from AnyQt .QtCore import QObject
78
@@ -23,7 +24,7 @@ def vartype(var):
2324
2425
2526def progress_bar_milestones (count , iterations = 100 ):
26- return set ([ int (i * count / float (iterations )) for i in range (iterations )] )
27+ return set (int (i * count / float (iterations )) for i in range (iterations ))
2728
2829
2930def getdeepattr (obj , attr , * arg , ** kwarg ):
@@ -32,8 +33,8 @@ def getdeepattr(obj, attr, *arg, **kwarg):
3233 return deepgetattr (obj , attr , * arg , ** kwarg )
3334
3435
35- def to_html (str ):
36- return str .replace ("<=" , "≤" ).replace (">=" , "≥" ).\
36+ def to_html (str_ ):
37+ return str_ .replace ("<=" , "≤" ).replace (">=" , "≥" ).\
3738 replace ("<" , "<" ).replace (">" , ">" ).replace ("=\\ =" , "≠" )
3839
3940getHtmlCompatibleString = to_html
@@ -90,3 +91,24 @@ def apply_all(seq, op):
9091 """Apply `op` on all elements of `seq`."""
9192 # from itertools recipes `consume`
9293 deque (map (op , seq ), maxlen = 0 )
94+
95+
96+ def instance_tooltip (domain , row , skip_attrs = ()):
97+ def show_part (_point_data , singular , plural , max_shown , _vars ):
98+ cols = [escape ('{} = {}' .format (var .name , _point_data [var ]))
99+ for var in _vars [:max_shown + 2 ]
100+ if _vars == domain .class_vars
101+ or var not in skip_attrs ][:max_shown ]
102+ if not cols :
103+ return ""
104+ n_vars = len (_vars )
105+ if n_vars > max_shown :
106+ cols [- 1 ] = "... and {} others" .format (n_vars - max_shown + 1 )
107+ return \
108+ "<b>{}</b>:<br/>" .format (singular if n_vars < 2 else plural ) \
109+ + "<br/>" .join (cols )
110+
111+ parts = (("Class" , "Classes" , 4 , domain .class_vars ),
112+ ("Meta" , "Metas" , 4 , domain .metas ),
113+ ("Feature" , "Features" , 10 , domain .attributes ))
114+ return "<br/>" .join (show_part (row , * columns ) for columns in parts )
0 commit comments