From 7ea6e4dbc722dc11913340934711cbf7f18fce82 Mon Sep 17 00:00:00 2001 From: Bingsu Date: Fri, 12 May 2023 12:08:27 +0900 Subject: [PATCH] refactor: widgets as userdict --- scripts/!adetailer.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/scripts/!adetailer.py b/scripts/!adetailer.py index 19b3c89..ca18bf8 100644 --- a/scripts/!adetailer.py +++ b/scripts/!adetailer.py @@ -3,10 +3,12 @@ from __future__ import annotations import platform import sys import traceback +from collections import UserDict from copy import copy, deepcopy from itertools import zip_longest from pathlib import Path from textwrap import dedent +from typing import Any import gradio as gr import torch @@ -50,9 +52,18 @@ print( ) -class Widgets: +class Widgets(UserDict): + def __getattribute__(self, __name: str) -> Any: + return self.__getitem__(__name) + + def __setattr__(self, __name: str, __value: Any) -> None: + self.__setitem__(__name, __value) + + def __delattr__(self, __name: str) -> None: + self.__delitem__(__name) + def tolist(self): - return [getattr(self, attr) for attr, *_ in ALL_ARGS[1:]] + return [self[attr] for attr, *_ in ALL_ARGS[1:]] class ChangeTorchLoad: @@ -64,7 +75,7 @@ class ChangeTorchLoad: torch.load = self.orig -def gr_show(visible=True): +def gr_show(visible: bool = True): return {"visible": visible, "__type__": "update"}