| 1 | # Copyright (C) 2025 AIDC-AI |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | # See the License for the specific language governing permissions and |
| 11 | # limitations under the License. |
| 12 | |
| 13 | """ |
| 14 | Pipeline UI Base & Registry |
| 15 | |
| 16 | Defines the PipelineUI protocol and the registration mechanism. |
| 17 | """ |
| 18 | |
| 19 | from typing import Dict, Any, List, Type |
| 20 | |
| 21 | class PipelineUI: |
| 22 | """ |
| 23 | Base class for Pipeline UI plugins. |
| 24 | |
| 25 | Each pipeline should implement a subclass to define its own full-page UI. |
| 26 | """ |
| 27 | name: str = "base" |
| 28 | display_name: str = "Base Pipeline" |
| 29 | icon: str = "🔌" |
| 30 | description: str = "" |
| 31 | |
| 32 | def render(self, pixelle_video: Any): |
| 33 | """ |
| 34 | Render the full page content for this pipeline (below settings). |
| 35 | |
| 36 | Args: |
| 37 | pixelle_video: The initialized PixelleVideoCore instance. |
| 38 | """ |
| 39 | raise NotImplementedError |
| 40 | |
| 41 | |
| 42 | # ==================== Registry ==================== |
| 43 | |
| 44 | _pipeline_uis: Dict[str, PipelineUI] = {} |
| 45 | |
| 46 | def register_pipeline_ui(ui_class: Type[PipelineUI]): |
| 47 | """Register a pipeline UI class""" |
| 48 | instance = ui_class() |
| 49 | _pipeline_uis[instance.name] = instance |
| 50 | |
| 51 | def get_pipeline_ui(name: str) -> PipelineUI: |
| 52 | """Get a pipeline UI instance by name""" |
| 53 | return _pipeline_uis.get(name) |
| 54 | |
| 55 | def get_all_pipeline_uis() -> List[PipelineUI]: |
| 56 | """Get all registered pipeline UI instances""" |
| 57 | return list(_pipeline_uis.values()) |
| 58 |