5
5
"""
6
6
__all__ = ['sheet' , 'current' , 'cell' , 'calculation' , 'row' , 'column' , 'cell_range' , 'hold_cells' , 'renderer' ]
7
7
8
- import numbers
9
8
import six
10
9
from contextlib import contextmanager
11
10
23
22
24
23
_common_doc = {
25
24
'args' : """
26
- type (string): Type of cell, options are: text, numeric, checkbox, dropdown, numeric , date, widget.
25
+ type (string): Type of cell, options are: text, int, float, checkbox, dropdown , date, widget.
27
26
If type is None, the type is inferred from the type of the value being passed,
28
- numeric ( float or int type) , boolean (bool type), widget (any widget object), or else text.
27
+ float, int, boolean (bool type), widget (any widget object), or else text.
29
28
When choice is given the type will be assumed to be dropdown.
30
29
The types refer (currently) to the handsontable types: https://handsontable.com/docs/6.2.2/demo-custom-renderers.html
31
30
color (string): The text color in the cell
32
31
background_color (string): The background color in the cell
33
32
read_only (bool): Whether the cell is editable or not
34
- numeric_format (string ): Numbers format
33
+ numeric_format (ipywidgets.widgets.trait_types.NumberFormat ): Numbers format, default is 'd' for int cells, '.2f' for float cells
35
34
date_format (string): Dates format
36
35
time_format (string): Time format
37
36
renderer (string): Renderer name to use for the cell
@@ -95,7 +94,7 @@ def current():
95
94
@doc_subst (_common_doc )
96
95
def cell (row , column , value = 0. , type = None , color = None , background_color = None ,
97
96
font_style = None , font_weight = None , style = None , label_left = None , choice = None ,
98
- read_only = False , numeric_format = '0.000' , date_format = 'YYYY/MM/DD' , renderer = None , ** kwargs ):
97
+ read_only = False , numeric_format = None , date_format = 'YYYY/MM/DD' , renderer = None , ** kwargs ):
99
98
"""Adds a new ``Cell`` widget to the current ``Sheet``
100
99
101
100
Args:
@@ -111,7 +110,8 @@ def cell(row, column, value=0., type=None, color=None, background_color=None,
111
110
>>> from ipysheet import sheet, cell
112
111
>>>
113
112
>>> s1 = sheet()
114
- >>> cell(0, 0, 36.) # The Cell type will be 'numeric'
113
+ >>> cell(0, 0, 36) # The Cell type will be 'int'
114
+ >>> cell(0, 0, 36.3) # The Cell type will be 'float'
115
115
>>> cell(1, 0, True) # The Cell type will be 'checkbox'
116
116
>>> cell(0, 1, 'Hello World!') # The Cell type will be 'text'
117
117
>>> c = cell(1, 1, True)
@@ -121,8 +121,10 @@ def cell(row, column, value=0., type=None, color=None, background_color=None,
121
121
if type is None :
122
122
if isinstance (value , bool ):
123
123
type = 'checkbox'
124
- elif isinstance (value , numbers .Number ):
125
- type = 'numeric'
124
+ elif isinstance (value , int ):
125
+ type = 'int'
126
+ elif isinstance (value , float ):
127
+ type = 'float'
126
128
elif isinstance (value , widgets .Widget ):
127
129
type = 'widget'
128
130
else :
@@ -157,7 +159,7 @@ def cell(row, column, value=0., type=None, color=None, background_color=None,
157
159
@doc_subst (_common_doc )
158
160
def row (row , value , column_start = 0 , column_end = None , type = None , color = None , background_color = None ,
159
161
font_style = None , font_weight = None , style = None , choice = None ,
160
- read_only = False , numeric_format = '0.000' , date_format = 'YYYY/MM/DD' , renderer = None , ** kwargs ):
162
+ read_only = False , numeric_format = None , date_format = 'YYYY/MM/DD' , renderer = None , ** kwargs ):
161
163
"""Create a ``Cell`` widget, representing multiple cells in a sheet, in a horizontal row
162
164
163
165
Args:
@@ -187,7 +189,7 @@ def row(row, value, column_start=0, column_end=None, type=None, color=None, back
187
189
@doc_subst (_common_doc )
188
190
def column (column , value , row_start = 0 , row_end = None , type = None , color = None , background_color = None ,
189
191
font_style = None , font_weight = None , style = None , choice = None ,
190
- read_only = False , numeric_format = '0.000' , date_format = 'YYYY/MM/DD' , renderer = None , ** kwargs ):
192
+ read_only = False , numeric_format = None , date_format = 'YYYY/MM/DD' , renderer = None , ** kwargs ):
191
193
"""Create a ``Cell`` widget, representing multiple cells in a sheet, in a vertical column
192
194
193
195
Args:
@@ -219,7 +221,7 @@ def cell_range(value,
219
221
row_start = 0 , column_start = 0 , row_end = None , column_end = None , transpose = False ,
220
222
squeeze_row = False , squeeze_column = False , type = None , color = None , background_color = None ,
221
223
font_style = None , font_weight = None , style = None , choice = None ,
222
- read_only = False , numeric_format = '0.000' , date_format = 'YYYY/MM/DD' , renderer = None , ** kwargs ):
224
+ read_only = False , numeric_format = None , date_format = 'YYYY/MM/DD' , renderer = None , ** kwargs ):
223
225
"""Create a ``Cell`` widget, representing multiple cells in a sheet
224
226
225
227
Args:
@@ -278,7 +280,8 @@ def cell_range(value,
278
280
# see if we an infer a type from the data, otherwise leave it None
279
281
if type is None :
280
282
type_check_map = [('checkbox' , lambda x : isinstance (x , bool )),
281
- ('numeric' , lambda x : isinstance (x , numbers .Number )),
283
+ ('int' , lambda x : isinstance (x , int )),
284
+ ('float' , lambda x : isinstance (x , float ) or isinstance (x , int )),
282
285
('text' , lambda x : isinstance (x , six .string_types )),
283
286
('widget' , lambda x : isinstance (x , widgets .Widget )),
284
287
]
0 commit comments