Skip to content

Commit

Permalink
fix: Updated FileUpload widget to ipywidgets 8.x API
Browse files Browse the repository at this point in the history
  • Loading branch information
gtdang committed Dec 12, 2023
1 parent 4391b46 commit 94576d9
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions hnn_core/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import urllib.request
from collections import defaultdict
from pathlib import Path
from datetime import datetime
from IPython.display import IFrame, display
from ipywidgets import (HTML, Accordion, AppLayout, BoundedFloatText,
BoundedIntText, Button, Dropdown, FileUpload, VBox,
Expand Down Expand Up @@ -653,16 +654,13 @@ def _prepare_upload_file_from_url(file_url):
for line in data:
content += line

return {
params_name: {
'metadata': {
'name': params_name,
'type': 'application/json',
'size': len(content),
},
'content': content
}
}
return [{
'name': params_name,
'type': 'application/json',
'size': len(content),
'content': content,
'last_modified': datetime.now()
}]


def create_expanded_button(description, button_style, layout, disabled=False,
Expand Down Expand Up @@ -1131,14 +1129,14 @@ def on_upload_data_change(change, data, viz_manager, log_out):
logger.info("Empty change")
return

key = list(change['new'].keys())[0]
data_dict = change['new'][0]

data_fname = change['new'][key]['metadata']['name'].rstrip('.txt')
data_fname = data_dict['name'].rstrip('.txt')
if data_fname in data['simulation_data'].keys():
logger.error(f"Found existing data: {data_fname}.")
return

ext_content = change['new'][key]['content']
ext_content = data_dict['content']
ext_content = codecs.decode(ext_content, encoding="utf-8")
with log_out:
data['simulation_data'][data_fname] = {'net': None, 'dpls': [
Expand All @@ -1161,10 +1159,9 @@ def on_upload_params_change(change, params, tstop, dt, log_out, drive_boxes,
logger.info("Empty change")
return
logger.info("Loading connectivity...")
key = list(change['new'].keys())[0]

params_fname = change['new'][key]['metadata']['name']
param_data = change['new'][key]['content']
param_dict = change['new'][0]
params_fname = param_dict['name']
param_data = param_dict['content']

param_data = codecs.decode(param_data, encoding="utf-8")

Expand Down

0 comments on commit 94576d9

Please sign in to comment.