Comments (5)
Thanks for the answer. Here is a working example based on your description:
import gphoto2 as gp
context = gp.Context()
camera = gp.Camera()
camera.init(context)
config_tree = camera.get_config(context)
print('=======')
total_child = config_tree.count_children()
for i in range(total_child):
child = config_tree.get_child(i)
text_child = '# ' + child.get_label() + ' ' + child.get_name()
print(text_child)
for a in range(child.count_children()):
grandchild = child.get_child(a)
text_grandchild = ' * ' + grandchild.get_label() + ' -- ' + grandchild.get_name()
print(text_grandchild)
try:
text_grandchild_value = ' Setted: ' + grandchild.get_value()
print(text_grandchild_value)
print(' Possibilities:')
for k in range(grandchild.count_choices()):
choice = grandchild.get_choice(k)
text_choice = ' - ' + choice
print(text_choice)
except:
pass
print()
print()
camera.exit(context)
from python-gphoto2.
The object returned by camera.get_config
is a 'widget' (the name libgphoto2 uses) that is the root of the config tree structure. It has methods such as config.count_children
to get the number of child widgets and config.get_child
to get a particular child. The widget layout varies with camera type, but is unlikely to be a simple list or dict, unless you use 'compound' keys such as settings.autopoweroff
for the autopoweroff
child of the settings
node.
The 'leaf' nodes on the tree have methods like config.get_value
to get the actual camera settings.
PS sorry about the earlier (deleted) reply - I hadn't read your question properly.
from python-gphoto2.
Never, ever, do this:
except:
pass
Remember that SyntaxError
is an exception which you are now ignoring. That makes fixing errors in your code more difficult. Be as specific as you can about the exceptions you want to catch and let others (the unexpected ones) propagate as normal.
from python-gphoto2.
Thanks for the advice ;)
from python-gphoto2.
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 I know that this is by far not a perfect solution, since as Jim already mentioned the Structure of the Configuration Tree may very well vary from Camera to Camera. In my particular case I am using a Canon EOS M6 Mark II, but I thought maybe this is helpful for others too.
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 except: pass
part. But the Documentation of libgphoto2 states that count_choices()
and get_choice()
should be avaibable for Camera Widgets of type GP_WIDGET_RADIO
and GP_WIDGET_MENU
. Hence the wild Logic Operations there π
(I just learned that this technique is actually called "short circuiting" π )
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 π
from python-gphoto2.
Related Issues (20)
- Missing pre-req's(?) after building libgphoto2 from source on Raspberry Pi HOT 3
- Can not set datetime on Canon EOS 1200D HOT 4
- equivalent of gphoto2 --reset HOT 1
- delete a file HOT 2
- gp_camera_get_single_config HOT 2
- Socket error after gp_camera_exit in windows/msys2 HOT 15
- Faster way to copy files from camera HOT 7
- Sony FX3 overshoot HOT 1
- `delete_file()` does not delete file HOT 9
- Segmentation Fault segfault on gp.Camera.autodetect() on Github Actions Runner HOT 21
- LGPL vs. GPL license? HOT 8
- Test Virtual Camera HOT 4
- Missing bindings for gp_port_new, gp_port_open, and gp_port_reset? HOT 2
- capture_preview() broken in v2.5.0 HOT 4
- having trouble getting gphoto2 on rpi HOT 3
- use python-gphoto2 in Windows system HOT 1
- Always connected capture anytime HOT 1
- Github Actions Python 3.12 environment. HOT 1
- Is live data acquisition available in the library? HOT 1
- Error When Installing with "Local" libgphoto2 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-gphoto2.