pyragephoto: add 'with' support

This commit is contained in:
Syping 2024-03-25 13:43:10 +01:00
parent c55b99e23f
commit 18325f7c05
1 changed files with 9 additions and 1 deletions

View File

@ -79,8 +79,16 @@ class RagePhoto:
def __init__(self):
self.__instance = libragephoto.ragephoto_open()
def __del__(self):
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
libragephoto.ragephoto_close(self.__instance)
self.__instance = None
def __del__(self):
if self.__instance is not None:
libragephoto.ragephoto_close(self.__instance)
def clear(self):
libragephoto.ragephoto_clear(self.__instance)