From 56b58f58dbede707ee574fc0cc682b0b3723a11c Mon Sep 17 00:00:00 2001 From: David Perl Date: Wed, 30 Apr 2025 16:56:37 +0200 Subject: [PATCH 1/2] feat: add plugin widget template --- copier.yml | 54 ++++++++++++++++++- {{_copier_conf.answers_file}}.jinja | 5 +- .../__init__.py | 0 ...idget_plugin.module }}.ui{% endif %}.jinja | 8 +++ .../{{ widget_plugin.module }}.py.jinja | 11 ++++ 5 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 {{project_name}}/bec_widgets/widgets/{% yield widget_plugin from widget_plugins %}{{ widget_plugin.module }}{% endyield %}/__init__.py create mode 100644 {{project_name}}/bec_widgets/widgets/{% yield widget_plugin from widget_plugins %}{{ widget_plugin.module }}{% endyield %}/{% if widget_plugin.use_ui %}{{ widget_plugin.module }}.ui{% endif %}.jinja create mode 100644 {{project_name}}/bec_widgets/widgets/{% yield widget_plugin from widget_plugins %}{{ widget_plugin.module }}{% endyield %}/{{ widget_plugin.module }}.py.jinja diff --git a/copier.yml b/copier.yml index 944f339..194cffb 100644 --- a/copier.yml +++ b/copier.yml @@ -1,5 +1,9 @@ _exclude: - ".gitea/" +# imports + +_jinja_extensions: +- bec_lib.utils.copier_jinja_filters.CopierFilters # predefined values # make sure these have 'when: false' so that the questions are not asked and the items are not saved in answers.yml @@ -21,7 +25,55 @@ project_name: type: str help: What is your project name? +widget_plugins_input: + # Defines the list of plugin widgets, following: + # - name: widget name in snake case + # use_ui: whether to generate a .ui file + type: yaml + multiline: true + default: > + - name: test_widget_1 + use_ui: true + - name: test_widget_2 + use_ui: false + - name: another_test_widget + use_ui: true + +# derived from questions: single point of configuration for plugin class names etc. + +widget_plugins: + type: yaml + multiline: true + default: > + {% for wp in widget_plugins_input %} + - module: {{ wp.name }} # Module name for the whole plugin + class: {{ wp.name | snake_to_pascal }} # Class name for the plugin widget + use_ui: {{ wp.use_ui }} # Whether to create a .ui file and import it + {% if wp.use_ui %} + ui_module: {{ wp.name }}_ui # Module name for the compiled python UI + ui_class: Ui_{{ wp.name | snake_to_pascal }} # Class name for the compiled python UI + {% endif %} + {% endfor %} + when: false + + # other configuration +ui_fileinfo: # would like to save this programatically when generated but don't see how + type: yaml + multiline: true + default: > + {% for wp in widget_plugins %} + {% if wp.use_ui %} + - ui_file: {{ project_name }}/bec_widgets/widgets/{{ wp.module }}/{{ wp.module }}.ui + out_file: {{ project_name }}/bec_widgets/widgets/{{ wp.module }}/{{ wp.ui_module }}.py + {% endif %} + {% endfor %} + when: false + _tasks: - - "git init --initial-branch=main" \ No newline at end of file + - "git init --initial-branch=main" + - > + {% for info in ui_fileinfo %}pyside6-uic {{ info.ui_file }} -o {{ info.out_file }}; + {% endfor %} + - "git add -A; git commit -a -m 'Init repo {{ project_name }} at template version {{ _commit }}'" diff --git a/{{_copier_conf.answers_file}}.jinja b/{{_copier_conf.answers_file}}.jinja index 9b0aa19..f872db1 100644 --- a/{{_copier_conf.answers_file}}.jinja +++ b/{{_copier_conf.answers_file}}.jinja @@ -1,2 +1,5 @@ -# Changes here will be overwritten by Copier! +# Do not edit this file! +# It is needed to track the repo template version, and editing may break things. +# This file will be overwritten by copier on template updates. + {{ _copier_answers|to_nice_yaml -}} \ No newline at end of file diff --git a/{{project_name}}/bec_widgets/widgets/{% yield widget_plugin from widget_plugins %}{{ widget_plugin.module }}{% endyield %}/__init__.py b/{{project_name}}/bec_widgets/widgets/{% yield widget_plugin from widget_plugins %}{{ widget_plugin.module }}{% endyield %}/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/{{project_name}}/bec_widgets/widgets/{% yield widget_plugin from widget_plugins %}{{ widget_plugin.module }}{% endyield %}/{% if widget_plugin.use_ui %}{{ widget_plugin.module }}.ui{% endif %}.jinja b/{{project_name}}/bec_widgets/widgets/{% yield widget_plugin from widget_plugins %}{{ widget_plugin.module }}{% endyield %}/{% if widget_plugin.use_ui %}{{ widget_plugin.module }}.ui{% endif %}.jinja new file mode 100644 index 0000000..cd55395 --- /dev/null +++ b/{{project_name}}/bec_widgets/widgets/{% yield widget_plugin from widget_plugins %}{{ widget_plugin.module }}{% endyield %}/{% if widget_plugin.use_ui %}{{ widget_plugin.module }}.ui{% endif %}.jinja @@ -0,0 +1,8 @@ + + + {{ widget_plugin.class | stash_filename }} + + + + + \ No newline at end of file diff --git a/{{project_name}}/bec_widgets/widgets/{% yield widget_plugin from widget_plugins %}{{ widget_plugin.module }}{% endyield %}/{{ widget_plugin.module }}.py.jinja b/{{project_name}}/bec_widgets/widgets/{% yield widget_plugin from widget_plugins %}{{ widget_plugin.module }}{% endyield %}/{{ widget_plugin.module }}.py.jinja new file mode 100644 index 0000000..d3cb4a0 --- /dev/null +++ b/{{project_name}}/bec_widgets/widgets/{% yield widget_plugin from widget_plugins %}{{ widget_plugin.module }}{% endyield %}/{{ widget_plugin.module }}.py.jinja @@ -0,0 +1,11 @@ +from qtpy.QtWidgets import QWidget + +from bec_widgets.utils.bec_widget import BECWidget + +{% if widget_plugin.use_ui %} +from {{ project_name }}.bec_widgets.widgets.{{ widget_plugin.module }}.{{ widget_plugin.ui_module }} import {{ widget_plugin.ui_class }} +{% endif %} + +class {{ widget_plugin.class }}(BECWidget, QWidget{% if widget_plugin.use_ui %}, {{ widget_plugin.ui_class }}{% endif %}): + def __init__(self, parent=None): + super().__init__(parent=parent) -- 2.49.0 From 45a03e9dec15dd988f229296f360b764634b6947 Mon Sep 17 00:00:00 2001 From: perl_d Date: Tue, 6 May 2025 15:27:43 +0200 Subject: [PATCH 2/2] fix: don't include default test widgets --- copier.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/copier.yml b/copier.yml index 194cffb..0917b9e 100644 --- a/copier.yml +++ b/copier.yml @@ -32,12 +32,6 @@ widget_plugins_input: type: yaml multiline: true default: > - - name: test_widget_1 - use_ui: true - - name: test_widget_2 - use_ui: false - - name: another_test_widget - use_ui: true # derived from questions: single point of configuration for plugin class names etc. -- 2.49.0