From 90e006980ec51d49a957ab877d2da34e94ee9324 Mon Sep 17 00:00:00 2001 From: manatlan Date: Thu, 11 Apr 2024 16:00:40 +0200 Subject: [PATCH] Update htag.txt fix tag open/closed and boolean attributs --- brython/htag.txt | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/brython/htag.txt b/brython/htag.txt index bbd587c..fdee0f5 100644 --- a/brython/htag.txt +++ b/brython/htag.txt @@ -1,14 +1,8 @@ #------------------------------------------------------------------------------------------------------------------------------- # An "htag.Tag" implem for brython (see https://github.com/manatlan/htag/tree/main/brython) #------------------------------------------------------------------------------------------------------------------------------- -# In html/head add: -# -# In script/python add: -# from htag import Tag -#------------------------------------------------------------------------------------------------------------------------------- from browser import html,document,window - def importStatics(): import __main__ if not document.hasOwnProperty("htagStaticsImported"): @@ -57,11 +51,19 @@ class TAG: # it's "open tag" (accept redef) (it should got a 'init( ..., **a)' ) # (because it tries call with "_var") for k,v in attrs.items(): - self.attrs[k]=v + if isinstance(v,bool): + if v: self.attrs[k]="" + else: + self.attrs[k]=v for k,v in events.items(): self.bind(k,v) - constructor(*args,**props,**kargs) # to produce a typeerror if not "opened" + kargs={k:v for k,v in kargs.items() if k not in props} + try: + constructor(*args,**props,**kargs) # to produce a typeerror if not "opened" + except Exception as e: + print(f"***ERROR*** {self.__class__.__name__} constructor:",e) + raise e else: # it's "closed tag" (refuse redef) constructor(*args,**kargs) @@ -91,7 +93,10 @@ class TAG: self <= content for k,v in attrs.items(): - self.attrs[k]=v + if isinstance(v,bool): + if v: self.attrs[k]="" + else: + self.attrs[k]=v for k,v in events.items(): self.bind(k,v) for k,v in props.items():