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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "framegrab"
version = "0.11.0"
version = "0.11.1"
description = "Easily grab frames from cameras or streams"
authors = ["Groundlight <[email protected]>"]
license = "MIT"
Expand Down
7 changes: 7 additions & 0 deletions src/framegrab/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

"""
Return the FrameGrabber options portion of the config as a dictionary,
consistent with the 'options' key in the Framegrab standard format.
"""
return self.to_framegrab_config_dict().get("options", {})


class WithResolutionMixin(FrameGrabberConfig, ABC):
"""Mixin class to add resolution configuration to FrameGrabberConfig."""
Expand Down
18 changes: 18 additions & 0 deletions test/test_all_grabber_types_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

# """
# Test that we can get the grabber's options and make an update to the options
# """
# original_zoom = 2.0
# new_zoom = 2.1

# config = MockFrameGrabberConfig(digital_zoom=original_zoom)
# grabber = FrameGrabber.create_grabber(config)

# assert grabber.config.get_options() == {'zoom': {'digital': original_zoom}}

# new_options = grabber.config.get_options()
# new_options["zoom"] = {'digital': new_zoom}
# grabber.apply_options(new_options)
# options = grabber.config.get_options()
# assert options == {'zoom': {'digital': new_zoom}}
Loading