Skip to content

Adding a method to get options #72

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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Adding a method to get options #72

wants to merge 17 commits into from

Conversation

timmarkhuff
Copy link
Contributor

@timmarkhuff timmarkhuff commented Apr 30, 2025

The latest pydantification of framegrab broke some applications that interact with grabber options like this:

grabber.config["options"]

config is now a pydantic object and cannot be accessed in this way.

I realized that there is no straightforward way in the new pydantic version of framegrab to get options, so I added a method. Now you can do this:

grabber.config.options

@timmarkhuff timmarkhuff marked this pull request as draft April 30, 2025 21:59
@timmarkhuff timmarkhuff marked this pull request as ready for review April 30, 2025 22:48
@timmarkhuff timmarkhuff requested a review from roxanne-o April 30, 2025 22:48
@@ -337,3 +337,21 @@ def test_determine_input_type_in_create(self):
# this won't work because there are multiple input types that could be mapped to the serial_number field
with self.assertRaises(ValueError):
FrameGrabberConfig.create(serial_number="1234567890", resolution_width=640, resolution_height=480, digital_zoom=2)

# def test_get_and_apply_options(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we uncomment this test? I dont think we should leave it in if we're just going to keep it commented.

@@ -284,6 +284,13 @@ def create(cls, input_type: Optional[InputTypes] = None, **kwargs) -> "FrameGrab
continue
raise ValueError("Could not determine input type from provided arguments")

def get_options(self) -> dict:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want this to actually be grabber.config.options, then you could use the @Property decorator and call this def options(self):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered this, however sometimes the rpc server tries to do things like this:
grabber.config.options["some_option"] = "new value"

This works if grabber.config.options is actually a property, but raises an exception if it is a method decorated with property.

In general, I try to stay away from the property decorator for this reason. I would rather know if something is a method or a property.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, maybe the RPC server shouldn't be updating options like that. We need to figure out the right way to update options, especially in light of the recent pydantic refactor.

Copy link
Contributor

@tyler-romero tyler-romero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, see comment about test

@timmarkhuff
Copy link
Contributor Author

Roxanne raised some concerns about this PR, so we'll put it on pause until we agree on a path forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants