|
|
|
@ -39,7 +39,7 @@ import inspect |
|
|
|
# From |
|
|
|
# From |
|
|
|
# https://stackoverflow.com/questions/3232024/introspection-to-get-decorator-names-on-a-method |
|
|
|
# https://stackoverflow.com/questions/3232024/introspection-to-get-decorator-names-on-a-method |
|
|
|
|
|
|
|
|
|
|
|
def get_decorators(cls): |
|
|
|
def _get_decorators(cls): |
|
|
|
target = cls |
|
|
|
target = cls |
|
|
|
decorators = {} |
|
|
|
decorators = {} |
|
|
|
|
|
|
|
|
|
|
|
@ -59,6 +59,11 @@ def get_decorators(cls): |
|
|
|
node_iter.visit(ast.parse(inspect.getsource(target))) |
|
|
|
node_iter.visit(ast.parse(inspect.getsource(target))) |
|
|
|
return decorators |
|
|
|
return decorators |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _get_attributes(obj,filter): |
|
|
|
|
|
|
|
return sorted([item for item in (set(dir(obj)) - set(filter)) if not item.startswith('_') and not inspect.isclass(getattr(obj,item))]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _get_classes(obj,filter): |
|
|
|
|
|
|
|
return sorted([item for item in (set(dir(obj)) - set(filter)) if not item.startswith('_') and inspect.isclass(getattr(obj,item))]) |
|
|
|
|
|
|
|
|
|
|
|
_styleMatch = re.compile('^ *classStyle') |
|
|
|
_styleMatch = re.compile('^ *classStyle') |
|
|
|
_colorMatch = re.compile('^#[0-9a-fA-F]{6}') |
|
|
|
_colorMatch = re.compile('^#[0-9a-fA-F]{6}') |
|
|
|
@ -83,11 +88,11 @@ def _get_classStyleCode(obj) -> list[str]: |
|
|
|
# print(line) |
|
|
|
# print(line) |
|
|
|
# print(f"{_styleMatch.match(line)=}") |
|
|
|
# print(f"{_styleMatch.match(line)=}") |
|
|
|
if curlyBraket == 0 and _styleMatch.match(line): |
|
|
|
if curlyBraket == 0 and _styleMatch.match(line): |
|
|
|
print(line) |
|
|
|
# print(line) |
|
|
|
ret.append(line) |
|
|
|
ret.append(line) |
|
|
|
curlyBraket += _processLine(line) |
|
|
|
curlyBraket += _processLine(line) |
|
|
|
elif curlyBraket > 0: |
|
|
|
elif curlyBraket > 0: |
|
|
|
print(line) |
|
|
|
# print(line) |
|
|
|
ret.append(line) |
|
|
|
ret.append(line) |
|
|
|
curlyBraket += _processLine(line) |
|
|
|
curlyBraket += _processLine(line) |
|
|
|
if curlyBraket == 0: |
|
|
|
if curlyBraket == 0: |
|
|
|
@ -102,13 +107,45 @@ def setup(app: Sphinx) -> ExtensionMetadata: |
|
|
|
modSub = {} |
|
|
|
modSub = {} |
|
|
|
modSubSorted = {} |
|
|
|
modSubSorted = {} |
|
|
|
modStyles = {} |
|
|
|
modStyles = {} |
|
|
|
|
|
|
|
|
|
|
|
ttkAllSignals={} |
|
|
|
ttkAllSignals={} |
|
|
|
|
|
|
|
ttkAllMethods={} |
|
|
|
ttkAllSlots={} |
|
|
|
ttkAllSlots={} |
|
|
|
|
|
|
|
ttkAllMembers={} # List all the member of a class |
|
|
|
|
|
|
|
ttkInherited={} # List of the inherited classes for each class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _getMethodsAndSlots(_obj): |
|
|
|
|
|
|
|
retSlots = [] |
|
|
|
|
|
|
|
retMethods = [] |
|
|
|
|
|
|
|
def _hasmethod(obj, name): |
|
|
|
|
|
|
|
return hasattr(obj, name) and type(getattr(obj, name)) in (types.MethodType, types.FunctionType) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _name in (_dec:=_get_decorators(_obj)): |
|
|
|
|
|
|
|
if _name.startswith('_'): continue |
|
|
|
|
|
|
|
if _hasmethod(_obj,_name): |
|
|
|
|
|
|
|
retMethods.append(_name) |
|
|
|
|
|
|
|
for _decorator in _dec[_name]: |
|
|
|
|
|
|
|
if "pyTTkSlot"in _decorator: |
|
|
|
|
|
|
|
retSlots.append(_name) |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
return retMethods,retSlots |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _getInherited(_obj): |
|
|
|
|
|
|
|
ret = [] |
|
|
|
|
|
|
|
for cc in _obj.__mro__: |
|
|
|
|
|
|
|
if cc==_obj: continue |
|
|
|
|
|
|
|
# if hasattr(cc,'_ttkProperties'): |
|
|
|
|
|
|
|
if issubclass(cc, ttk.TTkWidget) or issubclass(cc, ttk.TTkLayout): |
|
|
|
|
|
|
|
ccName = cc.__name__ |
|
|
|
|
|
|
|
ret.append(ccName) |
|
|
|
|
|
|
|
# print(ccName) |
|
|
|
|
|
|
|
# print(f"_getInherited {ret}") |
|
|
|
|
|
|
|
return ret |
|
|
|
|
|
|
|
|
|
|
|
def _getSignals(_obj): |
|
|
|
def _getSignals(_obj): |
|
|
|
ret = [] |
|
|
|
ret = [] |
|
|
|
for _name in (_th:=get_type_hints(_obj)): |
|
|
|
for _name in (_th:=get_type_hints(_obj)): |
|
|
|
print(f"{_th=}") |
|
|
|
# print(f"{_th=}") |
|
|
|
if _name.startswith('_'): continue |
|
|
|
if _name.startswith('_'): continue |
|
|
|
if 'pyTTkSignal' in str(_th[_name]): |
|
|
|
if 'pyTTkSignal' in str(_th[_name]): |
|
|
|
ret.append(_name) |
|
|
|
ret.append(_name) |
|
|
|
@ -119,12 +156,19 @@ def setup(app: Sphinx) -> ExtensionMetadata: |
|
|
|
def _parseModules(_mod): |
|
|
|
def _parseModules(_mod): |
|
|
|
if _file:=getattr(_mod,'__file__',None): |
|
|
|
if _file:=getattr(_mod,'__file__',None): |
|
|
|
if '__init__.py' in _file and '/TermTk/' in _file: |
|
|
|
if '__init__.py' in _file and '/TermTk/' in _file: |
|
|
|
print(_file) |
|
|
|
# print(_file) |
|
|
|
for _name, _obj in inspect.getmembers(_mod): |
|
|
|
for _name, _obj in inspect.getmembers(_mod): |
|
|
|
if _mod.__name__ == 'TermTk.TTkCore.drivers': continue |
|
|
|
if _mod.__name__ == 'TermTk.TTkCore.drivers': continue |
|
|
|
if inspect.isclass(_obj): |
|
|
|
if inspect.isclass(_obj): |
|
|
|
|
|
|
|
_meth,_slots = _getMethodsAndSlots(_obj) |
|
|
|
|
|
|
|
if _name not in ttkAllMethods: |
|
|
|
|
|
|
|
ttkAllMethods[_name] = _meth |
|
|
|
|
|
|
|
if _name not in ttkAllSlots: |
|
|
|
|
|
|
|
ttkAllSlots[_name] = _slots |
|
|
|
if _name not in ttkAllSignals: |
|
|
|
if _name not in ttkAllSignals: |
|
|
|
ttkAllSignals[_name] = _getSignals(_obj) |
|
|
|
ttkAllSignals[_name] = _getSignals(_obj) |
|
|
|
|
|
|
|
if _name not in ttkInherited: |
|
|
|
|
|
|
|
ttkInherited[_name] = _getInherited(_obj) |
|
|
|
if _name not in modStyles: |
|
|
|
if _name not in modStyles: |
|
|
|
modStyles[_name] = _get_classStyleCode(_obj) |
|
|
|
modStyles[_name] = _get_classStyleCode(_obj) |
|
|
|
if _name not in modules: |
|
|
|
if _name not in modules: |
|
|
|
@ -164,81 +208,78 @@ def setup(app: Sphinx) -> ExtensionMetadata: |
|
|
|
for x in b: |
|
|
|
for x in b: |
|
|
|
print (f" - {x}") |
|
|
|
print (f" - {x}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (x,y) in ttkInherited.items(): |
|
|
|
|
|
|
|
print(f"Inherited {x} -> {y}") |
|
|
|
|
|
|
|
|
|
|
|
# print(modStyles) |
|
|
|
# print(modStyles) |
|
|
|
|
|
|
|
|
|
|
|
# raise Exception |
|
|
|
# raise Exception |
|
|
|
|
|
|
|
|
|
|
|
def generate_autosummary_content( |
|
|
|
def generate_autosummary_content_hack( |
|
|
|
name, obj, parent, template, template_name, imported_members, |
|
|
|
name, obj, parent, template, template_name, imported_members, |
|
|
|
app, recursive, context, modname, qualname, |
|
|
|
app, recursive, context, modname, qualname, |
|
|
|
generate_autosummary_content_old = seautogenerate.generate_autosummary_content |
|
|
|
generate_autosummary_content_old = seautogenerate.generate_autosummary_content |
|
|
|
) -> str: |
|
|
|
) -> str: |
|
|
|
print(f"-----------------> OVERRIDEEEEE!!! {type(context)}") |
|
|
|
print(f"-----------------> OVERRIDEEEEE!!! {type(context)}") |
|
|
|
print(f"{name=}") |
|
|
|
print(f"{name=}") |
|
|
|
print(f"{obj=}") |
|
|
|
# print(f"{obj=}") |
|
|
|
print(f"{parent=}") |
|
|
|
# print(f"{parent=}") |
|
|
|
print(f"{template=}") |
|
|
|
# print(f"{template=}") |
|
|
|
print(f"{template_name=}") |
|
|
|
# print(f"{template_name=}") |
|
|
|
print(f"{imported_members=}") |
|
|
|
# print(f"{imported_members=}") |
|
|
|
print(f"{app=}") |
|
|
|
# print(f"{app=}") |
|
|
|
print(f"{recursive=}") |
|
|
|
# print(f"{recursive=}") |
|
|
|
print(f"{context=}") |
|
|
|
# print(f"{context=}") |
|
|
|
print(f"{modname=}") |
|
|
|
print(f"{modname=}") |
|
|
|
print(f"{qualname=}") |
|
|
|
print(f"{qualname=}") |
|
|
|
|
|
|
|
|
|
|
|
ttkSignals = [] |
|
|
|
ttkSignals = [] |
|
|
|
ttkSignalsImported = {} |
|
|
|
ttkSignalsImported = {} |
|
|
|
ttkSlots = [] |
|
|
|
ttkSlots = [] |
|
|
|
ttkSlotsImported = {} |
|
|
|
ttkSlotsInherited = {} |
|
|
|
ttkMethods = [] |
|
|
|
ttkMethods = [] |
|
|
|
ttkInheritedMethods = [] |
|
|
|
ttkInheritedMethods = [] |
|
|
|
ttkSubClasses = modSorted.get(name,[]) |
|
|
|
ttkSubClasses = modSorted.get(name,[]) |
|
|
|
ttkSubModules = modSubSorted.get(name,[]) |
|
|
|
ttkSubModules = modSubSorted.get(name,[]) |
|
|
|
|
|
|
|
|
|
|
|
# ns['members'] = dir(obj) |
|
|
|
def _get_slots_in_obj(_name): |
|
|
|
# ns['inherited_members'] = set(dir(obj)) - set(obj.__dict__.keys()) |
|
|
|
_slotsInherited = {_sub : sorted(ttkAllSlots.get(_sub,[])) for _sub in ttkInherited.get(_name,[])} |
|
|
|
# ns['methods'], ns['all_methods'] = _get_members( |
|
|
|
_slots = set(ttkAllSlots.get(_name,[])) - set([_sl for _subSl in _slotsInherited.values() for _sl in _subSl]) |
|
|
|
# doc, app, obj, {'method'}, include_public={'__init__'} |
|
|
|
return sorted(list(_slots)), _slotsInherited |
|
|
|
# ) |
|
|
|
|
|
|
|
# ns['attributes'], ns['all_attributes'] = _get_members( |
|
|
|
ttkSlots, ttkSlotsInherited = _get_slots_in_obj(qualname) |
|
|
|
# doc, app, obj, {'attribute', 'property'} |
|
|
|
|
|
|
|
# ) |
|
|
|
def _get_attributes_in_obj(_obj,_name): |
|
|
|
|
|
|
|
_allMethods = ttkAllMethods.get(_name,[]) |
|
|
|
print(f"{obj=}") |
|
|
|
_slots = ttkAllSlots.get(_name,[]) |
|
|
|
# for member in inspect.getmembers(obj): |
|
|
|
_signals = ttkAllSignals.get(_name,[]) |
|
|
|
# _name = member[0] |
|
|
|
_classes = _get_classes(_obj,[]) |
|
|
|
# if _name.startswith('_'): continue |
|
|
|
return _get_attributes(_obj,_allMethods+_slots+_signals+_classes) |
|
|
|
# _hint = get_type_hints(obj)[_name] |
|
|
|
|
|
|
|
|
|
|
|
def _get_simple_attributes(_obj): |
|
|
|
# print(f"{obj=} - {get_type_hints(obj)=}") |
|
|
|
return sorted(set( |
|
|
|
# for _name in (_th:=get_type_hints(obj)): |
|
|
|
[item for item in dir(obj) |
|
|
|
# print(f"{_th=}") |
|
|
|
if ( |
|
|
|
# if _name.startswith('_'): continue |
|
|
|
not ( |
|
|
|
# if 'pyTTkSignal' in str(_th[_name]): |
|
|
|
item.startswith('_') or |
|
|
|
# ttkSignals.append(_name) |
|
|
|
inspect.isclass( _attr:=getattr(obj,item)) or |
|
|
|
# else: |
|
|
|
inspect.ismethod( _attr) or |
|
|
|
# print(ttk.TTkString(f"element not typed: {_name} - { _th[_name]}",ttk.TTkColor.BG_CYAN)) |
|
|
|
inspect.isfunction(_attr) |
|
|
|
# print(ttkSignals) |
|
|
|
) ) ] ) ) |
|
|
|
|
|
|
|
|
|
|
|
def _hasmethod(obj, name): |
|
|
|
ttkAttributes = sorted(set(_get_simple_attributes(obj)) - set(ttkAllSignals.get(qualname,''))) |
|
|
|
return hasattr(obj, name) and type(getattr(obj, name)) in (types.MethodType, types.FunctionType) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _name in (_dec:=get_decorators(obj)): |
|
|
|
|
|
|
|
if _name.startswith('_'): continue |
|
|
|
|
|
|
|
if _hasmethod(obj,_name): |
|
|
|
|
|
|
|
ttkMethods.append(_name) |
|
|
|
|
|
|
|
for _decorator in _dec[_name]: |
|
|
|
|
|
|
|
if "pyTTkSlot"in _decorator: |
|
|
|
|
|
|
|
ttkSlots.append(_name) |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context |= { |
|
|
|
context |= { |
|
|
|
|
|
|
|
'TTkAttributes':ttkAttributes, |
|
|
|
|
|
|
|
'TTkClasses':_get_classes(obj,ttkMethods+ttkSlots+ttkAllSignals.get(qualname,[])), |
|
|
|
'TTkStyle':modStyles.get(qualname,''), |
|
|
|
'TTkStyle':modStyles.get(qualname,''), |
|
|
|
'TTkSignals':ttkAllSignals.get(qualname,''), |
|
|
|
'TTkSignals':ttkAllSignals.get(qualname,''), |
|
|
|
'TTkSubClasses': ttkSubClasses, |
|
|
|
'TTkSubClasses': ttkSubClasses, |
|
|
|
'TTkSubModules': ttkSubModules, |
|
|
|
'TTkSubModules': ttkSubModules, |
|
|
|
'TTkMethods':ttkMethods, |
|
|
|
'TTkMethods':ttkAllMethods.get(qualname,''), |
|
|
|
'TTkSlots':ttkSlots} |
|
|
|
'TTkSlots':ttkSlots, |
|
|
|
|
|
|
|
'TTkSlotsInherited':ttkSlotsInherited, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
print('\n'.join([f" * {x}={context[x]}" for x in context])) |
|
|
|
print('\n'.join([f" * {x}={context[x]}" for x in context])) |
|
|
|
|
|
|
|
|
|
|
|
@ -246,6 +287,24 @@ def setup(app: Sphinx) -> ExtensionMetadata: |
|
|
|
name, obj, parent, template, template_name, imported_members, |
|
|
|
name, obj, parent, template, template_name, imported_members, |
|
|
|
app, recursive, context, modname, qualname) |
|
|
|
app, recursive, context, modname, qualname) |
|
|
|
|
|
|
|
|
|
|
|
seautogenerate.generate_autosummary_content = generate_autosummary_content |
|
|
|
# def get_import_prefixes_from_env_hack(env, get_import_prefixes_from_env_old=seauto.get_import_prefixes_from_env) -> list[str | None]: |
|
|
|
|
|
|
|
# pyClass = env.ref_context.get('py:class') |
|
|
|
|
|
|
|
# # env.ref_context.set('py:class') |
|
|
|
|
|
|
|
# prefixes = get_import_prefixes_from_env_old(env) |
|
|
|
|
|
|
|
# retPrefixes = [] |
|
|
|
|
|
|
|
# for p in prefixes: |
|
|
|
|
|
|
|
# if not p: |
|
|
|
|
|
|
|
# retPrefixes.append(p) |
|
|
|
|
|
|
|
# continue |
|
|
|
|
|
|
|
# psplit = p.split('.') |
|
|
|
|
|
|
|
# cur = ret = psplit[0] |
|
|
|
|
|
|
|
# for pp in psplit[1:]: |
|
|
|
|
|
|
|
# print(f"SPLIT: {pp} - {pyClass=} - {prefixes}") |
|
|
|
|
|
|
|
# if cur != pp: |
|
|
|
|
|
|
|
# ret += f".{pp}" |
|
|
|
|
|
|
|
# retPrefixes.append(ret) |
|
|
|
|
|
|
|
# return retPrefixes |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
seautogenerate.generate_autosummary_content = generate_autosummary_content_hack |
|
|
|
|
|
|
|
# seauto.get_import_prefixes_from_env = get_import_prefixes_from_env_hack |
|
|
|
return seauto.setup(app) |
|
|
|
return seauto.setup(app) |
|
|
|
|