Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: Fill screen with stimuli such as video. in their max size without altering aspect ratio I.E. Don't stretch it, , just fill the screen, and maintain aspect ratio: Example code inside #6234

Open
MichaelWoodc opened this issue Feb 15, 2024 · 3 comments
Labels
🌟 enhancement Proposed improvement or feature request.

Comments

@MichaelWoodc
Copy link

MichaelWoodc commented Feb 15, 2024

Description

When programming the layout for the stimuli, it'd be nice to be able to make it fill the screen, without stretching the video in either x or y. I couldn't find how to do it in the settings menu:
image
so I did it this way using the code component in the begin routing section:
`try:
window_width, window_height = win.size
print('stim clip size:', stimclip.size)
print('stim clip original size:', stimclip.frameSize)

# Get the original size of the video
orig_width, orig_height = stimclip.frameSize

# Calculate the scaling factors for width and height
scale_width = window_width / orig_width
scale_height = window_height / orig_height

# Use the smaller scaling factor to maintain aspect ratio
scale_factor = min(scale_width, scale_height)

# Scale the size of the stimclip proportionally
new_width = int(orig_width * scale_factor)
new_height = int(orig_height * scale_factor)

# Set the size of the stimclip to maintain aspect ratio
stimclip.size = (new_width, new_height)'

'except Exception as e:
print('Exception:', e)
# Handle the exception if necessary
# stimclip.size=1000,1000#stimclip.size=stimclip.origSize()`

Purpose

This would create a feature that I've seen on the forums others would benefit from

Is your feature request related to a problem?

No response

Describe the solution you would like

A check box to enable the feature

Describe alternatives that you have considered

I have tried all the setting options but couldn't get them to work

Additional context

No response

@MichaelWoodc MichaelWoodc added the 🌟 enhancement Proposed improvement or feature request. label Feb 15, 2024
@peircej
Copy link
Member

peircej commented Feb 15, 2024

There are 2 parts to this:

  • The first is how to get the full height of the screen which is best achieved using either height or norm units rather than pixels (then you don't need to query the screen etc). Either use height units and set the hegiht to be 1 (because you want 1 screen height high) or use norm units and set the height to be 2 (because the screen ranges -1:1 so it's full height is 2 units long)
  • The second issue is how to scale the width by the same amount as the height. We added the option (certainly to images but I think to movies as well) that you can set a dimension to be None and it will then happily rescale to fit the other dimension

When you put those 2 things together you should be able to do this relatively easily:

  • units = 'height'
  • size = [None, 1]
    to get a full-height, original ratio movie with no code required

@peircej
Copy link
Member

peircej commented Feb 15, 2024

Update: I checked and it looked like this was only implemented for images. We'll look to add that probably for the summer 2024 release

And it doesn't have the flexibility to check first which dimension is the larger - you need to decide that yourself in advance. I'm not sure what the best way would be to allow the full version of what you're requesting in the current user interface. As in, where would we put the selection option(s) for "full-screen rescale" or "full-screen stretch"?

@MichaelWoodc
Copy link
Author

MichaelWoodc commented Feb 15, 2024

Update: I checked and it looked like this was only implemented for images. We'll look to add that probably for the summer 2024 release

And it doesn't have the flexibility to check first which dimension is the larger - you need to decide that yourself in advance. I'm not sure what the best way would be to allow the full version of what you're requesting in the current user interface. As in, where would we put the selection option(s) for "full-screen rescale" or "full-screen stretch"?

My apologies on the poor code example! The github code feature doesn't agree with my code, as I'm using ' instead of " in my code!

I noticed what you mentioned aswell that it does not have the flexibility to check the size first. When going to get the size of the stim, you must also get the stim clip size only after it's already loaded.

Personally I would either have another drop select before the size to determine if it is "Shrink to fit", "stretch to fit", or "shrink or stretch to fit" if either is selected then there's an option to maintain original aspect ratio.

I figure it should go almost first because if you maximize the video size, you're basically guaranteeing that it's going to be centered, and the spatial units don't matter. Neither would the anchor.

To make it a less confusing experience, I would have the dialog box dynamically remove the extreneous options when one of these features is enabled.

I've only taken a brief look under the psychopy hood and I'm not yet sure if it can easily be made dynamic, this option window. I've had success using TKinter to make these kinds of windows with options that dynamically change, but I believe that this window uses WXPython, and I'll have to become familiar with this in the future before I can really know for sure.

Basically have a box at the top like this:
image

If you select shrink or stretch to fit, everything unneeded disappears and you get a checkbox:

image

I hope this makes sense! Probably poor examples! But just the idea that it can come first. A checkbox can be used to activate this mode first. If this checkbox isn't selected, the rest of the menu stays the exact same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌟 enhancement Proposed improvement or feature request.
Projects
None yet
Development

No branches or pull requests

2 participants