mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
feat(bec-designer): automatic plugin discovery
This commit is contained in:
@ -3,17 +3,17 @@ import sys
|
||||
import sysconfig
|
||||
from pathlib import Path
|
||||
|
||||
import bec_widgets
|
||||
|
||||
from PySide6.scripts.pyside_tool import (
|
||||
qt_tool_wrapper,
|
||||
ui_tool_binary,
|
||||
_extend_path_var,
|
||||
init_virtual_env,
|
||||
is_pyenv_python,
|
||||
is_virtual_env,
|
||||
_extend_path_var,
|
||||
qt_tool_wrapper,
|
||||
ui_tool_binary,
|
||||
)
|
||||
|
||||
import bec_widgets
|
||||
|
||||
|
||||
def patch_designer(): # pragma: no cover
|
||||
# init_virtual_env()
|
||||
@ -40,14 +40,37 @@ def patch_designer(): # pragma: no cover
|
||||
qt_tool_wrapper(ui_tool_binary("designer"), sys.argv[1:])
|
||||
|
||||
|
||||
def find_plugin_paths(base_path: Path):
|
||||
"""
|
||||
Recursively find all directories containing a .pyproject file.
|
||||
"""
|
||||
plugin_paths = []
|
||||
for path in base_path.rglob("*.pyproject"):
|
||||
plugin_paths.append(str(path.parent))
|
||||
return plugin_paths
|
||||
|
||||
|
||||
def set_plugin_environment_variable(plugin_paths):
|
||||
"""
|
||||
Set the PYSIDE_DESIGNER_PLUGINS environment variable with the given plugin paths.
|
||||
"""
|
||||
current_paths = os.environ.get("PYSIDE_DESIGNER_PLUGINS", "")
|
||||
if current_paths:
|
||||
current_paths = current_paths.split(os.pathsep)
|
||||
else:
|
||||
current_paths = []
|
||||
|
||||
current_paths.extend(plugin_paths)
|
||||
os.environ["PYSIDE_DESIGNER_PLUGINS"] = os.pathsep.join(current_paths)
|
||||
|
||||
|
||||
# Patch the designer function
|
||||
def main(): # pragma: no cover
|
||||
os.environ["PYSIDE_DESIGNER_PLUGINS"] = os.path.join(
|
||||
os.path.dirname(bec_widgets.__file__), "widgets/device_inputs/device_combobox"
|
||||
)
|
||||
# os.environ["PYSIDE_DESIGNER_PLUGINS"] = os.path.join(
|
||||
# os.path.dirname(bec_widgets.__file__), "widgets/motor_control/selection"
|
||||
# )
|
||||
|
||||
base_dir = Path(os.path.dirname(bec_widgets.__file__)).resolve()
|
||||
plugin_paths = find_plugin_paths(base_dir)
|
||||
set_plugin_environment_variable(plugin_paths)
|
||||
|
||||
patch_designer()
|
||||
|
||||
|
||||
|
@ -2,10 +2,8 @@
|
||||
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
from device_combobox import DeviceComboBox
|
||||
|
||||
from qtpy.QtGui import QIcon
|
||||
from qtpy.QtDesigner import QDesignerCustomWidgetInterface
|
||||
|
||||
from qtpy.QtGui import QIcon
|
||||
|
||||
DOM_XML = """
|
||||
<ui language='c++'>
|
||||
|
@ -2,7 +2,6 @@
|
||||
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
from device_combobox import DeviceComboBox
|
||||
|
||||
from PySide6.QtDesigner import QPyDesignerCustomWidgetCollection
|
||||
|
||||
from bec_widgets.widgets.device_inputs.device_combobox.device_combobox_plugin import (
|
||||
|
@ -2,9 +2,8 @@
|
||||
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
from device_line_edit import DeviceLineEdit
|
||||
from qtpy.QtGui import QIcon
|
||||
from qtpy.QtDesigner import QDesignerCustomWidgetInterface
|
||||
|
||||
from qtpy.QtGui import QIcon
|
||||
|
||||
DOM_XML = """
|
||||
<ui language='c++'>
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
from device_line_edit import DeviceLineEdit
|
||||
from device_line_edit_plugin import DeviceLineEditPlugin
|
||||
|
||||
from PySide6.QtDesigner import QPyDesignerCustomWidgetCollection
|
||||
|
||||
# Set PYSIDE_DESIGNER_PLUGINS to point to this directory and load the plugin
|
||||
|
Reference in New Issue
Block a user