Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
marscher committed Dec 4, 2023
1 parent e70ef7c commit 38be7a4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
9 changes: 0 additions & 9 deletions weldx_widgets/tests/test_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
25 changes: 22 additions & 3 deletions weldx_widgets/widget_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions weldx_widgets/widget_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion weldx_widgets/widget_gmaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 38be7a4

Please sign in to comment.