### Configuring Camera ISO Setting Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/README.md This example demonstrates how to get, modify, and set a specific camera configuration option, using 'iso' as an example. It shows the process of interacting with camera settings. ```python iso_widget = camera.get_single_config('iso') iso_widget.set_value('400') camera.set_single_config('iso', iso_widget) ``` -------------------------------- ### Initialize camera and get summary Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/README.rst A complete example program demonstrating camera initialization, retrieving the camera summary, and printing it. Error checking is omitted for brevity. ```python import gphoto2 as gp error, camera = gp.gp_camera_new() error = gp.gp_camera_init(camera) error, text = gp.gp_camera_get_summary(camera) print('Summary') print('=======') print(text.text) error = gp.gp_camera_exit(camera) ``` -------------------------------- ### Install python-gphoto2 with Binary Wheel Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/INSTALL.rst Use pip's --only-binary option to install a pre-built wheel for quick setup. This method includes necessary libgphoto2 libraries. ```bash $ pip3 install gphoto2 --user --only-binary :all: ``` -------------------------------- ### Configure, Build, and Install Local libgphoto2 Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/developer/README.rst Steps to build a local copy of libgphoto2. Ensure to use a local installation prefix to avoid conflicts with system-wide installations. ```bash ./configure --prefix=$PWD/local_install --enable-vusb make make install ``` -------------------------------- ### Complete Camera Interaction Example Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/QUICK_REFERENCE.md This snippet shows a full workflow for interacting with a camera using python-gphoto2. It covers initialization, getting camera summary, listing files, and reading configuration. Ensure the camera is connected and recognized by gphoto2. ```python #!/usr/bin/env python3 import gphoto2 as gp import logging # Setup logging logging.basicConfig( format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING ) callback_obj = gp.use_python_logging() try: # Create and initialize camera camera = gp.Camera() print("Initializing camera...") camera.init() # Get camera info summary = camera.get_summary() print(f"Camera: {str(summary)}") # List files files = camera.folder_list_files('/DCIM/100EOS') print(f"Files in DCIM/100EOS: {len(files)}") for i in range(min(5, len(files))): print(f" - {files.get_name(i)}") # Get configuration config = camera.get_config() iso = config.get_child_by_name('iso') print(f"Current ISO: {iso.get_value()}") camera.exit() print("Done!") except gp.GPhoto2Error as ex: print(f"Error: {ex}") ``` -------------------------------- ### Build and Install Local libgphoto2 Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/INSTALL.rst Manually build and install a local version of libgphoto2. Configure with a prefix, then compile and install. ```bash ./configure --prefix=$HOME/.local ``` ```bash make ``` ```bash make install ``` -------------------------------- ### Print Available ISO Values Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-widget.md Example of iterating through and printing all available ISO settings for a camera. It first gets the ISO widget, then loops through its choices. ```python iso_widget = config.get_child_by_name('iso') for i in range(iso_widget.count_choices()): iso_value = iso_widget.get_choice(i) print(f"ISO {i}: {iso_value}") ``` -------------------------------- ### Install python-gphoto2 from Source Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/INSTALL.rst Install python-gphoto2 from PyPI and compile it against your system's libgphoto2. Use --no-binary to prevent installation from a wheel. ```bash $ pip3 install gphoto2 --user --no-binary :all: ``` -------------------------------- ### Initialize Camera and Get Summary (with check_result) Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/README.rst This example shows how to use the `check_result()` function for explicit error checking when interacting with the camera. It ensures that each libgphoto2 function call is successful before proceeding. ```python import gphoto2 as gp camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(camera)) text = gp.check_result(gp.gp_camera_get_summary(camera)) print('Summary') print('=======') print(text.text) gp.check_result(gp.gp_camera_exit(camera)) ``` -------------------------------- ### Python GPhoto2 Download File Examples Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/filesys.md Examples demonstrating how to download different types of files from the camera. This includes downloading JPEG previews, RAW files, and EXIF metadata. ```python # Download JPEG preview camera_file = camera.file_get('/DCIM/100EOS', 'IMG_0001.JPG', gp.GP_FILE_TYPE_NORMAL) # Download RAW file if available camera_file = camera.file_get('/DCIM/100EOS', 'IMG_0001.CR2', gp.GP_FILE_TYPE_RAW) # Get EXIF data camera_file = camera.file_get('/DCIM/100EOS', 'IMG_0001.JPG', gp.GP_FILE_TYPE_EXIF) ``` -------------------------------- ### Installing Multiple Callback Types Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/context.md Shows how to install different types of callbacks (error, idle, progress) on the same `GPContext` object simultaneously. Each callback type can be managed independently. ```python context = gp.GPContext() error_cb = context.set_error_func(on_error) idle_cb = context.set_idle_func(on_idle) progress_cb = context.set_progress_funcs(on_start, on_update, on_stop) # All three are active ``` -------------------------------- ### Python CameraList keys() Example Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-list.md Shows how to use the keys() method to get an accessor for all names (keys) within a CameraList. This is useful for iterating through just the names. ```python for name in list.keys(): print(name) ``` -------------------------------- ### Install python-gphoto2 with Local libgphoto2 Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/developer/README.rst Install the python-gphoto2 package using a locally built libgphoto2. The GPHOTO2_ROOT environment variable must point to an absolute path of the local installation. ```bash GPHOTO2_ROOT=$PWD/libgphoto2-2.5.28/local_install pip install --user . -v ``` -------------------------------- ### Install python-gphoto2 from local source with custom libgphoto2 root Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/INSTALL.rst Install python-gphoto2 using pip from the current directory after setting the GPHOTO2_ROOT environment variable. The -v flag provides verbose output during installation. ```bash $ GPHOTO2_ROOT=$HOME/.local pip3 install --user -v . ``` -------------------------------- ### Example Usage of Progress Callbacks Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/context.md Demonstrates how to define and use custom callback functions for progress notifications with `set_progress_funcs`. The example shows printing messages at each stage of the progress. ```python def on_progress_start(context, target, text, data): print(f"Starting: {text} (target: {target})") return 0 def on_progress_update(context, id, current, data): print(f"Progress: {current}/{target}") def on_progress_stop(context, id, data): print("Done") callback_obj = context.set_progress_funcs( on_progress_start, on_progress_update, on_progress_stop) ``` -------------------------------- ### Build SWIG interface with specified libgphoto2 prefix Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/INSTALL.rst Run the build_swig.py script from the developer directory to generate the Python interface for a specific libgphoto2 installation. Provide the installation prefix as an argument. ```bash $ python3 developer/build_swig.py $HOME/.local ``` -------------------------------- ### Minimal Camera Initialization and Summary Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/README.md This snippet demonstrates the basic steps to initialize a camera, retrieve its summary, and then exit. It's a starting point for interacting with the camera. ```python import gphoto2 as gp camera = gp.Camera() camera.init() summary = camera.get_summary() print(str(summary)) camera.exit() ``` -------------------------------- ### Install python-gphoto2 on Raspberry Pi Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/README.rst Install system packages and then python-gphoto2 using pip on a Raspberry Pi. Binary wheels are available from piwheels. ```bash sudo apt install libexif12 libgphoto2-6 libgphoto2-port12 libltdl7 pip3 install gphoto2 --user --only-binary :all: ``` -------------------------------- ### Work with Camera Configuration Lists using gphoto2 Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-list.md This example shows how to initialize a camera, retrieve its configuration list, and iterate through all configuration options. Proper camera initialization and exit are crucial. ```python import gphoto2 as gp camera = gp.Camera() camera.init() config_list = camera.list_config() # Iterate over all configuration options for name, value in config_list.items(): print(f"Config: {name}") camera.exit() ``` -------------------------------- ### Install Dependencies for Raspberry Pi Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/INSTALL.rst On Raspberry Pi, install required system packages before installing python-gphoto2 using pip with the --only-binary option. ```bash $ sudo apt install libgphoto2-6 libgphoto2-port12 libexif12 libltdl7 ``` ```bash $ pip3 install gphoto2 --user --only-binary :all: ``` -------------------------------- ### Enumerate All Available Ports Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/port-info.md A comprehensive example demonstrating how to initialize the port list, load system information, and then iterate through all detected ports to print their names and paths. ```python import gphoto2 as gp port_list = gp.GPPortInfoList() port_list.load() print(f"Available ports: {port_list.count()}") for i in range(port_list.count()): info = port_list.get_info(i) print(f" {info.name}: {info.path}") ``` -------------------------------- ### Python File Path Format Examples Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/filesys.md Illustrates the POSIX-like file path format used for camera directories and subdirectories. ```python '/' # Root directory '/DCIM' # Folder '/DCIM/100EOS' # Subfolder ``` -------------------------------- ### Set Question Callback Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/context.md Install a function to handle questions from the camera. The callback should return a feedback value to indicate the response. ```python def on_question(context, text, data): print(f"Question: {text}") return gp.GP_CONTEXT_FEEDBACK_OK callback_obj = context.set_question_func(on_question) ``` -------------------------------- ### Test python-gphoto2 Installation Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/INSTALL.rst Verify your python-gphoto2 installation by running it as a module. This command displays version information for both python-gphoto2 and libgphoto2. ```bash $ python3 -m gphoto2 ``` -------------------------------- ### Install python-gphoto2 with custom libgphoto2 root Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/INSTALL.rst Set the GPHOTO2_ROOT environment variable to point to your local libgphoto2 installation before installing python-gphoto2. This ensures the correct library version is used. Use --no-binary :all: to force a source build. ```bash $ GPHOTO2_ROOT=$HOME/.local pip3 install gphoto2 --user --no-binary :all: ``` -------------------------------- ### Build Documentation with doxy2swig Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/developer/README.rst Generate documentation for the python interfaces by integrating libgphoto2's doxygen documentation. This requires installing doxygen and doxy2swig first. ```bash python3 developer/build_doc.py source_dir python3 developer/build_swig.py install_dir ``` -------------------------------- ### Example Status Callback Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/QUICK_REFERENCE.md An example of defining and setting a status callback function. The callback receives the context, a text message, and associated data. ```python def my_callback(context, text, data): print(f"Camera: {text}") callback_obj = context.set_status_func(my_callback) ``` -------------------------------- ### Python CameraList items() Example Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-list.md Provides an example of using the items() method to iterate over (name, value) tuples from a CameraList. This is the preferred method for accessing both name and value during iteration. ```python for name, value in list.items(): print(f"{name}: {value}") ``` -------------------------------- ### Connect to Camera on Specific USB Port Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/port-info.md An example showing how to find a USB port, set it for the camera object, initialize the camera, and then proceed with camera operations. Ensure to call camera.exit() when done. ```python import gphoto2 as gp camera = gp.Camera() port_list = gp.GPPortInfoList() port_list.load() # Find USB port for i in range(port_list.count()): info = port_list.get_info(i) if info.type == gp.GP_PORT_USB: camera.set_port_info(info) break camera.init() # ... use camera ... camera.exit() ``` -------------------------------- ### Get Root Configuration Widget Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-widget.md Demonstrates how to obtain the root configuration widget from a camera object. This is the entry point for accessing camera settings. ```python # Get root configuration widget from camera config = camera.get_config() # Get specific widget widget = config.get_child_by_name('iso') ``` -------------------------------- ### Create an Empty CameraList Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-list.md Instantiate an empty CameraList object. This is the starting point for managing lists of items. ```python import gphoto2 as gp list = gp.CameraList() ``` -------------------------------- ### Handling Camera Initialization Errors Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/README.md This example shows how to catch and handle specific GPhoto2 errors, particularly when a camera model is not found. It provides a way to gracefully manage connection issues. ```python try: camera.init() except gp.GPhoto2Error as ex: if ex.code == gp.GP_ERROR_MODEL_NOT_FOUND: print("Camera not connected") else: raise ``` -------------------------------- ### Check libgphoto2 and Python Versions Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/INSTALL.rst Use pkg-config to verify the installed versions of libgphoto2 and Python, ensuring they meet the requirements for python-gphoto2. ```bash $ pkg-config --modversion libgphoto2 python3 ``` -------------------------------- ### Python CameraList values() Example Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-list.md Demonstrates using the values() method to obtain an accessor for all values within a CameraList. This allows iteration specifically over the values. ```python for value in list.values(): print(value) ``` -------------------------------- ### Build SWIG interface with system libgphoto2 Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/INSTALL.rst Execute the build_swig.py script without parameters to generate the Python interface for the system's default libgphoto2 installation. This is the default behavior. ```bash $ python3 developer/build_swig.py ``` -------------------------------- ### Set Informational Message Callback Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/context.md Install a function to handle informational messages from the camera. The message text and user data are passed to the callback. ```python def on_message(context, text, data): print(f"Message: {text}") callback_obj = context.set_message_func(on_message) ``` -------------------------------- ### Build SWIG Interface with Local libgphoto2 Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/developer/README.rst Use this script to build the SWIG interface for python-gphoto2, optionally specifying a local installation directory for libgphoto2. If omitted, the system-installed libgphoto2 is used. ```bash python3 developer/build_swig.py libgphoto2-2.5.28/local_install ``` -------------------------------- ### Get Camera Summary in Python Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/INDEX.md Retrieve a summary of the connected camera's status and capabilities. This is useful for a quick overview. ```python text = camera.get_summary() ``` -------------------------------- ### Get Root Camera Widget Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-widget.md Retrieves the root widget of the camera's configuration tree. This is the starting point for navigating the widget hierarchy. ```python camera_widget.get_root() ``` ```python root = widget.get_root() ``` -------------------------------- ### Python GPhoto2 List and Download Files Workflow Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/filesys.md A typical workflow for listing all files in a camera directory and then downloading each file to a local directory. Ensure the 'gphoto2' library is installed and imported. ```python import gphoto2 as gp import os camera = gp.Camera() camera.init() # Get list of files files = camera.folder_list_files('/DCIM/100EOS') # Download each file for i in range(len(files)): file_name = files.get_name(i) print(f"Downloading {file_name}...") # Get the file from camera camera_file = camera.file_get( '/DCIM/100EOS', file_name, gp.GP_FILE_TYPE_NORMAL ) # Save to disk camera_file.save(os.path.join('/tmp', file_name)) camera.exit() ``` -------------------------------- ### Handling Camera Connection Errors with Exceptions Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/README.rst This example shows how to use a try-except block to handle potential `GPhoto2Error` exceptions, specifically waiting for a camera to be connected by retrying initialization if `GP_ERROR_MODEL_NOT_FOUND` occurs. ```python import gphoto2 as gp ... print('Please connect and switch on your camera') while True: try: camera.init() except gp.GPhoto2Error as ex: if ex.code == gp.GP_ERROR_MODEL_NOT_FOUND: # no camera, try again in 2 seconds time.sleep(2) continue # some other error we can't handle here raise # operation completed successfully so exit loop break # continue with rest of program ... ``` -------------------------------- ### Access Camera Configuration (ISO) Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/QUICK_REFERENCE.md Get the camera's configuration object, access a specific widget (e.g., ISO), and retrieve its current value. ```python config = camera.get_config() iso_widget = config.get_child_by_name('iso') iso_value = iso_widget.get_value() print(f"Current ISO: {iso_value}") ``` -------------------------------- ### Get Full Camera Configuration Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera.md Retrieves the entire camera configuration as a tree of widgets. This allows for detailed inspection and modification of settings. ```python config = camera.get_config() # Traverse the widget tree for i in range(config.count_children()): child = config.get_child(i) ``` -------------------------------- ### Complete gphoto2 Configuration and Logging Example Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/configuration.md Initialize gphoto2 with comprehensive logging, including Python's logging module and gphoto2's internal logging. Configures error severity levels and displays version information. Connects to a camera, retrieves its summary, and exits. ```python import logging import gphoto2 as gp def setup_gphoto2(verbose=False): """Initialize gphoto2 with comprehensive logging configuration.""" # Configure Python logging log_level = logging.DEBUG if verbose else logging.WARNING logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=log_level, handlers=[ logging.FileHandler('gphoto2.log'), logging.StreamHandler() ] ) # Connect gphoto2 to Python logging callback_obj = gp.check_result(gp.use_python_logging(mapping={ gp.GP_LOG_ERROR: logging.WARNING, gp.GP_LOG_VERBOSE: logging.INFO, gp.GP_LOG_DEBUG: logging.DEBUG, gp.GP_LOG_DATA: logging.DEBUG - 5, })) # Configure error handling gp.error_severity[gp.GP_ERROR_CANCEL] = logging.INFO gp.error_severity[gp.GP_ERROR_DIRECTORY_EXISTS] = logging.WARNING gp.error_exception = logging.ERROR # Display version info print(f"python-gphoto2: {gp.__version__}") versions = gp.gp_library_version(gp.GP_VERSION_SHORT) print(f"libgphoto2: {', '.join(versions)}") return callback_obj def main(): callback_obj = setup_gphoto2(verbose=True) try: camera = gp.Camera() camera.init() summary = camera.get_summary() print(str(summary)) camera.exit() except gp.GPhoto2Error as ex: logging.error(f"Camera error: {ex}") if __name__ == '__main__': main() ``` -------------------------------- ### List Files in Camera Directory with gphoto2 Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-list.md Demonstrates how to initialize a camera, list files in the root directory, and print their names. Remember to properly initialize and exit the camera connection. ```python import gphoto2 as gp camera = gp.Camera() camera.init() files = camera.folder_list_files('/') print(f"Files in /: {files.count()}") for name in files.keys(): print(f" {name}") camera.exit() ``` -------------------------------- ### Convert doxygen documentation to SWIG format Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/INSTALL.rst Use the build_doc.py script to convert libgphoto2's doxygen documentation into SWIG format. This script requires the source directory of libgphoto2, not its installation root. ```bash $ python3 developer/build_doc.py $HOME/libgphoto2-2.5.30 ``` -------------------------------- ### Get help for a gphoto2 function Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/README.rst Use pydoc to display documentation for a specific gphoto2 function, showing its signature, parameters, and return values. ```bash pydoc3 gphoto2.gp_camera_folder_list_files ``` -------------------------------- ### Accessing CameraList Keys by Index and Iteration Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-list.md Demonstrates how to append items to a CameraList, retrieve its keys accessor, access keys by index, get the total number of keys, and iterate through the keys. ```python list = gp.CameraList() list.append('a', '1') list.append('b', '2') list.append('c', '3') keys_accessor = list.keys() # Get by index first_key = keys_accessor[0] # 'a' # Get length num_keys = len(keys_accessor) # 3 # Iterate for key in keys_accessor: print(key) ``` -------------------------------- ### Initialize Camera and Get Summary (Pythonic Style) Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/README.rst This snippet demonstrates the preferred Pythonic way to interact with a camera using libgphoto2. It initializes the camera, retrieves its summary, prints it, and then exits. Error checking is handled internally by the methods. ```python import gphoto2 as gp camera = gp.Camera() camera.init() text = camera.get_summary() print('Summary') print('=======') print(str(text)) camera.exit() ``` -------------------------------- ### Python GPhoto2 Create Folder and Upload File Workflow Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/filesys.md Demonstrates creating a new directory on the camera and then uploading a local file to that directory. The 'gphoto2' library must be imported and initialized. ```python import gphoto2 as gp camera = gp.Camera() camera.init() # Create a new folder camera.folder_make_dir('/DCIM', 'MyFolder') # Create file object and load from disk camera_file = gp.CameraFile() camera_file.open('/local/file_to_upload.jpg') # Upload to camera camera.folder_put_file( '/DCIM/MyFolder', 'uploaded.jpg', gp.GP_FILE_TYPE_NORMAL, camera_file ) camera.exit() ``` -------------------------------- ### Create a Camera Instance Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera.md Instantiate the Camera class to begin interacting with a connected camera. No parameters are needed for basic instantiation. ```python import gphoto2 as gp camera = gp.Camera() ``` -------------------------------- ### List Configurable Camera Settings Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera.md Retrieves a list of all configurable setting names on the camera. This is useful for discovering available options before attempting to get or set specific configurations. ```python config_list = camera.list_config() for n in range(len(config_list)): name = config_list.get_name(n) print(name) ``` -------------------------------- ### List Files in Camera Folders using Python Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/filesys.md Demonstrates how to list files within different directories on the camera using the `folder_list_files` method. Ensure the camera is initialized before calling this method. ```python import gphoto2 as gp camera = gp.Camera() camera.init() # List files in root files = camera.folder_list_files('/') # List files in DCIM files = camera.folder_list_files('/DCIM') # List files in subfolder files = camera.folder_list_files('/DCIM/100EOS') ``` -------------------------------- ### Create CameraAbilitiesList Instance Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/abilities-list.md Instantiate a new CameraAbilitiesList. This list is initially empty and needs to be loaded with data. ```python import gphoto2 as gp abilities_list = gp.CameraAbilitiesList() ``` -------------------------------- ### get_parent Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-widget.md Gets the parent widget of the current widget in the tree. ```APIDOC ## get_parent ### Description Gets the parent widget in the tree. ### Method `camera_widget.get_parent()` ### Returns `gphoto2.CameraWidget` — Parent widget, or None if already root ### Example ```python parent = widget.get_parent() ``` ``` -------------------------------- ### Initialize Camera and Print Widget Tree Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-widget.md Initializes a gphoto2 camera and recursively prints its configuration widget tree. This is useful for exploring the available camera settings. ```python import gphoto2 as gp camera = gp.Camera() camera.init() config = camera.get_config() def print_widget_tree(widget, indent=0): prefix = " " * indent name = widget.get_name() label = widget.get_label() print(f"{prefix}{name} ({label})") for i in range(widget.count_children()): child = widget.get_child(i) print_widget_tree(child, indent + 1) print_widget_tree(config) camera.exit() ``` -------------------------------- ### Read Current ISO Setting Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-widget.md Initializes a camera, retrieves the configuration, and reads the current ISO value. It also prints all available ISO choices. ```python import gphoto2 as gp camera = gp.Camera() camera.init() config = camera.get_config() # Get ISO setting iso_widget = config.get_child_by_name('iso') current_iso = iso_widget.get_value() print(f"Current ISO: {current_iso}") # Get available ISO values print("Available ISO values:") for i in range(iso_widget.count_choices()): print(f" {iso_widget.get_choice(i)}") camera.exit() ``` -------------------------------- ### get_root Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-widget.md Gets the root widget of the camera widget tree. ```APIDOC ## get_root ### Description Gets the root widget of the tree. ### Method `camera_widget.get_root()` ### Returns `gphoto2.CameraWidget` — Root widget ### Example ```python root = widget.get_root() ``` ``` -------------------------------- ### count_children Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-widget.md Gets the total number of child widgets for the current widget. ```APIDOC ## count_children ### Description Gets the number of child widgets. ### Method `camera_widget.count_children()` ### Returns `int` — Number of children ### Example ```python num_children = widget.count_children() for i in range(num_children): child = widget.get_child(i) ``` ``` -------------------------------- ### C-style API for Camera Initialization Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/README.md Demonstrates the low-level C-style API for creating and initializing a camera object. This method returns error codes. ```python error, camera = gp.gp_camera_new() error = gp.gp_camera_init(camera) ``` -------------------------------- ### Get CameraFile name Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-file.md Retrieve the currently set filename for the CameraFile object. ```python name = file.get_name() ``` -------------------------------- ### Get CameraFile MIME type Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-file.md Retrieve the MIME type associated with the CameraFile object. ```python mime = file.get_mime_type() print(f"Type: {mime}") ``` -------------------------------- ### Get CameraFile modification time Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-file.md Retrieve the modification timestamp of the file as a Unix timestamp (integer). ```python mtime = file.get_mtime() ``` -------------------------------- ### get_port_speed Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera.md Gets the current port communication speed. This method returns the speed at which the camera is communicating over its port. ```APIDOC ## get_port_speed ### Description Gets the current port communication speed. This method returns the speed at which the camera is communicating over its port. ### Method `camera.get_port_speed()` ### Returns `int` — Port speed in baud (or 0 for USB) ``` -------------------------------- ### CameraList Length Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-list.md Explains how to get the total number of items in a CameraList using the built-in len() function. ```APIDOC ## Length ### Description Retrieve the total number of items currently stored in the `CameraList`. ### Method `len(list)` ### Response #### Success Response - **num_items** (int) - The total count of items in the list. ### Example ```python num_items = len(list) ``` ``` -------------------------------- ### Object-Oriented API for Camera Initialization Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/README.md Illustrates the preferred high-level object-oriented API for initializing a camera. This method raises exceptions on failure. ```python camera = gp.Camera() camera.init() # Raises GPhoto2Error on failure ``` -------------------------------- ### count_choices Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-widget.md Gets the number of available choices for a radio or menu widget. This is useful for iterating through all possible options. ```APIDOC ## count_choices ### Description Gets the number of available choices for a radio/menu widget. ### Method ```python camera_widget.count_choices() ``` ### Returns `int` — Number of choices ``` -------------------------------- ### Accessing Camera Abilities by Index Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/abilities-list.md Demonstrates how to load the camera abilities list and retrieve specific camera abilities by their index. ```python abilities_list = gp.CameraAbilitiesList() abilities_list.load() # Get abilities by index abilities = abilities_list[0] print(abilities.model) ``` -------------------------------- ### Get Widget Information Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-widget.md Retrieves the help or informational text for a CameraWidget. This can provide context on how to use the setting. ```python info = widget.get_info() ``` -------------------------------- ### Get Widget Label Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-widget.md Fetches the human-readable label associated with a CameraWidget. This is useful for displaying settings to users. ```python label = widget.get_label() print(f"Setting: {label}") ``` -------------------------------- ### Download File from Camera Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-file.md Demonstrates downloading a file from the camera to the local disk. This involves initializing the camera, retrieving the file, and then saving it. ```python import gphoto2 as gp camera = gp.Camera() camera.init() # Get file from camera camera_file = camera.file_get('/', 'photo.jpg', gp.GP_FILE_TYPE_NORMAL) # Save to disk camera_file.save('/tmp/my_photo.jpg') camera.exit() ``` -------------------------------- ### Get Widget Type Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-widget.md Retrieves the type of a CameraWidget. Use this to determine how to interact with the widget's value. ```python widget_type = widget.get_type() if widget_type == gp.GP_WIDGET_TEXT: print("Text field") ``` -------------------------------- ### Upload File to Camera Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-file.md Demonstrates uploading a file from the local disk to the camera. This involves initializing the camera, opening the local file, and then uploading it. ```python import gphoto2 as gp camera = gp.Camera() camera.init() # Create file object and load from disk camera_file = gp.CameraFile() camera_file.open('/tmp/file_to_upload.jpg') # Upload to camera camera.folder_put_file('/', 'uploaded.jpg', gp.GP_FILE_TYPE_NORMAL, camera_file) camera.exit() ``` -------------------------------- ### Set Idle Event Callback Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/context.md Install a function to be called when the camera is idle. User data can be passed to the callback. ```python def on_idle(context, data): print("Camera idle") callback_obj = context.set_idle_func(on_idle, data="user_data") ``` -------------------------------- ### Initialize Camera Connection in Python Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/INDEX.md Use this snippet to establish a connection with the camera. Ensure the camera is connected before calling this method. ```python camera = gp.Camera(); camera.init() ``` -------------------------------- ### get_port_info Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera.md Gets the port information for the current camera connection. This method returns details about the communication port being used. ```APIDOC ## get_port_info ### Description Gets the port information for the current camera connection. This method returns details about the communication port being used. ### Method `camera.get_port_info()` ### Returns `gphoto2.GPPortInfo` — Port information structure ``` -------------------------------- ### Python CameraList Length Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-list.md Illustrates how to get the total number of items in a CameraList using the built-in len() function. ```python num_items = len(list) ``` -------------------------------- ### Navigating and Modifying Widget Tree Configuration Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/README.md Demonstrates how to access and modify camera configuration settings organized as a hierarchical widget tree. Changes are applied by setting the configuration back to the camera. ```python config = camera.get_config() # Root widget iso = config.get_child_by_name('iso') # Navigate tree value = iso.get_value() # Get/set typed values iso.set_value('400') camera.set_config(config) # Apply changes ``` -------------------------------- ### Get Library and Dependency Versions Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/README.md Retrieve the version information for the python-gphoto2 bindings, the libgphoto2 library, and the libgphoto2_port library. ```python import gphoto2 as gp gp.__version__ # Python bindings version gp.gp_library_version(gp.GP_VERSION_SHORT) # libgphoto2 version gp.gp_port_library_version(gp.GP_VERSION_VERBOSE) # libgphoto2_port version ``` -------------------------------- ### Get Widget ID Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-widget.md Retrieves a unique integer identifier for a CameraWidget. This ID can be used for internal tracking or referencing. ```python widget_id = widget.get_id() ``` -------------------------------- ### Get Widget Name Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-widget.md Obtains the internal, programmatic name of a CameraWidget. This is often used when accessing widgets by name. ```python name = widget.get_name() ``` -------------------------------- ### Widget Value Types Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/QUICK_REFERENCE.md Illustrates the Python data types and example values corresponding to different gphoto2 widget types. ```python gp.GP_WIDGET_TEXT | '100' gp.GP_WIDGET_RANGE | 400.0 gp.GP_WIDGET_TOGGLE | 0 or 1 gp.GP_WIDGET_DATE | 1234567890 gp.GP_WIDGET_MENU | 'Manual' gp.GP_WIDGET_RADIO | 'AE' ``` -------------------------------- ### Get Storage Information Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera.md Retrieve information about storage devices on the camera using `get_storageinfo`. This returns a list of `CameraStorageInformation` objects. ```python storage_list = camera.get_storageinfo() for storage_info in storage_list: print(f"Total space: {storage_info.capacitykbytes} KB") ``` -------------------------------- ### Get Port Information Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera.md Retrieve details about the camera's connection port using `get_port_info`. This returns a `GPPortInfo` structure. ```python camera.get_port_info() ``` -------------------------------- ### Discover and Run All Tests Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/tests/README.rst Utilize the unittest discover facility to find and execute all tests within the tests directory. This is the recommended way to run the full test suite. ```python python -m unittest discover tests ``` -------------------------------- ### Custom CameraList Operations in Python Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-list.md Illustrates creating a custom CameraList, populating it with items, sorting it, and accessing/modifying elements by index and name. It also shows how to find an item's index by its name. ```python import gphoto2 as gp # Create and populate a list my_list = gp.CameraList() my_list.append('first', 'value1') my_list.append('second', 'value2') my_list.append('third', 'value3') # Sort alphabetically my_list.sort() # Access by index print(my_list[0]) # ('first', 'value1') # Access by name print(my_list['second']) # 'value2' # Modify my_list.set_value(1, 'updated_value') # Find idx = my_list.find_by_name('third') print(idx) # 2 ``` -------------------------------- ### Get Parent Camera Widget Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-widget.md Retrieves the parent widget of the current widget. Returns None if the current widget is the root. ```python camera_widget.get_parent() ``` ```python parent = widget.get_parent() ``` -------------------------------- ### Create GPPortInfoList Instance Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/port-info.md Instantiate a new GPPortInfoList object to manage port information. This is the first step before loading or querying port data. ```python import gphoto2 as gp port_list = gp.GPPortInfoList() ``` -------------------------------- ### GPContext Methods Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/INDEX.md Methods for setting up callbacks and context for gphoto2 operations. ```APIDOC ## GPContext Methods - `set_idle_func(func, data)` — Idle callback - `set_error_func(func, data)` — Error callback - `set_status_func(func, data)` — Status callback - `set_message_func(func, data)` — Message callback - `set_question_func(func, data)` — Question callback - `set_cancel_func(func, data)` — Cancel callback - `set_progress_funcs(start, update, stop, data)` — Progress callbacks ``` -------------------------------- ### Camera Widget Types Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/types.md Describes the type of a configuration widget. Use CameraWidget.get_type() to determine the widget type before getting or setting values. ```c enum CameraWidgetType { GP_WIDGET_WINDOW, // Container/root widget GP_WIDGET_SECTION, // Section/group GP_WIDGET_TEXT, // Text input field GP_WIDGET_RANGE, // Numeric range slider GP_WIDGET_TOGGLE, // On/off toggle (checkbox) GP_WIDGET_RADIO, // Radio button group GP_WIDGET_MENU, // Dropdown menu GP_WIDGET_BUTTON // Action button } ``` -------------------------------- ### Control Menu/Radio Widget (White Balance) Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-widget.md Demonstrates how to list available white balance modes and set the camera to the first available mode. ```python import gphoto2 as gp camera = gp.Camera() camera.init() config = camera.get_config() white_balance = config.get_child_by_name('whitebalance') print("Available white balance modes:") for i in range(white_balance.count_choices()): mode = white_balance.get_choice(i) print(f" {mode}") # Set to first available mode white_balance.set_value(white_balance.get_choice(0)) camera.set_config(config) camera.exit() ``` -------------------------------- ### Get File Metadata from Camera Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera.md Retrieves metadata information for a specific file located in a folder on the camera. An optional context can be provided. ```python camera.file_get_info(folder, file, context=None) ``` ```python info = camera.file_get_info('/', 'photo.jpg') print(f"Size: {info.file.size} bytes") ``` -------------------------------- ### Create CameraFile from file descriptor Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-file.md Initialize a CameraFile object using an existing operating system file descriptor. This allows the CameraFile to manage data associated with that descriptor. ```python import os fd = os.open('/tmp/camera_file', os.O_WRONLY | os.O_CREAT) file = gp.CameraFile(fd) ``` -------------------------------- ### Get Name by Index from CameraList Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-list.md Retrieve the name of an item at a specific zero-based index in the CameraList. An error is thrown if the index is out of bounds. ```python name = list.get_name(0) ``` -------------------------------- ### camera.list_config Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera.md Lists all configurable camera settings available. ```APIDOC ## camera.list_config() ### Description Lists all configurable camera settings. ### Method `camera.list_config(context=None)` ### Parameters #### Optional Parameters - **context** (`gphoto2.GPContext`) - Optional context for callbacks ### Returns `gphoto2.CameraList` — List of configuration option names ### Example ```python config_list = camera.list_config() for n in range(len(config_list)): name = config_list.get_name(n) print(name) ``` ``` -------------------------------- ### Control Range Widget (Zoom) Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-widget.md Shows how to get the range of a zoom widget, set its value to the midpoint, and then apply the configuration to the camera. ```python import gphoto2 as gp camera = gp.Camera() camera.init() config = camera.get_config() zoom = config.get_child_by_name('zoom') min_z, max_z, step = zoom.get_range() current = zoom.get_value() print(f"Zoom: {current} (range: {min_z}-{max_z}, step: {step})") zoom.set_value(min_z + (max_z - min_z) / 2) # Set to middle camera.set_config(config) camera.exit() ``` -------------------------------- ### Get Widget Value Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-widget.md Fetches the current value of a CameraWidget. The data type of the returned value depends on the widget's type. ```python value = widget.get_value() print(f"Current ISO: {value}") ``` -------------------------------- ### load() Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/abilities-list.md Loads the camera abilities database from the system into the CameraAbilitiesList instance. ```APIDOC ## load() ### Description Loads the camera abilities database from the system. ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Parameters * **context** (`gphoto2.GPContext`, Optional) - Optional context for callbacks ### Returns `None` ### Throws `gphoto2.GPhoto2Error` — If loading fails ### Example ```python abilities_list = gp.CameraAbilitiesList() abilities_list.load() ``` ``` -------------------------------- ### GPContext Constructor Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/context.md Creates a new GPContext instance with no callbacks installed. This context is used to manage communication and event handlers for gphoto2 operations. ```APIDOC ## GPContext() ### Description Creates a new context with no callbacks installed. ### Returns `gphoto2.GPContext` — A new context instance. ### Example ```python import gphoto2 as gp context = gp.GPContext() ``` ``` -------------------------------- ### Iterate and Print Widget Choices Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-widget.md Demonstrates how to loop through all available choices for a widget and print each one. This is useful for understanding the options a widget provides. ```python for i in range(widget.count_choices()): choice = widget.get_choice(i) print(choice) ``` -------------------------------- ### Load Camera Abilities from Directory Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/abilities-list.md Loads camera abilities from a specific directory. This is useful for custom configurations or when the default system directory is not accessible. ```python abilities_list.load_dir('/usr/share/libgphoto2') ``` -------------------------------- ### Get Value by Index from CameraList Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-list.md Retrieve the value associated with an item at a specific zero-based index in the CameraList. An error is thrown if the index is out of bounds. ```python value = list.get_value(0) ``` -------------------------------- ### Get CameraList Item Count Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-list.md Retrieve the total number of items currently stored in the CameraList. Useful for iteration or checking if the list is empty. ```python num_items = list.count() ``` -------------------------------- ### Using Context with Camera Operations Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/context.md Demonstrates passing a configured `GPContext` object to camera methods like `init` and `capture`. This allows camera operations to utilize the set callbacks. ```python camera = gp.Camera() context = gp.GPContext() context.set_progress_funcs(on_start, on_update, on_stop) camera.init(context) camera.capture(gp.GP_CAPTURE_IMAGE, context) ``` -------------------------------- ### Get Child Camera Widget by Name Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-widget.md Finds a child widget by its internal programmatic name. This is useful when the label might change or for scripting. ```python camera_widget.get_child_by_name(name) ``` ```python iso_widget = config.get_child_by_name('iso') ``` -------------------------------- ### Import gphoto2 Module Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/QUICK_REFERENCE.md Import the gphoto2 library to begin using its functionalities. ```python import gphoto2 as gp ``` -------------------------------- ### Get Child Camera Widget by Index Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-widget.md Retrieves a specific child widget using its 0-based index. An error is thrown if the index is out of range. ```python camera_widget.get_child(index) ``` ```python for i in range(widget.count_children()): child = widget.get_child(i) print(child.get_label()) ``` -------------------------------- ### CameraFile Constructors Source: https://github.com/jim-easterbrook/python-gphoto2/blob/main/_autodocs/api-reference/camera-file.md Provides documentation for the two constructors of the CameraFile class: the default constructor and the constructor that accepts a file descriptor. ```APIDOC ## CameraFile Constructors ### Default Constructor ```python CameraFile() ``` Creates an empty file object. **Returns:** `gphoto2.CameraFile` — A new file instance. ### File Descriptor Constructor ```python CameraFile(fd) ``` Creates a file object from a file descriptor. | Parameter | Type | Required | Description | |-----------|------|----------|-------------| | fd | int | Yes | Operating system file descriptor | **Returns:** `gphoto2.CameraFile` — File object backed by the descriptor ```