@@ -152,11 +152,6 @@ class SciCell(Cell):
152
152
153
153
"""
154
154
155
- def __init__ (self , * args , ** kwargs ):
156
-
157
- # Call base
158
- Cell .__init__ (self , * args , ** kwargs )
159
-
160
155
@allow_rasterization
161
156
def draw (self , renderer ):
162
157
if not self .get_visible ():
@@ -248,15 +243,13 @@ def __init__(self, ax, loc=None, bbox=None, **kwargs):
248
243
249
244
self ._cachedRenderer = None
250
245
self ._cellType = 'default'
246
+ self ._cellCreation = {"default" : Cell , "scicell" : SciCell }
251
247
252
248
def add_cell (self , row , col , * args , ** kwargs ):
253
249
""" Add a cell to the table. """
254
250
xy = (0 , 0 )
255
251
256
- if self ._cellType == 'default' :
257
- cell = Cell (xy , * args , ** kwargs )
258
- else :
259
- cell = SciCell (xy , * args , ** kwargs )
252
+ cell = self ._cellCreation [self ._cellType ](xy , * args , ** kwargs )
260
253
261
254
cell .set_figure (self .figure )
262
255
cell .set_transform (self .get_transform ())
@@ -494,24 +487,29 @@ def get_celld(self):
494
487
'return a dict of cells in the table'
495
488
return self ._cells
496
489
497
- def get_cell_type (self ):
490
+ @property
491
+ def cellType (self ):
498
492
return self ._cellType
499
493
500
- def set_cell_type (self , cellType ):
501
- if cellType in ('default' , 'scicell' ):
494
+ @cellType .setter
495
+ def cellType (self , cellType ):
496
+ if cellType is None :
497
+ self ._cellType = 'default'
498
+
499
+ elif cellType in ('default' , 'scicell' ):
502
500
self ._cellType = cellType
503
501
504
502
else :
505
- raise ValueError ('Unrecognized cell type %s; '
506
- 'Has to be default or scicell' % cellType )
503
+ raise ValueError ('Unrecognized cellType %s; '
504
+ 'must be " default" or " scicell" ' % cellType )
507
505
508
506
509
507
def table (ax ,
510
- cellType = None , cellText = None , cellColours = None ,
508
+ cellText = None , cellColours = None ,
511
509
cellLoc = 'right' , colWidths = None ,
512
510
rowLabels = None , rowColours = None , rowLoc = 'left' ,
513
511
colLabels = None , colColours = None , colLoc = 'center' ,
514
- loc = 'bottom' , bbox = None ,
512
+ loc = 'bottom' , bbox = None , cellType = None ,
515
513
** kwargs ):
516
514
"""
517
515
TABLE(cellType='default', cellText=None, cellColours=None,
@@ -524,8 +522,8 @@ def table(ax,
524
522
525
523
Thanks to John Gill for providing the class and table.
526
524
"""
527
- if cellType is not None :
528
- assert cellType in ( ' default' , ' scicell' )
525
+ if cellType is not None and cellType not in ( 'default' , 'scicell' ) :
526
+ raise ValueError ( 'cellType must be " default" or " scicell" instead of %s ' % cellType )
529
527
530
528
# Check we have some cellText
531
529
if cellText is None :
@@ -584,9 +582,7 @@ def table(ax,
584
582
# Now create the table
585
583
table = Table (ax , loc , bbox , ** kwargs )
586
584
height = table ._approx_text_height ()
587
-
588
- if cellType is not None :
589
- table .set_cell_type (cellType )
585
+ table .cellType = cellType
590
586
591
587
# Add the cells
592
588
for row in xrange (rows ):
0 commit comments