-
Notifications
You must be signed in to change notification settings - Fork 59
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
Get list of available config OOP #30
Comments
The object returned by The 'leaf' nodes on the tree have methods like PS sorry about the earlier (deleted) reply - I hadn't read your question properly. |
Thanks for the answer. Here is a working example based on your description:
|
Never, ever, do this:
Remember that |
Thanks for the advice ;) |
Hi 👋 Sorry I just stumbled across this Thread and wanted to chip in my solution, since I wanted to do a similar thing (I think). Now if you´re only interested in the actual Configuration Parameters and their values, you don´t really need the Information about the Hierarchy in between the Nodes. Only the Leafs and their Values. So for that you can parse the Config into a nice little Dictionary like so: config_leafs = {config_tree.get_child(i).get_child(a).get_name(): config_tree.get_child(i).get_child(a).get_value() for i in range(config_tree.count_children()) for a in range(config_tree.get_child(i).count_children())} which would result in a dict like this: {
'syncdatetimeutc': 0,
'syncdatetime': 0,
'uilock': 2,
...
} But if you actually want to preserve the Hierarchy Information I came up with this monstrosity: config = {
child.get_name(): dict(
label=child.get_label(),
**{grandchild.get_name(): {
'label': grandchild.get_label(),
'set_value': grandchild.get_value(),
'possible_values': grandchild.get_type()==gp.GP_WIDGET_RADIO or grandchild.get_type()==gp.GP_WIDGET_MENU and [grandchild.get_choice(k) for k in range(grandchild.count_choices())] or []
} for grandchild in [child.get_child(a) for a in range(child.count_children())]}
) for child in [config_tree.get_child(i) for i in range(config_tree.count_children())]
} This actually gives you a dict like this: {
<child_name>: {
'label': <child_label>,
<grandchild_name>: {
'label': <grandchild_label>,
'set_value': <grandchild_value>,
'possible_values': [<grandchild_choice(1)>, <grandchild_choice(2)>, ...]
},
...
},
...
} The Problem with the 'possible_values' is that they only exist in some 'grandchild Nodes'. I guess that was the reason for the Now like I said. This is by no means a perfect solution. And since I am really neither a Expert in Python nor in the underlying C I can´t actually decide if I find this code really cool or totally unmaintainable 😄 (maybe both) but I figured since I already took the time I would just share the results in case it helps someone else too 🙂 |
Hi Jim,
I want to list all available config options like camera-gui-config-oop.py file by using oop stracture. I inspected codebase but I'm not expert on C or SWIG. I tried camera.get_config(context) and it returns a SWIG object. How can i convert it to list or dict of possible values?
The text was updated successfully, but these errors were encountered: