@@ -20,8 +20,6 @@ class AbstractArrayModel(QAbstractTableModel):
20
20
----------
21
21
parent : QWidget, optional
22
22
Parent Widget.
23
- data : array-like, optional
24
- Input data.
25
23
readonly : bool, optional
26
24
If True, data cannot be changed. False by default.
27
25
font : QFont, optional
@@ -30,7 +28,7 @@ class AbstractArrayModel(QAbstractTableModel):
30
28
ROWS_TO_LOAD = 500
31
29
COLS_TO_LOAD = 40
32
30
33
- def __init__ (self , parent = None , data = None , readonly = False , font = None ):
31
+ def __init__ (self , parent = None , readonly = False , font = None ):
34
32
QAbstractTableModel .__init__ (self )
35
33
36
34
self .dialog = parent
@@ -45,13 +43,12 @@ def __init__(self, parent=None, data=None, readonly=False, font=None):
45
43
self .cols_loaded = 0
46
44
self .total_rows = 0
47
45
self .total_cols = 0
48
- self .set_data (data )
49
46
50
- def _set_data (self , data , changes = None ):
47
+ def _set_data (self , data ):
51
48
raise NotImplementedError ()
52
49
53
- def set_data (self , data , changes = None , ** kwargs ):
54
- self ._set_data (data , changes , ** kwargs )
50
+ def set_data (self , data ):
51
+ self ._set_data (data )
55
52
self .reset ()
56
53
57
54
def rowCount (self , parent = QModelIndex ()):
@@ -119,20 +116,16 @@ class LabelsArrayModel(AbstractArrayModel):
119
116
----------
120
117
parent : QWidget, optional
121
118
Parent Widget.
122
- data : nested list or tuple, optional
123
- Input data.
124
119
readonly : bool, optional
125
120
If True, data cannot be changed. False by default.
126
121
font : QFont, optional
127
122
Font. Default is `Calibri` with size 11.
128
123
"""
129
- def __init__ (self , parent = None , data = None , readonly = False , font = None ):
130
- AbstractArrayModel .__init__ (self , parent , data , readonly , font )
124
+ def __init__ (self , parent = None , readonly = False , font = None ):
125
+ AbstractArrayModel .__init__ (self , parent , readonly , font )
131
126
self .font .setBold (True )
132
127
133
- def _set_data (self , data , changes = None ):
134
- if data is None :
135
- data = [[]]
128
+ def _set_data (self , data ):
136
129
# TODO: use sequence instead
137
130
if not isinstance (data , (list , tuple , Product )):
138
131
QMessageBox .critical (self .dialog , "Error" , "Expected list, tuple or Product" )
@@ -188,42 +181,44 @@ class DataArrayModel(AbstractArrayModel):
188
181
189
182
Parameters
190
183
----------
191
- data : Numpy ndarray, optional
192
- Input 2D array.
193
- format : str, optional
194
- Indicates how data are represented in cells.
195
- By default, they are represented as floats with 3 decimal points.
184
+ parent : QWidget, optional
185
+ Parent Widget.
196
186
readonly : bool, optional
197
187
If True, data cannot be changed. False by default.
188
+ format : str, optional
189
+ Indicates how data is represented in cells.
190
+ By default, they are represented as floats with 3 decimal points.
198
191
font : QFont, optional
199
192
Font. Default is `Calibri` with size 11.
200
- parent : QWidget, optional
201
- Parent Widget.
202
193
bg_gradient : LinearGradient, optional
203
194
Background color gradient
204
195
bg_value : Numpy ndarray, optional
205
196
Background color value. Must have the shape as data
206
- minvalue : scalar
197
+ minvalue : scalar, optional
207
198
Minimum value allowed.
208
- maxvalue : scalar
199
+ maxvalue : scalar, optional
209
200
Maximum value allowed.
210
201
"""
211
202
212
203
ROWS_TO_LOAD = 500
213
204
COLS_TO_LOAD = 40
214
205
215
- def __init__ (self , parent = None , data = None , readonly = False , format = "%.3f" , font = None ,
216
- bg_gradient = None , bg_value = None , minvalue = None , maxvalue = None ):
217
- AbstractArrayModel .__init__ (self , parent , data , readonly , font )
206
+ def __init__ (self , parent = None , readonly = False , format = "%.3f" , font = None , minvalue = None , maxvalue = None ):
207
+ AbstractArrayModel .__init__ (self , parent , readonly , font )
218
208
self ._format = format
219
209
220
210
self .minvalue = minvalue
221
211
self .maxvalue = maxvalue
222
- self ._set_data (data )
223
- self ._set_bg_gradient (bg_gradient )
224
- self ._set_bg_value (bg_value )
225
- # XXX: unsure this is necessary at all in __init__
226
- self .reset ()
212
+
213
+ self .changes = None
214
+ self .color_func = None
215
+
216
+ self .vmin = None
217
+ self .vmax = None
218
+ self .bgcolor_possible = False
219
+
220
+ self .bg_value = None
221
+ self .bg_gradient = None
227
222
228
223
def get_format (self ):
229
224
"""Return current format"""
@@ -234,16 +229,12 @@ def get_data(self):
234
229
"""Return data"""
235
230
return self ._data
236
231
237
- def _set_data (self , data , changes = None , reset_minmax = True ):
238
- if changes is None :
239
- changes = {}
232
+ def _set_changes (self , changes ):
240
233
self .changes = changes
241
234
235
+ def _set_data (self , data ):
242
236
# TODO: check that data respects minvalue/maxvalue
243
- if data is None :
244
- data = np .empty ((0 , 0 ), dtype = np .int8 )
245
- if not (isinstance (data , np .ndarray ) and data .ndim == 2 ):
246
- QMessageBox .critical (self .dialog , "Error" , "Expect Numpy ndarray of 2 dimensions" )
237
+ assert isinstance (data , np .ndarray ) and data .ndim == 2
247
238
self ._data = data
248
239
249
240
dtype = data .dtype
@@ -262,8 +253,6 @@ def _set_data(self, data, changes=None, reset_minmax=True):
262
253
self .color_func = None
263
254
# --------------------------------------
264
255
self .total_rows , self .total_cols = self ._data .shape
265
- if reset_minmax :
266
- self .reset_minmax ()
267
256
self ._compute_rows_cols_loaded ()
268
257
269
258
def reset_minmax (self ):
@@ -283,9 +272,12 @@ def reset_minmax(self):
283
272
284
273
def set_format (self , format ):
285
274
"""Change display format"""
286
- self ._format = format
275
+ self ._set_format ( format )
287
276
self .reset ()
288
277
278
+ def _set_format (self , format ):
279
+ self ._format = format
280
+
289
281
def set_bg_gradient (self , bg_gradient ):
290
282
self ._set_bg_gradient (bg_gradient )
291
283
self .reset ()
@@ -459,17 +451,22 @@ def set_values(self, left, top, right, bottom, values):
459
451
460
452
# Update vmin/vmax if necessary
461
453
if self .vmin is not None and self .vmax is not None :
454
+ # FIXME: -inf/+inf and non-number values should be ignored here too
462
455
colorval = self .color_func (values ) if self .color_func is not None else values
463
456
old_colorval = self .color_func (oldvalues ) if self .color_func is not None else oldvalues
457
+ # we need to lower vmax or increase vmin
464
458
if np .any (((old_colorval == self .vmax ) & (colorval < self .vmax )) |
465
459
((old_colorval == self .vmin ) & (colorval > self .vmin ))):
466
460
self .reset_minmax ()
461
+ self .reset ()
467
462
# this is faster, when the condition is False (which should be most of the cases) than computing
468
463
# subset_max and checking if subset_max > self.vmax
469
464
67A7
code>
if np .any (colorval > self .vmax ):
470
465
self .vmax = float (np .nanmax (colorval ))
466
+ self .reset ()
471
467
if np .any (colorval < self .vmin ):
472
468
self .vmin = float (np .nanmin (colorval ))
469
+ self .reset ()
473
470
474
471
top_left = self .index (left , top )
475
472
# -1 because Qt index end bounds are inclusive
0 commit comments