blockpy-edu / blockpy

Blockly that's more Python than JavaScript, powered with Skulpt
Apache License 2.0
391 stars 130 forks source link

Intelligent copy/paste image #109

Open acbart opened 3 years ago

acbart commented 3 years ago

When someone copy/pastes an image into the BlockPy editor, you can set up hooks with BlockMirror to convert the image into a URL (potentially uploading it to a remote server along the way), and then returning some Python code to inject (that will be rendered as an image by BlockMirror in its respective editors).

The code that should be injected could vary in a few different ways, depending on what framework you are using. Both PIL and Pygame are popular choices for image manipulation, and we probably will ultimately create our own library that sits on one or both of them.

I think BlockPy could do a little witchcraft to check what packages are currently "loaded" (imported) in a user's code in order to provide a best guess about what they want. For example, if import pygame is found in the AST, then we can probably assume they want it to be a pygame image.

Ultimately, I'd like the following user experience:

  1. User pastes an image into the editor
  2. The image gets stored in the images associated with that submission
  3. A filename is produced for that image relative to the current folder.
  4. The following code gets injected (intelligently reusing any viable existing import)
import pygame
# ...
dog = pygame.image.load('images/dog.png')
  1. The editor knows to render the pygame.image.load("valid filename") call as an image

The user could then go into the Images tab to edit/replace/move the image.

thomaswp commented 1 year ago

This would also be nice on the instructor's side in the assignment editor :D