.. This file is autogenerated. Do not edit. It will be overwritten. Edit the file in the examples directory and generate the docs again.

InstallWithPortal
==========================

.. code:: python

    import desktop_entry_lib
    import sys
    
    
    def main() -> None:
        entry = desktop_entry_lib.DesktopEntry()
        entry.Name.default_text = "My Name"
        entry.desktop_id = "com.example.App.Entry"
        entry.Exec = "firefox"
    
        path = input("Please enter the path to an icon file:")
    
        if path == "":
            print("You haven't entered a path", file=sys.stderr)
            sys.exit(1)
    
        try:
            with open(path, "rb") as f:
                icon = f.read()
        except FileNotFoundError:
            print(f"{path} was not found", file=sys.stderr)
            sys.exit(1)
    
        try:
            response = entry.install_with_portal("", icon)
        except ModuleNotFoundError:
            print('jeepney is not installed. Run "pip install jeepney"', file=sys.stderr)
            sys.exit(1)
        except desktop_entry_lib.InstallWithPortalsNotAvailable:
            print("The DynamicLauncher portal is not available", file=sys.stderr)
            sys.exit(1)
        except desktop_entry_lib.InstallWithPortalError as ex:
            print(f"An error occurred: {ex.message}", file=sys.stderr)
            sys.exit(1)
        except desktop_entry_lib.InstallWithPortalsCanceled:
            print("The user canceled the installation", file=sys.stderr)
            sys.exit(1)
    
        print(f"Your desktop entry was successfully installed with the name {response['Name']}.")
    
    
    if __name__ == "__main__":
        main()


:repolink:`View this example on Codeberg <examples/InstallWithPortal.py>`