bokeh.events.MenuItemClick

Here are the examples of the python api bokeh.events.MenuItemClick taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

5 Examples 7

3 Source : test_button.py
with BSD 3-Clause "New" or "Revised" License
from holoviz

def test_menu_button(document, comm):
    menu_items = [('Option A', 'a'), ('Option B', 'b'), ('Option C', 'c'), None, ('Help', 'help')]
    menu_button = MenuButton(items=menu_items)

    widget = menu_button.get_root(document, comm=comm)

    events = []
    def callback(event):
        events.append(event.new)

    menu_button.param.watch(callback, 'clicked')

    menu_button._process_event(MenuItemClick(widget, 'b'))

    assert events == ['b']


def test_button_jscallback_clicks(document, comm):

3 Source : local_helper.py
with MIT License
from phurwicz

def action_commit_selection(dataset, subset="train"):
    commit_event = MenuItemClick(dataset.data_committer, item=subset)
    dataset.data_committer._trigger_event(commit_event)
    return dataset


def action_deduplicate(dataset):

0 Source : test_functionality.py
with MIT License
from phurwicz

    def test_comprehensive(example_raw_df, example_labeled_df):
        """
        Some methods are the same across child classes.

        Test as many of those as possible here.
        """

        def subroutine(df_dict, feature_type):
            finder = get_explorer_class("finder", feature_type)(df_dict)
            annotator = get_explorer_class("annotator", feature_type)(df_dict)

            finder.plot()
            annotator.plot()

            finder.dfs["raw"] = example_raw_df.copy()
            finder._update_sources()

            finder.link_selection("raw", annotator, "raw")
            finder.link_selection_options(annotator)
            finder.link_xy_range(annotator)

            # change axes and check source and glyph
            # the source should not change, just glyph axes
            embed_cols = annotator.find_embedding_fields()
            prev_source_data = annotator.sources["raw"].data.copy()
            inspect_renderer = annotator.figure.renderers[0]

            for _axis, _from_idx, _to_idx in [
                ("x", 0, 1),
                ("y", 1, 0),
            ]:
                _widget = getattr(annotator, f"dropdown_{_axis}_axis")
                _click_event = MenuItemClick(_widget, item=embed_cols[_to_idx])
                assert getattr(inspect_renderer.glyph, _axis) == embed_cols[_from_idx]
                _widget._trigger_event(_click_event)
                assert getattr(inspect_renderer.glyph, _axis) == embed_cols[_to_idx]
                assert annotator.sources["raw"].data is not prev_source_data
                assert annotator.sources["raw"].data == prev_source_data

        df_dict = {
            "raw": example_raw_df.copy(),
            "train": example_labeled_df.copy(),
            "dev": example_labeled_df.copy(),
            "test": example_labeled_df.copy(),
        }

        # test four subset combinations of df_dicts
        for _key in ["test", "dev", "train", "raw"]:
            # test all main features
            for _feature in MAIN_FEATURES:
                subroutine(df_dict, _feature)
            df_dict.pop(_key)


@pytest.mark.core

0 Source : test_functionality.py
with MIT License
from phurwicz

    def test_lf_labeling(example_raw_df, example_labeled_df):
        """
        No difference across text / image / audio.
        Just using text should suffice.
        """
        explorer = get_explorer_class("snorkel", "text")(
            {
                "raw": example_raw_df,
                "labeled": example_labeled_df,
            }
        )
        explorer.plot()
        initial_palette_size = len(explorer.palette)

        # create some dummy rules for predictable outcome
        lf_collection = subroutine_rules_from_text_df(explorer.dfs["raw"])
        narrow_rule_a = lf_collection["narrow_a"]
        narrow_rule_b = lf_collection["narrow_b"]
        broad_rule_a = lf_collection["broad_a"]
        broad_rule_b = lf_collection["broad_b"]
        # add a rule, check menu
        explorer.plot_lf(narrow_rule_b)
        assert explorer.lf_apply_trigger.menu == ["narrow_rule_b"]
        assert explorer.lf_filter_trigger.menu == ["narrow_rule_b"]

        # subscribe to a LF list, refresh, and check again
        lf_list = [narrow_rule_a, broad_rule_a]
        explorer.subscribed_lf_list = lf_list
        refresh_event = ButtonClick(explorer.lf_list_refresher)
        explorer.lf_list_refresher._trigger_event(refresh_event)
        lf_names_so_far = ["narrow_rule_a", "broad_rule_a"]
        assert explorer.lf_apply_trigger.menu == lf_names_so_far
        assert explorer.lf_filter_trigger.menu == lf_names_so_far

        # add an existing rule: menu, glyph, and view should stay the same
        old_narrow_a_lf = explorer.lf_data["narrow_rule_a"]["lf"]
        old_narrow_a_glyph_c = explorer.lf_data["narrow_rule_a"]["glyphs"]["C"]
        old_narrow_a_view_c = old_narrow_a_glyph_c.view
        explorer.plot_lf(narrow_rule_a)
        assert explorer.lf_apply_trigger.menu == lf_names_so_far
        assert explorer.lf_filter_trigger.menu == lf_names_so_far
        narrow_a_data_dict = explorer.lf_data["narrow_rule_a"]
        assert narrow_a_data_dict["lf"] is old_narrow_a_lf
        assert narrow_a_data_dict["glyphs"]["C"] is old_narrow_a_glyph_c
        assert narrow_a_data_dict["glyphs"]["C"].view is old_narrow_a_view_c

        # overwrite a rule: the dict reference in lf_data should stay the same
        # menu items and glyph references should stay the same
        # the view references of the glyphs should have changed
        narrow_rule_a = lf_collection["narrow_a_clone"]
        explorer.plot_lf(narrow_rule_a)
        assert explorer.lf_apply_trigger.menu == lf_names_so_far
        assert explorer.lf_filter_trigger.menu == lf_names_so_far
        assert narrow_a_data_dict["lf"] is not old_narrow_a_lf
        assert narrow_a_data_dict["glyphs"]["C"] is old_narrow_a_glyph_c
        assert narrow_a_data_dict["glyphs"]["C"].view is not old_narrow_a_view_c

        # empty click: nothing selected
        filter_event = MenuItemClick(explorer.lf_filter_trigger, item="broad_rule_a")
        apply_event = MenuItemClick(explorer.lf_apply_trigger, item="narrow_rule_a")
        explorer.lf_filter_trigger._trigger_event(filter_event)
        explorer.lf_apply_trigger._trigger_event(apply_event)

        # emulate selection by user
        # slice to first ten, then assign A to first six
        all_raw_idx = list(range(explorer.dfs["raw"].shape[0]))
        # note: bokeh's SelectionGeometry seems to not actually make a selection
        # note: the indices assignment has to happen before SelectionGeometry trigger
        # - this is for treating indices assignment as a manual select
        explorer.sources["raw"].selected.indices = all_raw_idx[:]
        select_event = almost_global_select(explorer.figure)
        explorer.figure._trigger_event(select_event)
        assert explorer.sources["raw"].selected.indices == all_raw_idx

        # actually triggering LFs on a valid selection
        explorer.lf_filter_trigger._trigger_event(filter_event)
        explorer.lf_apply_trigger._trigger_event(apply_event)

        first_six_labels = explorer.dfs["raw"]["label"].iloc[:6].tolist()
        assert first_six_labels == ["A"] * 6

        # add more rules, check menu again
        lf_list.append(narrow_rule_b)
        lf_list.append(broad_rule_b)
        explorer.lf_list_refresher._trigger_event(refresh_event)

        lf_names_so_far = [
            "narrow_rule_a",
            "broad_rule_a",
            "narrow_rule_b",
            "broad_rule_b",
        ]
        assert explorer.lf_apply_trigger.menu == lf_names_so_far
        assert explorer.lf_filter_trigger.menu == lf_names_so_far

        # note: bokeh's SelectionGeometry seems to not actually make a selection
        # note: the indices assignment has to happen before SelectionGeometry trigger
        # - this is for treating indices assignment as a manual select
        explorer.sources["raw"].selected.indices = all_raw_idx[:]
        explorer.figure._trigger_event(select_event)
        # slice to first ten, then assign B to first six
        _event = MenuItemClick(explorer.lf_filter_trigger, item="broad_rule_b")
        explorer.lf_filter_trigger._trigger_event(_event)
        _event = MenuItemClick(explorer.lf_apply_trigger, item="narrow_rule_b")
        explorer.lf_apply_trigger._trigger_event(_event)

        first_six_labels = explorer.dfs["raw"]["label"].iloc[:6].tolist()
        assert first_six_labels == ["B"] * 6

        # use two pops to check against misremoval of renderers
        lf_list.pop()
        lf_list.pop()
        explorer.lf_list_refresher._trigger_event(refresh_event)
        assert len(explorer.palette) == initial_palette_size - len(lf_list)

0 Source : test_dataset.py
with MIT License
from phurwicz

    def test_export_import(example_text_dataset):
        dataset = example_text_dataset.copy()

        df = dataset.to_pandas()
        dataset = SupervisableTextDataset.from_pandas(df)

        # trigger callback through button click (UI behavior)
        for _item, _ext in [
            ("Excel", ".xlsx"),
            ("CSV", ".csv"),
            ("JSON", ".json"),
            ("pickle", ".pkl"),
        ]:
            _f_old = [_path for _path in os.listdir(".") if _path.endswith(_ext)]
            _event = MenuItemClick(dataset.file_exporter, item=_item)
            dataset.file_exporter._trigger_event(_event)
            _f_new = [_path for _path in os.listdir(".") if _path.endswith(_ext)]
            assert len(_f_new) == len(_f_old) + 1

    @staticmethod