Skip to content

Commit 34f290c

Browse files
committed
Remove button_style pass-through property
1 parent 8ec07cd commit 34f290c

File tree

5 files changed

+30
-98
lines changed

5 files changed

+30
-98
lines changed

docs/source/examples/Widget List.ipynb

+7-16
Original file line numberDiff line numberDiff line change
@@ -1431,19 +1431,10 @@
14311431
],
14321432
"source": [
14331433
"widgets.FileUpload(\n",
1434-
" # https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-accept\n",
1435-
" # eg. '.txt', '.pdf', 'image/*', 'image/*,.pdf'\n",
1436-
" accept='', # default\n",
1437-
" # True to accept multiple files upload else False\n",
1438-
" multiple=False, # default\n",
1439-
" # True to disable the button else False to enable it\n",
1440-
" disabled=False, # default\n",
1441-
" # CSS transparently passed to button (a button element overlays the input[type=file] element for better styling)\n",
1442-
" # e.g. 'color: darkblue; background-color: lightsalmon; width: 180px;'\n",
1443-
" style_button='', # default\n",
1444-
" # to compress data from browser to kernel\n",
1445-
" # compress level from 1 to 9 incl. - 0 for no compression\n",
1446-
" compress_level=0 # default\n",
1434+
" accept='', # Accepted file extension e.g. '.txt', '.pdf', 'image/*', 'image/*,.pdf'\n",
1435+
" multiple=False, # True to accept multiple files upload else False\n",
1436+
" disabled=False,\n",
1437+
" compress_level=0 # Compression level from 1 to 9 incl. - 0 for no compression\n",
14471438
")"
14481439
]
14491440
},
@@ -1749,9 +1740,9 @@
17491740
],
17501741
"metadata": {
17511742
"kernelspec": {
1752-
"display_name": "ipywidgets",
1743+
"display_name": "Python 3",
17531744
"language": "python",
1754-
"name": "ipywidgets"
1745+
"name": "python3"
17551746
},
17561747
"language_info": {
17571748
"codemirror_mode": {
@@ -1763,7 +1754,7 @@
17631754
"name": "python",
17641755
"nbconvert_exporter": "python",
17651756
"pygments_lexer": "ipython3",
1766-
"version": "3.7.0"
1757+
"version": "3.7.3"
17671758
},
17681759
"widgets": {
17691760
"application/vnd.jupyter.widget-state+json": {

ipywidgets/widgets/tests/test_widget_upload.py

-3
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@ def test_construction(self):
1616
assert uploader.accept == ''
1717
assert not uploader.multiple
1818
assert not uploader.disabled
19-
assert uploader.style_button == ''
2019
assert uploader.compress_level == 0
2120

2221
def test_construction_with_params(self):
2322
uploader = FileUpload(accept='.txt',
2423
multiple=True,
2524
disabled=True,
26-
style_button='color: red',
2725
compress_level=9)
2826
assert uploader.accept == '.txt'
2927
assert uploader.multiple
3028
assert uploader.disabled
31-
assert uploader.style_button == 'color: red'
3229
assert uploader.compress_level == 9

ipywidgets/widgets/widget_upload.py

+11-59
Original file line numberDiff line numberDiff line change
@@ -36,81 +36,33 @@ class FileUpload(DescriptionWidget, ValueWidget, CoreWidget):
3636
"""
3737
_model_name = Unicode('FileUploadModel').tag(sync=True)
3838
_view_name = Unicode('FileUploadView').tag(sync=True)
39-
4039
_counter = Int(0).tag(sync=True)
4140

42-
help = 'Type of files the input accepts. None for all. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-accept'
43-
accept = Unicode(help=help).tag(sync=True)
44-
45-
help = 'If true, allow for multiple files upload, else only accept one'
46-
multiple = Bool(False, help=help).tag(sync=True)
47-
48-
help = 'Enable or disable button'
49-
disabled = Bool(False, help=help).tag(sync=True)
50-
51-
help = 'Optional style for button (label element)'
52-
style_button = Unicode('', help=help).tag(sync=True)
53-
54-
help = 'Compress level: from 1 to 9 - 0 for no compression'
55-
compress_level = Int(0, help=help).tag(sync=True)
56-
57-
help = 'List of file metadata'
58-
li_metadata = List(Dict, help=help).tag(sync=True)
59-
60-
help = 'List of file content (bytes)'
61-
li_content = List(Bytes, help=help).tag(sync=True, from_json=content_from_json)
62-
63-
help = 'Error message'
64-
error = Unicode('', help=help).tag(sync=True)
65-
66-
value = Dict({}).tag(sync=False)
41+
accept = Unicode(help='File types to accept, empty string for all').tag(sync=True)
42+
multiple = Bool(False, help='If True, allow for multiple file upload').tag(sync=True)
43+
disabled = Bool(False, help='Enable or disable button').tag(sync=True)
44+
compress_level = Int(help='Compression level: from 0 to 9 - 0 for no compression').tag(sync=True)
45+
li_metadata = List(Dict, help='List of file metadata').tag(sync=True)
46+
li_content = List(Bytes, help='List of file content (bytes)').tag(sync=True, from_json=content_from_json)
47+
error = Unicode(help='Error message').tag(sync=True)
6748

68-
def __init__(self,
69-
accept='',
70-
multiple=False,
71-
disabled=False,
72-
style_button='',
73-
compress_level=0,
74-
):
75-
"""
76-
Instantiate widget
77-
"""
78-
79-
if accept is None:
80-
accept = ''
81-
82-
if style_button is None:
83-
style_button = ''
84-
85-
self._counter = 0
86-
self.accept = accept
87-
self.disabled = disabled
88-
self.multiple = multiple
89-
self.style_button = style_button
90-
self.compress_level = compress_level
91-
self.value = {}
92-
93-
super(FileUpload, self).__init__()
49+
value = Dict()
9450

9551
@validate('compress_level')
9652
def _valid_compress_level(self, proposal):
97-
if proposal['value'] not in range(10):
53+
if proposal.value not in range(10):
9854
raise TraitError('compress_level must be an int from 0 to 9 incl.')
99-
return proposal['value']
55+
return proposal.value
10056

10157
@observe('_counter')
10258
def on_incr_counter(self, change):
10359
"""
10460
counter increment triggers the update of trait value
10561
"""
10662
res = {}
107-
10863
msg = 'Error: length of li_metadata and li_content must be equal'
10964
assert len(self.li_metadata) == len(self.li_content), msg
110-
111-
for metadata, content in zip(self.li_metadata,
112-
self.li_content):
65+
for metadata, content in zip(self.li_metadata, self.li_content):
11366
name = metadata['name']
11467
res[name] = {'metadata': metadata, 'content': content}
115-
11668
self.value = res

packages/controls/src/widget_upload.ts

+12-19
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export class FileUploadModel extends CoreDOMWidgetModel {
3636
accept: '',
3737
disabled: false,
3838
multiple: false,
39-
style: '',
4039
compress_level: 0,
4140
li_metadata: [],
4241
li_content: [],
@@ -60,25 +59,18 @@ export class FileUploadView extends DOMWidgetView {
6059
this.pWidget.addClass('jupyter-widgets');
6160
this.pWidget.addClass('widget-upload');
6261

63-
const that = this;
64-
let counter;
65-
66-
const divLoader = document.createElement('div');
67-
this.el.appendChild(divLoader);
68-
6962
const fileInput = document.createElement('input');
7063
fileInput.type = 'file';
7164
fileInput.multiple = this.model.get('multiple');
7265
fileInput.setAttribute('style', 'display: none');
73-
divLoader.appendChild(fileInput);
66+
this.el.appendChild(fileInput);
7467
this.fileInput = fileInput;
7568

7669
const btn = document.createElement('button');
7770
btn.innerHTML = build_btn_inner_html(null);
78-
btn.className = 'p-Widget jupyter-widgets jupyter-button widget-button';
71+
btn.classList.add('jupyter-button');
7972
btn.disabled = this.model.get('disabled');
80-
btn.setAttribute('style', this.model.get('style_button'));
81-
divLoader.appendChild(btn);
73+
this.el.appendChild(btn);
8274
this.btn = btn;
8375

8476
btn.addEventListener('click', () => {
@@ -89,6 +81,9 @@ export class FileUploadView extends DOMWidgetView {
8981
fileInput.value = '';
9082
});
9183

84+
const that = this;
85+
let counter;
86+
9287
fileInput.addEventListener('change', () => {
9388
// console.log(`new input: nb files = ${fileInput.files.length}`);
9489
const promisesFile = [];
@@ -156,24 +151,22 @@ export class FileUploadView extends DOMWidgetView {
156151
});
157152
});
158153

159-
that.model.on('change:accept', that.update_accept, that);
160-
that.model.on('change:disabled', that.toggle_disabled, that);
161-
that.model.on('change:multiple', that.update_multiple, that);
162-
that.model.on('change:style_button', that.update_style_button, that);
154+
this.model.on('change:accept', this.update_accept, this);
155+
this.model.on('change:disabled', this.toggle_disabled, this);
156+
this.model.on('change:multiple', this.update_multiple, this);
163157
}
164158

165159
update_accept() {
166160
this.fileInput.accept = this.model.get('accept');
167161
}
162+
168163
toggle_disabled() {
169164
this.btn.disabled = this.model.get('disabled');
170165
}
166+
171167
update_multiple() {
172168
this.fileInput.multiple = this.model.get('multiple');
173169
}
174-
update_style_button() {
175-
this.btn.setAttribute('style', this.model.get('style_button'));
176-
}
177170

178-
el: HTMLImageElement;
171+
el: HTMLDivElement;
179172
}

packages/schema/jupyterwidgetmodels.latest.md

-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ Attribute | Type | Default | Help
368368
`li_metadata` | array | `[]` | List of file metadata
369369
`multiple` | boolean | `false` | If true, allow for multiple files upload, else only accept one
370370
`style` | reference to DescriptionStyle widget | reference to new instance | Styling customizations
371-
`style_button` | string | `''` | Optional style for button (label element)
372371

373372
### FloatLogSliderModel (@jupyter-widgets/controls, 1.4.0); FloatLogSliderView (@jupyter-widgets/controls, 1.4.0)
374373

0 commit comments

Comments
 (0)