Skip to content

Commit

Permalink
image preview WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
villares committed Oct 13, 2023
1 parent 9b007c6 commit 8b1e795
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions admin_scripts/folder_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
TODO:
-[ ] Implement image/tex/code preview in preview mode
-[X] First attempt at image preview
-[ ] Add folder image preview? refactor thumbnail's code?
-[ ] Add text/code preview
-[ ] Decide about mouse_over/selection behavior
-[ ] Implement diff mode using code from folder_diff.py
-[X] Create a "selected items list" feature
- Currently saves selection in
Expand Down Expand Up @@ -100,12 +104,16 @@ def draw():
def draw_browser():
global over, max_width
over = None
max_height = py5.height
if state['mode'] == 'browse':
max_width = py5.width
max_height = py5.height
if state['mode'] == 'browse_preview':
max_width = py5.width - py5.height
max_height = py5.height
preview_size = py5.height - margin * 2
if state['mode'] == 'browse_preview' and state['selection']:
if img := image_preview(state['selection'][-1], preview_size):
py5.image(img, max_width, margin)

i = scroll['scroll_start']
x = 0
y = margin
Expand Down Expand Up @@ -240,6 +248,18 @@ def image_thumbnail(path):
if DEBUG:
print(f'{e}\nCould not open {path}')

@lru_cache(maxsize=64)
def image_preview(path, preview_size):
if path.suffix.lower() == '.svg':
if svg_img := image_from_svg(path):
return svg_img
try:
img = PIL.Image.open(path)
img.thumbnail((preview_size, preview_size))
return py5.convert_image(img)
except Exception as e:
if DEBUG:
print(f'{e}\nCould not open {path}')

def load_icon_images():
global icon_images
Expand Down

0 comments on commit 8b1e795

Please sign in to comment.