feat: add plugin widget template

This commit is contained in:
2025-04-30 16:56:37 +02:00
committed by perl_d
parent ea95f2d970
commit 56b58f58db
5 changed files with 76 additions and 2 deletions

View File

@ -1,5 +1,9 @@
_exclude: _exclude:
- ".gitea/" - ".gitea/"
# imports
_jinja_extensions:
- bec_lib.utils.copier_jinja_filters.CopierFilters
# predefined values # predefined values
# make sure these have 'when: false' so that the questions are not asked and the items are not saved in answers.yml # 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 type: str
help: What is your project name? 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 # 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: _tasks:
- "git init --initial-branch=main" - "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 }}'"

View File

@ -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 -}} {{ _copier_answers|to_nice_yaml -}}

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>{{ widget_plugin.class | stash_filename }}</class>
<widget class="QWidget" name="MainWindow">
</widget>
<resources />
<connections />
</ui>

View File

@ -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)