blockpy icon indicating copy to clipboard operation
blockpy copied to clipboard

Intelligent copy/paste image

Open acbart opened this issue 5 years ago • 1 comments

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.

acbart avatar Nov 25 '20 16:11 acbart

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

thomaswp avatar Dec 15 '22 15:12 thomaswp