Exemplo n.º 1
0
def request_new_load_solution(study, kind="livemodal", **traits):
    """ Build a new instance of a data model invoking its UI editor.

    The provided study may contain data necessary to create the model.

    Parameters
    ----------
    study : Study
        Study that this load solution configuration tool will be contributed
        to.

    kind : None or str
        Kind of the dialog. Set to None to make it non-blocking. Useful for
        testing purposes.

    traits : dict
        Attributes of the created object. Used to override the defaults.
    """
    if not study.product_set:
        prod_chooser = ProductChooser(datasource=study.datasource)
        ui = prod_chooser.edit_traits(kind=kind)
        if kind is None:
            return ui
        elif ui.result:
            study.product = prod_chooser.selected_product
        else:
            return

    model = SolutionWithProduct(name="New load", solution_type="Load",
                                product=study.product, **traits)
    view = SolutionWithProductView(model=model, datasource=study.datasource)
    return _show_view_and_return_model(view, kind)
Exemplo n.º 2
0
def request_binding_model_ds(datasource, kind="livemodal", **traits):
    """ Build a new instance of a binding_model invoking its UI editor.

    The provided study may contain data necessary to create the model.

    Parameters
    ----------
    datasource : Instance(SimpleDataSource)
        User datasource targeted to be contributed to.

    kind : None or str
        Kind of the dialog. Set to None to make it non-blocking. Useful for
        testing purposes.

    traits : dict
        Attributes of the created object. Used to override the defaults.
    """
    target_product = traits.pop("target_product", None)
    if target_product is None:
        prod_chooser = ProductChooser(datasource=datasource)
        ui = prod_chooser.edit_traits(kind=kind)
        if kind is None:
            return ui
        elif ui.result:
            target_product = prod_chooser.selected_product
        else:
            return

    traits["target_product"] = target_product.name
    # Reminder: binding model describes Cation component as its first component
    component_names = ["Cation"] + target_product.product_component_names
    view = BindingModelBuilder(_target_component_names=component_names,
                               **traits)
    return _show_view_and_return_model(view, kind)
Exemplo n.º 3
0
def request_binding_model(study, kind="livemodal", **traits):
    """ Build a new instance of a binding_model invoking its UI editor.

    The provided study may contain data necessary to create the model.

    Parameters
    ----------
    study : Study
        Study that this binding_model configuration tool will be contributed
        to.

    kind : None or str
        Kind of the dialog. Set to None to make it non-blocking. Useful for
        testing purposes.

    traits : dict
        Attributes of the created object. Used to override the defaults.
    """
    if not study.product_set:
        prod_chooser = ProductChooser(datasource=study.datasource)
        ui = prod_chooser.edit_traits(kind=kind)
        if kind is None:
            return ui
        elif ui.result:
            study.product = prod_chooser.selected_product
        else:
            return

    traits["target_product"] = study.product.name
    # Reminder: binding model describes Cation component as its first component
    component_names = study.product.product_component_names
    view = BindingModelBuilder(_target_component_names=component_names,
                               **traits)
    return _show_view_and_return_model(view, kind)
class TestProductChooser(TestCase):
    def setUp(self):
        self.ds = SimpleDataSource()
        self.prod_chooser = ProductChooser(datasource=self.ds)

    def test_create_ui(self):
        ui = self.prod_chooser.edit_traits()
        ui.dispose()

    def test_selection(self):
        target_prod = self.ds.get_object_names_by_type("products")[0]
        self.prod_chooser.selected_product_name = target_prod

        expected = self.ds.get_object_of_type("products", target_prod)
        assert_has_traits_almost_equal(self.prod_chooser.selected_product,
                                       expected)
        assert (self.prod_chooser.selected_product is not expected)
 def setUp(self):
     self.ds = SimpleDataSource()
     self.prod_chooser = ProductChooser(datasource=self.ds)