diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-08-08 15:07:12 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-08-11 09:12:56 +0200 |
| commit | c4a266e38fe5bdce707ad6b123fa88bb4f10dff3 (patch) | |
| tree | a7cc96a47dec82f5b11093ad9837cc221b8c6c8e /tools/snippets_translate/override.py | |
| parent | 89e5d35c0f002fcb1aac3b1205402ce306074255 (diff) | |
snippets_translate: Add a way of using snippets from Python
Split a helper off the snippet extraction function taking the comment
pattern and let it return a dict by id to make it possible to replace
snippets by id.
Prototypically use it for the modelview tutorial.
Fixes: PYSIDE-1984
Task-number: PYSIDE-1952
Pick-to: 6.3 6.2
Change-Id: I05dbc3e36825761fe2968d6507880cd6f588682d
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'tools/snippets_translate/override.py')
| -rw-r--r-- | tools/snippets_translate/override.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tools/snippets_translate/override.py b/tools/snippets_translate/override.py new file mode 100644 index 000000000..c9aa6d498 --- /dev/null +++ b/tools/snippets_translate/override.py @@ -0,0 +1,56 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +from pathlib import Path + +ROOT_PATH = Path(__file__).parents[2] +EXAMPLES_PATH = ROOT_PATH / "examples" + + +_PYTHON_EXAMPLE_SNIPPET_MAPPING = { + ("qtbase/examples/widgets/tutorials/modelview/1_readonly/mymodel.cpp", + "Quoting ModelView Tutorial"): + (EXAMPLES_PATH / "widgets" / "tutorials" / "modelview" / "1_readonly.py", "1"), + ("qtbase/examples/widgets/tutorials/modelview/2_formatting/mymodel.cpp", + "Quoting ModelView Tutorial"): + (EXAMPLES_PATH / "widgets" / "tutorials" / "modelview" / "2_formatting.py", "1"), + ("qtbase/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp", + "quoting mymodel_QVariant"): + (EXAMPLES_PATH / "widgets" / "tutorials" / "modelview" / "3_changingmodel.py", "2"), + ("qtbase/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp", + "quoting mymodel_a"): + (EXAMPLES_PATH / "widgets" / "tutorials" / "modelview" / "3_changingmodel.py", "1"), + ("qtbase/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp", + "quoting mymodel_b"): + (EXAMPLES_PATH / "widgets" / "tutorials" / "modelview" / "3_changingmodel.py", "3"), + ("qtbase/examples/widgets/tutorials/modelview/4_headers/mymodel.cpp", + "quoting mymodel_c"): + (EXAMPLES_PATH / "widgets" / "tutorials" / "modelview" / "4_headers.py", "1"), + ("qtbase/examples/widgets/tutorials/modelview/5_edit/mymodel.cpp", + "quoting mymodel_e"): + (EXAMPLES_PATH / "widgets" / "tutorials" / "modelview" / "5_edit.py", "1"), + ("qtbase/examples/widgets/tutorials/modelview/5_edit/mymodel.cpp", + "quoting mymodel_f"): + (EXAMPLES_PATH / "widgets" / "tutorials" / "modelview" / "5_edit.py", "2"), + ("qtbase/examples/widgets/tutorials/modelview/6_treeview/mainwindow.cpp", + "Quoting ModelView Tutorial"): + (EXAMPLES_PATH / "widgets" / "tutorials" / "modelview" / "6_treeview.py", "1"), + ("qtbase/examples/widgets/tutorials/modelview/7_selections/mainwindow.cpp", + "quoting modelview_a"): + (EXAMPLES_PATH / "widgets" / "tutorials" / "modelview" / "7_selections.py", "1"), + ("qtbase/examples/widgets/tutorials/modelview/7_selections/mainwindow.cpp", + "quoting modelview_b"): + (EXAMPLES_PATH / "widgets" / "tutorials" / "modelview" / "7_selections.py", "2") +} + + +_python_example_snippet_mapping = {} + + +def python_example_snippet_mapping(): + global _python_example_snippet_mapping + if not _python_example_snippet_mapping: + result = _PYTHON_EXAMPLE_SNIPPET_MAPPING + _python_example_snippet_mapping = result + + return _python_example_snippet_mapping |
