Skip to content

Registry Handler

RegistryHandler

RegistryHandler()

Helper for bridging between pure ContextMenu objects and the registry.

Source code in windows_context_menus/registry/registry_handler.py
14
15
16
def __init__(self) -> None:
    """Basic initialization of RegistryHandler."""
    self.exporter = RegistryExporter()

apply_context_menu

apply_context_menu(
    menu: ContextMenu, bindings: list[ContextMenuBinding]
) -> None

Apply context menu to the registry for specified bindings.

Source code in windows_context_menus/registry/registry_handler.py
18
19
20
21
22
23
24
25
26
27
def apply_context_menu(
    self,
    menu: ContextMenu,
    bindings: list[ContextMenuBinding],
) -> None:
    """Apply context menu to the registry for specified bindings."""
    built_menu: RegistryKey = self.exporter.export_tree(menu)

    for binding in bindings:
        binding.to_path().write(built_menu)

export_reg_file

export_reg_file(
    menu: ContextMenu, bindings: list[ContextMenuBinding]
) -> list[str]

Export the Context Menu as a .reg file format.

Example
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\Software\Classes\*\shell\ConvertVideo]
"MUIVerb"="Convert mp4..."

Returns:

Type Description
list[str]

A list of lines of the .reg file.

References
Source code in windows_context_menus/registry/registry_handler.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def export_reg_file(self, menu: ContextMenu, bindings: list[ContextMenuBinding]) -> list[str]:
    r"""Export the Context Menu as a .reg file format.

    Example:
        ```
        Windows Registry Editor Version 5.00

        [HKEY_LOCAL_MACHINE\Software\Classes\*\shell\ConvertVideo]
        "MUIVerb"="Convert mp4..."
        ```

    Returns:
        A list of lines of the .reg file.

    References:
        [^1]: <https://support.microsoft.com/en-us/topic/how-to-add-modify-or-delete-registry-subkeys-and-values-by-using-a-reg-file-9c7f37cf-a5e9-e1cd-c4fa-2a26218a1a23>
    """
    return self.exporter.export_reg_file(menu, bindings)