38 changed files with 1268 additions and 345 deletions
@ -1,56 +1,74 @@
|
||||
alabaster==0.7.12 |
||||
attrs==22.1.0 |
||||
Babel==2.10.3 |
||||
bleach==5.0.1 |
||||
build==0.8.0 |
||||
certifi==2022.6.15 |
||||
cffi==1.15.1 |
||||
charset-normalizer==2.1.0 |
||||
commonmark==0.9.1 |
||||
cryptography==37.0.4 |
||||
docutils==0.17.1 |
||||
flake8==5.0.4 |
||||
idna==3.3 |
||||
accessible-pygments==0.0.5 |
||||
alabaster==1.0.0 |
||||
babel==2.16.0 |
||||
backports.tarfile==1.2.0 |
||||
beautifulsoup4==4.12.3 |
||||
build==1.2.2.post1 |
||||
certifi==2024.8.30 |
||||
cffi==1.17.1 |
||||
charset-normalizer==3.4.0 |
||||
cryptography==43.0.3 |
||||
css-html-js-minify==2.5.5 |
||||
docutils==0.21.2 |
||||
flake8==7.1.1 |
||||
furo==2024.8.6 |
||||
idna==3.10 |
||||
imagesize==1.4.1 |
||||
importlib-metadata==4.12.0 |
||||
iniconfig==1.1.1 |
||||
importlib_metadata==8.5.0 |
||||
iniconfig==2.0.0 |
||||
jaraco.classes==3.4.0 |
||||
jaraco.context==6.0.1 |
||||
jaraco.functools==4.1.0 |
||||
jeepney==0.8.0 |
||||
Jinja2==3.1.2 |
||||
keyring==23.8.2 |
||||
MarkupSafe==2.1.1 |
||||
Jinja2==3.1.4 |
||||
keyring==25.4.1 |
||||
lxml==5.3.0 |
||||
markdown-it-py==3.0.0 |
||||
MarkupSafe==3.0.2 |
||||
mccabe==0.7.0 |
||||
packaging==21.3 |
||||
pep517==0.13.0 |
||||
pkginfo==1.8.3 |
||||
pluggy==1.0.0 |
||||
py==1.11.0 |
||||
pycodestyle==2.9.1 |
||||
pycparser==2.21 |
||||
pyflakes==2.5.0 |
||||
Pygments==2.12.0 |
||||
pyparsing==3.0.9 |
||||
pytest==7.1.2 |
||||
pytz==2022.1 |
||||
readme-renderer==36.0 |
||||
requests==2.28.1 |
||||
requests-toolbelt==0.9.1 |
||||
mdurl==0.1.2 |
||||
more-itertools==10.5.0 |
||||
nh3==0.2.18 |
||||
packaging==24.1 |
||||
piccolo_theme==0.24.0 |
||||
pkginfo==1.10.0 |
||||
pluggy==1.5.0 |
||||
pycodestyle==2.12.1 |
||||
pycparser==2.22 |
||||
pydata-sphinx-theme==0.16.0 |
||||
pyflakes==3.2.0 |
||||
Pygments==2.18.0 |
||||
pyproject_hooks==1.2.0 |
||||
pytest==8.3.3 |
||||
python-slugify==8.0.4 |
||||
readme_renderer==44.0 |
||||
requests==2.32.3 |
||||
requests-toolbelt==1.0.0 |
||||
rfc3986==2.0.0 |
||||
rich==12.5.1 |
||||
SecretStorage==3.3.2 |
||||
six==1.16.0 |
||||
rich==13.9.3 |
||||
SecretStorage==3.3.3 |
||||
snowballstemmer==2.2.0 |
||||
Sphinx==5.1.1 |
||||
soupsieve==2.6 |
||||
Sphinx==8.1.3 |
||||
sphinx-autodocgen==1.3 |
||||
sphinx-basic-ng==1.0.0b2 |
||||
sphinx-book-theme==1.1.3 |
||||
sphinx-epytext==0.0.4 |
||||
sphinx-rtd-theme==1.0.0 |
||||
sphinxcontrib-applehelp==1.0.2 |
||||
sphinxcontrib-devhelp==1.0.2 |
||||
sphinxcontrib-htmlhelp==2.0.0 |
||||
sphinx-material==0.0.36 |
||||
sphinx-rtd-theme==3.0.1 |
||||
sphinx-wagtail-theme==6.3.0 |
||||
sphinx_press_theme==0.9.1 |
||||
sphinxawesome-theme==5.3.1 |
||||
sphinxcontrib-applehelp==2.0.0 |
||||
sphinxcontrib-devhelp==2.0.0 |
||||
sphinxcontrib-htmlhelp==2.1.0 |
||||
sphinxcontrib-jquery==4.1 |
||||
sphinxcontrib-jsmath==1.0.1 |
||||
sphinxcontrib-qthelp==1.0.3 |
||||
sphinxcontrib-serializinghtml==1.1.5 |
||||
tomli==2.0.1 |
||||
twine==4.0.1 |
||||
urllib3==1.26.11 |
||||
webencodings==0.5.1 |
||||
zipp==3.8.1 |
||||
sphinxcontrib-qthelp==2.0.0 |
||||
sphinxcontrib-serializinghtml==2.0.0 |
||||
text-unidecode==1.3 |
||||
twine==5.1.1 |
||||
typing_extensions==4.12.2 |
||||
Unidecode==1.3.8 |
||||
urllib3==2.2.3 |
||||
zipp==3.20.2 |
||||
|
||||
@ -1 +1,3 @@
|
||||
autogen.* |
||||
autogen.* |
||||
_build |
||||
_autosummary |
||||
|
||||
@ -0,0 +1,35 @@
|
||||
@ECHO OFF |
||||
|
||||
pushd %~dp0 |
||||
|
||||
REM Command file for Sphinx documentation |
||||
|
||||
if "%SPHINXBUILD%" == "" ( |
||||
set SPHINXBUILD=sphinx-build |
||||
) |
||||
set SOURCEDIR=. |
||||
set BUILDDIR=_build |
||||
|
||||
%SPHINXBUILD% >NUL 2>NUL |
||||
if errorlevel 9009 ( |
||||
echo. |
||||
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx |
||||
echo.installed, then set the SPHINXBUILD environment variable to point |
||||
echo.to the full path of the 'sphinx-build' executable. Alternatively you |
||||
echo.may add the Sphinx directory to PATH. |
||||
echo. |
||||
echo.If you don't have Sphinx installed, grab it from |
||||
echo.https://www.sphinx-doc.org/ |
||||
exit /b 1 |
||||
) |
||||
|
||||
if "%1" == "" goto help |
||||
|
||||
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% |
||||
goto end |
||||
|
||||
:help |
||||
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% |
||||
|
||||
:end |
||||
popd |
||||
@ -0,0 +1,43 @@
|
||||
"""Sphinx extension to handle the signal directive in the method.""" |
||||
|
||||
__version__ = '2024.10' |
||||
|
||||
from typing import get_overloads |
||||
from typing import TYPE_CHECKING, Any, ClassVar, NamedTuple, cast |
||||
|
||||
from sphinx.util.inspect import signature, stringify_signature |
||||
|
||||
from sphinx import addnodes |
||||
from docutils import nodes |
||||
from docutils.parsers.rst import directives |
||||
from sphinx.domains.python import PyMethod, PyObject |
||||
|
||||
if True or TYPE_CHECKING: |
||||
from collections.abc import Sequence |
||||
|
||||
from docutils.nodes import Node, system_message |
||||
|
||||
from sphinx.application import Sphinx |
||||
from sphinx.extension import Extension |
||||
from sphinx.util.typing import ExtensionMetadata, OptionSpec |
||||
from sphinx.writers.html5 import HTML5Translator |
||||
|
||||
|
||||
|
||||
class TermTkMethod(PyMethod): |
||||
option_spec: ClassVar[OptionSpec] = PyMethod.option_spec.copy() |
||||
option_spec.update({ |
||||
'signal': directives.flag, |
||||
}) |
||||
|
||||
def get_signature_prefix(self, sig: str) -> list[nodes.Node]: |
||||
prefix: list[nodes.Node] = super().get_signature_prefix(sig) |
||||
if 'signal' in self.options: |
||||
prefix.append(nodes.Text('signal')) |
||||
prefix.append(addnodes.desc_sig_space()) |
||||
return prefix |
||||
|
||||
def setup(app: Sphinx) -> ExtensionMetadata: |
||||
'''Initialise the extension.''' |
||||
|
||||
app.add_directive_to_domain("py", "method", TermTkMethod, override=True) |
||||
@ -0,0 +1,229 @@
|
||||
"""Sphinx extension to handle the signal directive in the method.""" |
||||
|
||||
__version__ = '2024.10' |
||||
|
||||
import inspect |
||||
import ast |
||||
import sys |
||||
import types |
||||
import re |
||||
from typing import get_type_hints |
||||
from typing import get_overloads |
||||
from typing import TYPE_CHECKING, Any, ClassVar, NamedTuple, cast |
||||
|
||||
from sphinx.util.inspect import signature, stringify_signature |
||||
|
||||
from sphinx import addnodes |
||||
from docutils import nodes |
||||
from docutils.parsers.rst import directives |
||||
from sphinx.domains.python import PyMethod, PyObject |
||||
|
||||
if True or TYPE_CHECKING: |
||||
from collections.abc import Sequence |
||||
|
||||
from docutils.nodes import Node, system_message |
||||
|
||||
from sphinx.application import Sphinx |
||||
from sphinx.extension import Extension |
||||
from sphinx.util.typing import ExtensionMetadata, OptionSpec |
||||
from sphinx.writers.html5 import HTML5Translator |
||||
|
||||
import sphinx.ext.autosummary as seauto |
||||
import sphinx.ext.autosummary.generate as seautogenerate |
||||
|
||||
import TermTk as ttk |
||||
|
||||
import ast |
||||
import inspect |
||||
|
||||
# From |
||||
# https://stackoverflow.com/questions/3232024/introspection-to-get-decorator-names-on-a-method |
||||
|
||||
def get_decorators(cls): |
||||
target = cls |
||||
decorators = {} |
||||
|
||||
def visit_FunctionDef(node): |
||||
decorators[node.name] = [] |
||||
for n in node.decorator_list: |
||||
name = '' |
||||
if isinstance(n, ast.Call): |
||||
name = n.func.attr if isinstance(n.func, ast.Attribute) else n.func.id |
||||
else: |
||||
name = n.attr if isinstance(n, ast.Attribute) else n.id |
||||
|
||||
decorators[node.name].append(name) |
||||
|
||||
node_iter = ast.NodeVisitor() |
||||
node_iter.visit_FunctionDef = visit_FunctionDef |
||||
node_iter.visit(ast.parse(inspect.getsource(target))) |
||||
return decorators |
||||
|
||||
|
||||
_styleMatch = re.compile('^ *classStyle') |
||||
_colorMatch = re.compile('^#[0-9a-fA-F]{6}') |
||||
def _get_classStyleCode(obj) -> list[str]: |
||||
ret = [] |
||||
curlyBraket = 0 |
||||
def _processLine(line): |
||||
cbRet = 0 |
||||
for i,ch in enumerate(line): |
||||
if ch=='#': |
||||
if not _colorMatch.match(line[i:]): |
||||
continue |
||||
if ch == '{': |
||||
cbRet+=1 |
||||
elif ch == '}': |
||||
cbRet-=1 |
||||
if cbRet == 0: |
||||
return cbRet |
||||
return cbRet |
||||
|
||||
for line in inspect.getsource(obj).split('\n'): |
||||
# print(line) |
||||
# print(f"{_styleMatch.match(line)=}") |
||||
if curlyBraket == 0 and _styleMatch.match(line): |
||||
print(line) |
||||
ret.append(line) |
||||
curlyBraket += _processLine(line) |
||||
elif curlyBraket > 0: |
||||
print(line) |
||||
ret.append(line) |
||||
curlyBraket += _processLine(line) |
||||
if curlyBraket == 0: |
||||
return ret |
||||
return ret |
||||
|
||||
def setup(app: Sphinx) -> ExtensionMetadata: |
||||
'''Initialise the extension.''' |
||||
|
||||
modules = {} |
||||
modSorted = {} |
||||
modSub = {} |
||||
modSubSorted = {} |
||||
modStyles = {} |
||||
def _parseModules(_mod): |
||||
if _file:=getattr(_mod,'__file__',None): |
||||
if '__init__.py' in _file and '/TermTk/' in _file: |
||||
print(_file) |
||||
for _name, _obj in inspect.getmembers(_mod): |
||||
if inspect.isclass(_obj): |
||||
if _name not in modStyles: |
||||
modStyles[_name] = _get_classStyleCode(_obj) |
||||
if _name not in modules: |
||||
modules[_name] = _mod.__name__ |
||||
modules[_name] = _mod.__name__ if len(_mod.__name__)>len(modules[_name]) else modules[_name] |
||||
print(f" * {_name=} = {_obj}") |
||||
|
||||
for _module in sys.modules: |
||||
_parseModules(sys.modules[_module]) |
||||
|
||||
for x in modules.items(): |
||||
print(x) |
||||
a,b = x |
||||
if b not in modSorted: |
||||
modSorted[b] = [] |
||||
modSorted[b].append(a) |
||||
|
||||
for (a,b) in modSorted.items(): |
||||
print(a) |
||||
modSub[a] = '.'.join(a.split('.')[:-1]) |
||||
for x in b: |
||||
print (f" - {x}") |
||||
|
||||
for x in modSub.items(): |
||||
print(x) |
||||
|
||||
for x in modSub.items(): |
||||
print(x) |
||||
a,b = x |
||||
if b not in modSubSorted: |
||||
modSubSorted[b] = [] |
||||
modSubSorted[b].append(a) |
||||
|
||||
for (a,b) in modSubSorted.items(): |
||||
print(a) |
||||
for x in b: |
||||
print (f" - {x}") |
||||
|
||||
# print(modStyles) |
||||
|
||||
# raise Exception |
||||
|
||||
def generate_autosummary_content( |
||||
name, obj, parent, template, template_name, imported_members, |
||||
app, recursive, context, modname, qualname, |
||||
generate_autosummary_content_old = seautogenerate.generate_autosummary_content |
||||
) -> str: |
||||
print(f"-----------------> OVERRIDEEEEE!!! {type(context)}") |
||||
print(f"{name=}") |
||||
print(f"{obj=}") |
||||
print(f"{parent=}") |
||||
print(f"{template=}") |
||||
print(f"{template_name=}") |
||||
print(f"{imported_members=}") |
||||
print(f"{app=}") |
||||
print(f"{recursive=}") |
||||
print(f"{context=}") |
||||
print(f"{modname=}") |
||||
print(f"{qualname=}") |
||||
ttkSignals = [] |
||||
ttkSlots = [] |
||||
ttkMethods = [] |
||||
ttkInheritedMethods = [] |
||||
ttkSubClasses = modSorted.get(name,[]) |
||||
ttkSubModules = modSubSorted.get(name,[]) |
||||
|
||||
# ns['members'] = dir(obj) |
||||
# ns['inherited_members'] = set(dir(obj)) - set(obj.__dict__.keys()) |
||||
# ns['methods'], ns['all_methods'] = _get_members( |
||||
# doc, app, obj, {'method'}, include_public={'__init__'} |
||||
# ) |
||||
# ns['attributes'], ns['all_attributes'] = _get_members( |
||||
# doc, app, obj, {'attribute', 'property'} |
||||
# ) |
||||
|
||||
print(f"{obj=}") |
||||
# for member in inspect.getmembers(obj): |
||||
# _name = member[0] |
||||
# if _name.startswith('_'): continue |
||||
# _hint = get_type_hints(obj)[_name] |
||||
print(f"{obj=} - {get_type_hints(obj)=}") |
||||
for _name in (_th:=get_type_hints(obj)): |
||||
print(f"{_th=}") |
||||
if _name.startswith('_'): continue |
||||
if 'pyTTkSignal' in str(_th[_name]): |
||||
ttkSignals.append(_name) |
||||
else: |
||||
print(ttk.TTkString(f"element not typed: {_name} - { _th[_name]}",ttk.TTkColor.BG_CYAN)) |
||||
print(ttkSignals) |
||||
|
||||
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): |
||||
ttkMethods.append(_name) |
||||
for _decorator in _dec[_name]: |
||||
if "pyTTkSlot"in _decorator: |
||||
ttkSlots.append(_name) |
||||
break |
||||
|
||||
context |= { |
||||
'TTkStyle':modStyles.get(qualname,''), |
||||
'TTkSubClasses': ttkSubClasses, |
||||
'TTkSubModules': ttkSubModules, |
||||
'TTkMethods':ttkMethods, |
||||
'TTkSignals':ttkSignals, |
||||
'TTkSlots':ttkSlots} |
||||
|
||||
print('\n'.join([f" * {x}={context[x]}" for x in context])) |
||||
|
||||
return generate_autosummary_content_old( |
||||
name, obj, parent, template, template_name, imported_members, |
||||
app, recursive, context, modname, qualname) |
||||
|
||||
seautogenerate.generate_autosummary_content = generate_autosummary_content |
||||
|
||||
return seauto.setup(app) |
||||
@ -0,0 +1,58 @@
|
||||
"""Sphinx extension to render inherited overloads with autodoc.""" |
||||
|
||||
__version__ = '2023.4' |
||||
|
||||
from typing import get_overloads |
||||
from typing import TYPE_CHECKING, Any, ClassVar, NamedTuple, cast |
||||
|
||||
from sphinx.util.inspect import signature, stringify_signature |
||||
|
||||
from sphinx import addnodes |
||||
from docutils import nodes |
||||
from docutils.parsers.rst import directives |
||||
from sphinx.domains.python import PyMethod, PyObject |
||||
|
||||
if True or TYPE_CHECKING: |
||||
from collections.abc import Sequence |
||||
|
||||
from docutils.nodes import Node, system_message |
||||
|
||||
from sphinx.application import Sphinx |
||||
from sphinx.extension import Extension |
||||
from sphinx.util.typing import ExtensionMetadata, OptionSpec |
||||
from sphinx.writers.html5 import HTML5Translator |
||||
|
||||
|
||||
def test_process_signature(app, what, name, obj, options, sig, ret_ann): |
||||
'''Callback function to provide new signatures.''' |
||||
print(f"{app=}\n{what=}\n{name=}\n{obj=}\n{options=}\n{sig=}\n{ret_ann=}") |
||||
return '\n'.join(["a","b","c"]), "Pipppo Pippero" |
||||
|
||||
def test_process_docstring(app, what, name, obj, options, lines:list[str]): |
||||
'''Callback function to provide overloaded signatures.''' |
||||
print(f"{app=}\n{what=}\n{name=}\n{obj=}\n{options=}\n{lines=}") |
||||
for i,line in enumerate(lines): |
||||
lines[i] = line.replace("Table","PIPPO") |
||||
|
||||
class TermTkMethod(PyMethod): |
||||
option_spec: ClassVar[OptionSpec] = PyMethod.option_spec.copy() |
||||
option_spec.update({ |
||||
'signal': directives.flag, |
||||
}) |
||||
|
||||
def get_signature_prefix(self, sig: str) -> list[nodes.Node]: |
||||
prefix: list[nodes.Node] = super().get_signature_prefix(sig) |
||||
if 'signal' in self.options: |
||||
prefix.append(nodes.Text('signal')) |
||||
prefix.append(addnodes.desc_sig_space()) |
||||
return prefix |
||||
|
||||
def setup(app: Sphinx) -> ExtensionMetadata: |
||||
'''Initialise the extension.''' |
||||
# from: |
||||
# https://smobsc.readthedocs.io/en/stable/usage/extensions/autodoc.html |
||||
# https://github.com/ntessore/autodoc_inherit_overload/blob/main/sphinxcontrib/autodoc_inherit_overload.py |
||||
# app.connect('autodoc-process-signature', test_process_signature) |
||||
# app.connect('autodoc-process-docstring', test_process_docstring) |
||||
|
||||
app.add_directive_to_domain("py", "method", TermTkMethod, override=True) |
||||
@ -0,0 +1,5 @@
|
||||
{{ fullname | escape | underline}} |
||||
|
||||
.. currentmodule:: {{ module }} |
||||
|
||||
.. auto{{ objtype }}:: {{ objname }} |
||||
@ -0,0 +1,29 @@
|
||||
{{ fullname | escape | underline}} |
||||
|
||||
.. currentmodule:: {{ module }} |
||||
|
||||
.. autoclass:: {{ objname }} |
||||
|
||||
{% block methods %} |
||||
.. automethod:: __init__ |
||||
|
||||
{% if methods %} |
||||
.. rubric:: {{ _('Methods') }} |
||||
|
||||
.. autosummary:: |
||||
{% for item in methods %} |
||||
~{{ name }}.{{ item }} |
||||
{%- endfor %} |
||||
{% endif %} |
||||
{% endblock %} |
||||
|
||||
{% block attributes %} |
||||
{% if attributes %} |
||||
.. rubric:: {{ _('Attributes') }} |
||||
|
||||
.. autosummary:: |
||||
{% for item in attributes %} |
||||
~{{ name }}.{{ item }} |
||||
{%- endfor %} |
||||
{% endif %} |
||||
{% endblock %} |
||||
@ -0,0 +1,60 @@
|
||||
{{ fullname | escape | underline}} |
||||
|
||||
.. automodule:: {{ fullname }} |
||||
|
||||
{% block attributes %} |
||||
{%- if attributes %} |
||||
.. rubric:: {{ _('Module Attributes') }} |
||||
|
||||
.. autosummary:: |
||||
{% for item in attributes %} |
||||
{{ item }} |
||||
{%- endfor %} |
||||
{% endif %} |
||||
{%- endblock %} |
||||
|
||||
{%- block functions %} |
||||
{%- if functions %} |
||||
.. rubric:: {{ _('Functions') }} |
||||
|
||||
.. autosummary:: |
||||
{% for item in functions %} |
||||
{{ item }} |
||||
{%- endfor %} |
||||
{% endif %} |
||||
{%- endblock %} |
||||
|
||||
{%- block classes %} |
||||
{%- if classes %} |
||||
.. rubric:: {{ _('Classes') }} |
||||
|
||||
.. autosummary:: |
||||
{% for item in classes %} |
||||
{{ item }} |
||||
{%- endfor %} |
||||
{% endif %} |
||||
{%- endblock %} |
||||
|
||||
{%- block exceptions %} |
||||
{%- if exceptions %} |
||||
.. rubric:: {{ _('Exceptions') }} |
||||
|
||||
.. autosummary:: |
||||
{% for item in exceptions %} |
||||
{{ item }} |
||||
{%- endfor %} |
||||
{% endif %} |
||||
{%- endblock %} |
||||
|
||||
{%- block modules %} |
||||
{%- if modules %} |
||||
.. rubric:: Modules |
||||
|
||||
.. autosummary:: |
||||
:toctree: |
||||
:recursive: |
||||
{% for item in modules %} |
||||
{{ item }} |
||||
{%- endfor %} |
||||
{% endif %} |
||||
{%- endblock %} |
||||
@ -0,0 +1,60 @@
|
||||
{{ objname | escape | underline}} |
||||
|
||||
Pippo CUSTOM_CLASS_TEMPLATE.001 |
||||
|
||||
.. currentmodule:: {{ module }} |
||||
|
||||
.. autoclass:: {{ objname }} |
||||
|
||||
{% if TTkStyle %} |
||||
Style |
||||
----- |
||||
|
||||
.. code-block:: python |
||||
|
||||
{% for line in TTkStyle %} |
||||
{{ line }} |
||||
{%- endfor %} |
||||
{% endif %} |
||||
|
||||
{% if TTkSignals %} |
||||
:ref:`Signals <Signal and Slots>` |
||||
--------------------------------- |
||||
|
||||
.. autosummary:: |
||||
{% for item in TTkSignals %} |
||||
{{ item }} |
||||
{%- endfor %} |
||||
{% endif %} |
||||
|
||||
{% if TTkSlots %} |
||||
:ref:`Slots <Signal and Slots>` |
||||
------------------------------- |
||||
|
||||
.. autosummary:: |
||||
{% for item in TTkSlots %} |
||||
{{ item }} |
||||
{%- endfor %} |
||||
{% endif %} |
||||
|
||||
|
||||
{% if TTkSignals %} |
||||
|
||||
Members |
||||
------- |
||||
|
||||
{% for item in TTkSignals %} |
||||
.. autoattribute:: {{ item }} |
||||
{%- endfor %} |
||||
{% endif %} |
||||
|
||||
{% if TTkMethods %} |
||||
|
||||
Methods |
||||
------- |
||||
|
||||
{% for item in TTkMethods %} |
||||
.. automethod:: {{ item }} |
||||
{%- endfor %} |
||||
|
||||
{% endif %} |
||||
@ -0,0 +1,40 @@
|
||||
{{ fullname | escape | underline}} |
||||
|
||||
EugenioPOPOPPOPOPOPOPOPOPOP |
||||
|
||||
|
||||
.. currentmodule:: {{ module }} |
||||
|
||||
.. autoclass:: {{ objname }} |
||||
:members: |
||||
:show-inheritance: |
||||
:inherited-members: |
||||
|
||||
POPOPPOPOPOPOPOPOPOP |
||||
|
||||
.. {% block methods %} |
||||
.. automethod:: __init__ |
||||
|
||||
POPOPPOPOPOPOPOPOPOP 2 |
||||
|
||||
|
||||
{% if methods %} |
||||
.. rubric:: {{ _('Methods') }} |
||||
|
||||
.. autosummary:: |
||||
{% for item in methods %} |
||||
~{{ name }}.{{ item }} |
||||
{%- endfor %} |
||||
{% endif %} |
||||
{% endblock %} |
||||
|
||||
{% block attributes %} |
||||
{% if attributes %} |
||||
.. rubric:: {{ _('Attributes') }} |
||||
|
||||
.. autosummary:: |
||||
{% for item in attributes %} |
||||
~{{ name }}.{{ item }} |
||||
{%- endfor %} |
||||
{% endif %} |
||||
{% endblock %} |
||||
@ -0,0 +1,31 @@
|
||||
{{ fullname | escape | underline}} |
||||
|
||||
Pippo CUSTOM_MODULE_TEMPLATE.001 |
||||
|
||||
.. automodule:: {{ fullname }} |
||||
|
||||
{% if TTkSubClasses %} |
||||
.. rubric:: {{ _('Classes') }} |
||||
|
||||
.. autosummary:: |
||||
:caption: Classes: |
||||
:toctree: |
||||
:template: custom-class-template.01.rst |
||||
|
||||
{% for item in TTkSubClasses %} |
||||
{{ item }} |
||||
{%- endfor %} |
||||
{% endif %} |
||||
|
||||
{% if TTkSubModules %} |
||||
.. rubric:: Modules |
||||
|
||||
.. autosummary:: |
||||
:toctree: Modules: |
||||
:template: custom-module-template.01.rst |
||||
:recursive: |
||||
|
||||
{% for item in TTkSubModules %} |
||||
{{ item }} |
||||
{%- endfor %} |
||||
{% endif %} |
||||
@ -0,0 +1,66 @@
|
||||
{{ fullname | escape | underline}} |
||||
|
||||
.. automodule:: {{ fullname }} |
||||
|
||||
{% block attributes %} |
||||
{% if attributes %} |
||||
.. rubric:: Module Attributes |
||||
|
||||
.. autosummary:: |
||||
:toctree: |
||||
{% for item in attributes %} |
||||
{{ item }} |
||||
{%- endfor %} |
||||
{% endif %} |
||||
{% endblock %} |
||||
|
||||
{% block functions %} |
||||
{% if functions %} |
||||
.. rubric:: {{ _('Functions') }} |
||||
|
||||
.. autosummary:: |
||||
:toctree: |
||||
{% for item in functions %} |
||||
{{ item }} |
||||
{%- endfor %} |
||||
{% endif %} |
||||
{% endblock %} |
||||
|
||||
{% block classes %} |
||||
{% if classes %} |
||||
.. rubric:: {{ _('Classes') }} |
||||
|
||||
.. autosummary:: |
||||
:toctree: |
||||
:template: custom-class-template.rst |
||||
{% for item in classes %} |
||||
{{ item }} |
||||
{%- endfor %} |
||||
{% endif %} |
||||
{% endblock %} |
||||
|
||||
{% block exceptions %} |
||||
{% if exceptions %} |
||||
.. rubric:: {{ _('Exceptions') }} |
||||
|
||||
.. autosummary:: |
||||
:toctree: |
||||
{% for item in exceptions %} |
||||
{{ item }} |
||||
{%- endfor %} |
||||
{% endif %} |
||||
{% endblock %} |
||||
|
||||
{% block modules %} |
||||
{% if modules %} |
||||
.. rubric:: Modules |
||||
|
||||
.. autosummary:: |
||||
:toctree: |
||||
:template: custom-module-template.rst |
||||
:recursive: |
||||
{% for item in modules %} |
||||
{{ item }} |
||||
{%- endfor %} |
||||
{% endif %} |
||||
{% endblock %} |
||||
@ -0,0 +1,120 @@
|
||||
#!/usr/bin/env python3 |
||||
# vim:ts=4:sw=4:fdm=indent:cc=79: |
||||
|
||||
# MIT License |
||||
# |
||||
# Copyright (c) 2021 Eugenio Parodi <ceccopierangiolieugenio AT googlemail DOT com> |
||||
# |
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
# of this software and associated documentation files (the "Software"), to deal |
||||
# in the Software without restriction, including without limitation the rights |
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
# copies of the Software, and to permit persons to whom the Software is |
||||
# furnished to do so, subject to the following conditions: |
||||
# |
||||
# The above copyright notice and this permission notice shall be included in all |
||||
# copies or substantial portions of the Software. |
||||
# |
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
# SOFTWARE. |
||||
import os,sys |
||||
from typing import get_type_hints |
||||
import inspect |
||||
|
||||
sys.path.append(os.path.join(sys.path[0],'../..')) |
||||
import TermTk as ttk |
||||
|
||||
class A(): |
||||
__slots__ = ('a','b','c') |
||||
def __init__(self,a,b,c) -> None: |
||||
self.a=a |
||||
self.b=b |
||||
self.c=c |
||||
|
||||
def __str__(self) -> str: |
||||
return f"A: {id(self)} -> {self.a=}, {self.b=}, {self.c}" |
||||
self.c=c |
||||
|
||||
class B(): |
||||
__slots__ = ('a','b','c') |
||||
a:int |
||||
b:str |
||||
c:A |
||||
def __init__(self,a:int,b:str,c:A) -> None: |
||||
self.a=a |
||||
self.b=b |
||||
self.c=c |
||||
|
||||
def __str__(self) -> str: |
||||
return f"B: {id(self)} -> {self.a=}, {self.b=}, {self.c}" |
||||
|
||||
b1 = B(123,'Eugenio',A(1,2,3)) |
||||
b2 = B(456,'Parodi ',A(4,5,6)) |
||||
b3 = B(789,'Pappala',A(7,8,9)) |
||||
|
||||
tw = ttk.TTkTableWidget |
||||
tm = inspect.getmembers(ttk.TTkTableWidget) |
||||
th = get_type_hints(ttk.TTkTableWidget) |
||||
th = get_type_hints(ttk.TTkConstant) |
||||
|
||||
for i in th: |
||||
print(i) |
||||
|
||||
print(b1) |
||||
print(b2) |
||||
print(b3) |
||||
print(f"{B.a=}, {B.b=}, {B.c=}") |
||||
print(f"{A.a=}, {A.b=}, {A.c=}") |
||||
print(get_type_hints(B)) |
||||
print(get_type_hints(B)[B.c.__name__]) |
||||
print(get_type_hints(ttk.TTkTableWidget)[ttk.TTkTableWidget.cellChanged.__name__]) |
||||
print(get_type_hints(ttk.TTkTableWidget)) |
||||
print(inspect.getmembers(ttk.TTkTableWidget)) |
||||
|
||||
def template(func): |
||||
def wrapper(*args, **kwargs): |
||||
return func(*args, **kwargs) |
||||
return wrapper |
||||
|
||||
baz = template |
||||
che = template |
||||
|
||||
import ast |
||||
import inspect |
||||
|
||||
# From |
||||
# https://stackoverflow.com/questions/3232024/introspection-to-get-decorator-names-on-a-method |
||||
|
||||
class Foo(object): |
||||
@baz |
||||
@che |
||||
def bar(self): |
||||
pass |
||||
|
||||
def get_decorators(cls): |
||||
target = cls |
||||
decorators = {} |
||||
|
||||
def visit_FunctionDef(node): |
||||
decorators[node.name] = [] |
||||
for n in node.decorator_list: |
||||
name = '' |
||||
if isinstance(n, ast.Call): |
||||
name = n.func.attr if isinstance(n.func, ast.Attribute) else n.func.id |
||||
else: |
||||
name = n.attr if isinstance(n, ast.Attribute) else n.id |
||||
|
||||
decorators[node.name].append(name) |
||||
|
||||
node_iter = ast.NodeVisitor() |
||||
node_iter.visit_FunctionDef = visit_FunctionDef |
||||
node_iter.visit(ast.parse(inspect.getsource(target))) |
||||
return decorators |
||||
|
||||
print(inspect.getsource(Foo)) |
||||
print(get_decorators(Foo)) |
||||
Loading…
Reference in new issue