diff --git a/weldx_widgets/tests/test_gas.py b/weldx_widgets/tests/test_gas.py index fb220f1..e241a58 100644 --- a/weldx_widgets/tests/test_gas.py +++ b/weldx_widgets/tests/test_gas.py @@ -3,8 +3,6 @@ from weldx import WeldxFile from weldx_widgets import WidgetShieldingGas -from weldx_widgets.tests.util import voila_language -from weldx_widgets.widget_gas import WidgetSimpleGasSelection @pytest.mark.parametrize("write_file", (True, False)) @@ -28,10 +26,3 @@ def test_import_export(write_file): w2 = WidgetShieldingGas() w2.from_tree(tree) assert w2.to_tree() == tree - - -def test_lang(): - """Test translation.""" - with voila_language(lang="de"): - w = WidgetSimpleGasSelection() - assert "Sauerstoff" in w.gas_list diff --git a/weldx_widgets/widget_base.py b/weldx_widgets/widget_base.py index 200968b..7df366d 100644 --- a/weldx_widgets/widget_base.py +++ b/weldx_widgets/widget_base.py @@ -7,8 +7,27 @@ from weldx.asdf.util import get_schema_path +def metaclass_resolver(*classes): + """Merge multiple meta classes.""" + # Does something like this: + # https://coderedirect.com/questions/163000/multiple-inheritance-metaclass-conflict + metaclass = tuple(set(type(cls) for cls in classes)) -class WidgetBase: + def cls_name(classes): + return "_".join(mcls.__name__ for mcls in classes) + + metaclass = ( + metaclass[0] + if len(metaclass) == 1 + else type(cls_name(metaclass), metaclass, {}) + ) # class M_C + return metaclass(cls_name(classes), classes, {}) # class C + +class _merged_meta(type(abc.ABC)): # avoid metaclass conflict. + pass + + +class WidgetBase(abc.ABC, metaclass=_merged_meta): """Base class for weldx widgets.""" def copy(self): @@ -41,7 +60,7 @@ def _ipython_display_(self): margin = "" # "10px" -class WidgetMyHBox(HBox, WidgetBase): +class WidgetMyHBox(metaclass_resolver(HBox, WidgetBase)): """Wrap around a HBox sharing a common layout.""" def __init__(self, *args, **kwargs): @@ -56,7 +75,7 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) -class WidgetMyVBox(VBox, WidgetBase): +class WidgetMyVBox(metaclass_resolver(VBox, WidgetBase)): """Wrap around a VBox sharing a common layout.""" def __init__(self, *args, **kwargs): diff --git a/weldx_widgets/widget_evaluate.py b/weldx_widgets/widget_evaluate.py index 883429d..92265df 100644 --- a/weldx_widgets/widget_evaluate.py +++ b/weldx_widgets/widget_evaluate.py @@ -26,7 +26,7 @@ Trace, WeldxFile, ) -from weldx_widgets.widget_base import WidgetBase, WidgetSimpleOutput +from weldx_widgets.widget_base import WidgetBase, WidgetSimpleOutput, metaclass_resolver from weldx_widgets.widget_factory import make_title from weldx_widgets.widget_measurement import WidgetMeasurement, WidgetMeasurementChain @@ -85,7 +85,7 @@ def dims_as_coords(arr): data.coordinates = filtered -class WidgetEvaluateSinglePassWeld(Tab, WidgetBase): +class WidgetEvaluateSinglePassWeld(metaclass_resolver(Tab, WidgetBase)): """Aggregate info of passed file in several tabs.""" def __init__(self, file: WeldxFile): diff --git a/weldx_widgets/widget_gmaw.py b/weldx_widgets/widget_gmaw.py index b1e0c00..b18a486 100644 --- a/weldx_widgets/widget_gmaw.py +++ b/weldx_widgets/widget_gmaw.py @@ -38,7 +38,7 @@ def plot_gmaw(gmaw, t): fig, ax = plt.subplots(nrows=n, sharex="all", figsize=(_DEFAULT_FIGWIDTH, 2 * n)) for i, k in enumerate(pars): parplot(pars[k], t, k, ax[i]) - ax[-1].set_xlabel("time") + " / s" + ax[-1].set_xlabel("time / s") ax[0].set_title(title, loc="left") # ipympl_style(fig)