innovationOUtside / nbev3devsim

Ev3DevSim ipywidget in Jupyter notebooks
Apache License 2.0
5 stars 0 forks source link

Loading background images into the simulator #2

Closed psychemedia closed 4 years ago

psychemedia commented 4 years ago

At the moment this is broken - the image files are hard coded by name in templates/studio.js and via a relative path to a ./images directory.

Backgrounds available via the package need to be referenced by an appropriate path/

Some solution also needs to be found for allow users to load in their own background files. Originally this was done via an upload dialogue. Perhaps an alternative solution would be to path a local path name in via the %%sim_magic call that loads the simulator? <- the upload route via the background selection list is fine for now...

psychemedia commented 4 years ago

Alternatively, the code block magic could accept a parameter that specifies the background to be used for that code.

psychemedia commented 4 years ago
psychemedia commented 4 years ago

We can change the background from py by calling on js via the widget:

roboSim.js_init("""
  document.getElementById("map").value = "Lollipop";
  // Setting value doesn't seem to raise the event that kicks the loader in?
  // So give it an explicit kick...
  var event = new Event('change');
  document.getElementById("map").dispatchEvent(event);
""")

For the magic, decorate with:

 @magic_arguments.argument('--background', '-b', default='', help='Background selection')

and then call eg:

if args.background:
        self.shell.user_ns[args.sim].js_init(f'''
        var bgSelector = document.getElementById("map")
        bgSelector.value = "{args.background}";
        ''')

BUT THIS DOESN"T WORK... the event doesn't fire to reset the image? Even with:

var event = new Event('change');
document.getElementById("map").dispatchEvent(event);

Ah - maybe it does by changing the event tracked from 'inputtochange`.

I can't figure out how to pass in names containing spaces, eg Background image.

psychemedia commented 4 years ago

Re: accessibility: provide support for an optional audible response that says which background is loaded. Maybe also allow a keyboard shortcut that says the name of the loaded background.