def test_ui_tab_ui(interactive=False): filename = "test_ui_tab_ui" recording_filename = pjoin(DATA_DIR, filename + ".log.gz") expected_events_counts_filename = pjoin(DATA_DIR, filename + ".json") tab_ui = ui.TabUI(position=(50, 50), size=(300, 300), nb_tabs=3, draggable=True) tab_ui.tabs[0].title = "Tab 1" tab_ui.tabs[1].title = "Tab 2" tab_ui.tabs[2].title = "Tab 3" tab_ui.add_element(0, ui.Checkbox(["Option 1", "Option 2"]), (0.5, 0.5)) tab_ui.add_element(1, ui.LineSlider2D(), (0.0, 0.5)) tab_ui.add_element(2, ui.TextBlock2D(), (0.5, 0.5)) with npt.assert_raises(IndexError): tab_ui.add_element(3, ui.TextBlock2D(), (0.5, 0.5, 0.5)) with npt.assert_raises(IndexError): tab_ui.remove_element(3, ui.TextBlock2D()) with npt.assert_raises(IndexError): tab_ui.update_element(3, ui.TextBlock2D(), (0.5, 0.5, 0.5)) npt.assert_equal("Tab 1", tab_ui.tabs[0].title) npt.assert_equal("Tab 2", tab_ui.tabs[1].title) npt.assert_equal("Tab 3", tab_ui.tabs[2].title) npt.assert_equal(3, tab_ui.nb_tabs) collapses = itertools.count() changes = itertools.count() def collapse(tab_ui): if tab_ui.collapsed: next(collapses) def tab_change(tab_ui): next(changes) tab_ui.on_change = tab_change tab_ui.on_collapse = collapse event_counter = EventCounter() event_counter.monitor(tab_ui) current_size = (800, 800) show_manager = window.ShowManager(size=current_size, title="Tab UI Test") show_manager.scene.add(tab_ui) if interactive: show_manager.record_events_to_file(recording_filename) print(list(event_counter.events_counts.items())) event_counter.save(expected_events_counts_filename) else: show_manager.play_events_from_file(recording_filename) expected = EventCounter.load(expected_events_counts_filename) event_counter.check_counts(expected) npt.assert_equal(0, tab_ui.active_tab_idx) npt.assert_equal(11, next(changes)) npt.assert_equal(5, next(collapses))
def test_ui_checkbox(interactive=False): filename = "test_ui_checkbox" recording_filename = pjoin(DATA_DIR, filename + ".log.gz") expected_events_counts_filename = pjoin(DATA_DIR, filename + ".json") checkbox_test = ui.Checkbox(labels=["option 1", "option 2\nOption 2", "option 3", "option 4"], position=(10, 10)) old_positions = [] for option in checkbox_test.options: old_positions.append(option.position) old_positions = np.asarray(old_positions) checkbox_test.position = (100, 100) new_positions = [] for option in checkbox_test.options: new_positions.append(option.position) new_positions = np.asarray(new_positions) npt.assert_allclose(new_positions - old_positions, 90.0 * np.ones((4, 2))) # Collect the sequence of options that have been checked in this list. selected_options = [] def _on_change(checkbox): selected_options.append(list(checkbox.checked)) # Set up a callback when selection changes checkbox_test.on_change = _on_change event_counter = EventCounter() event_counter.monitor(checkbox_test) # Create a show manager and record/play events. show_manager = window.ShowManager(size=(600, 600), title="FURY Checkbox") show_manager.scene.add(checkbox_test) # Recorded events: # 1. Click on button of option 1. # 2. Click on button of option 2. # 3. Click on button of option 1. # 4. Click on text of option 3. # 5. Click on text of option 1. # 6. Click on button of option 4. # 7. Click on text of option 1. # 8. Click on text of option 2. # 9. Click on text of option 4. # 10. Click on button of option 3. show_manager.play_events_from_file(recording_filename) expected = EventCounter.load(expected_events_counts_filename) event_counter.check_counts(expected) # Check if the right options were selected. expected = [['option 1'], ['option 1', 'option 2\nOption 2'], ['option 2\nOption 2'], ['option 2\nOption 2', 'option 3'], ['option 2\nOption 2', 'option 3', 'option 1'], ['option 2\nOption 2', 'option 3', 'option 1', 'option 4'], ['option 2\nOption 2', 'option 3', 'option 4'], ['option 3', 'option 4'], ['option 3'], []] npt.assert_equal(len(selected_options), len(expected)) assert_arrays_equal(selected_options, expected) del show_manager if interactive: checkbox_test = ui.Checkbox(labels=["option 1", "option 2\nOption 2", "option 3", "option 4"], position=(100, 100)) showm = window.ShowManager(size=(600, 600)) showm.scene.add(checkbox_test) showm.start()
############################################################################### # CheckBoxes For Cylinder and Sphere for Tab Index 1 # ================================================== # # Now we prepare content for second tab. cylinder = actor.cylinder(centers=np.array([[0, 0, 0]]), directions=np.array([[1, 1, 0]]), colors=np.array([[0, 1, 1]]), radius=1.0) sphere = actor.sphere(centers=np.array([[5, 0, 0]]), colors=(1, 1, 0)) figure_dict = {'cylinder': cylinder, 'sphere': sphere} checkbox = ui.Checkbox(labels=["cylinder", "sphere"]) # Get difference between two lists. def sym_diff(l1, l2): return list(set(l1).symmetric_difference(set(l2))) # Set Visiblity of the figures def set_figure_visiblity(checkboxes): checked = checkboxes.checked_labels unchecked = sym_diff(list(figure_dict), checked) for visible in checked: figure_dict[visible].SetVisibility(True)
conn_matrix_path = os.path.join(DATA_DIR, '127_est_csd_unthresh_mat.npy') interactive = True # Instantiate scene scene = window.Scene() current_size = (1000, 1000) show_manager = window.ShowManager(scene=scene, size=current_size, title="Network Visualization") show_manager.initialize() panel = ui.Panel2D(size=(200, 200), position=(750, 20), color=(1, 1, 1), opacity=0.1, align="right") show_checkbox = ui.Checkbox(labels=["brain", "surfaces", "streamlines"]) show_checkbox.on_change = visible_callback panel.add_element(show_checkbox, coords=(0.1, 0.333)) scene.add(panel) win_callback.win_size = current_size win_callback.panel = panel # Load atlas rois atlas_img = nib.load(atlas) dims = atlas_img.shape zooms = atlas_img.get_header().get_zooms() atlas_img_data = atlas_img.get_data() # Collapse list of connected streamlines for visualization streamlines = nib.streamlines.load(streamlines_mni).streamlines
elif col == "Green": color_array[1] = 255 else: color_array[2] = 255 update_colors(color_array) ############################################################################### # We define a dictionary to store the actors with thier names as keys. # A checkbox is created with actor names as it's options. figure_dict = {'cube': cube, 'sphere': sphere, 'cone': cone, 'arrow': arrow} check_box = ui.Checkbox(list(figure_dict), list(figure_dict), padding=1, font_size=18, font_family='Arial', position=(400, 85)) ############################################################################### # A similar checkbox is created for changing colors. options = {'Blue': (0, 0, 1), 'Red': (1, 0, 0), 'Green': (0, 1, 0)} color_toggler = ui.Checkbox(list(options), checked_labels=['Blue'], padding=1, font_size=16, font_family='Arial', position=(600, 120)) check_box.on_change = set_figure_visiblity
def test_ui_checkbox_initial_state(recording=False): filename = "test_ui_checkbox_initial_state" recording_filename = pjoin(DATA_DIR, filename + ".log.gz") expected_events_counts_filename = pjoin(DATA_DIR, filename + ".json") checkbox_test = ui.Checkbox(labels=["option 1", "option 2\nOption 2", "option 3", "option 4"], position=(100, 100), checked_labels=["option 1", "option 4"]) # Collect the sequence of options that have been checked in this list. selected_options = [] def _on_change(checkbox): selected_options.append(list(checkbox.checked_labels)) # Set up a callback when selection changes checkbox_test.on_change = _on_change event_counter = EventCounter() event_counter.monitor(checkbox_test) # Create a show manager and record/play events. show_manager = window.ShowManager(size=(600, 600), title="FURY Checkbox") show_manager.scene.add(checkbox_test) if recording: show_manager.record_events_to_file(recording_filename) print(list(event_counter.events_counts.items())) event_counter.save(expected_events_counts_filename) print(selected_options) else: show_manager.play_events_from_file(recording_filename) expected = EventCounter.load(expected_events_counts_filename) event_counter.check_counts(expected) # Recorded events: # 1. Click on button of option 1. # 2. Click on button of option 2. # 3. Click on button of option 1. # 4. Click on text of option 3. # 5. Click on text of option 1. # 6. Click on button of option 4. # 7. Click on text of option 1. # 8. Click on text of option 2. # 9. Click on text of option 4. # 10. Click on button of option 3. # Check if the right options were selected. expected = [['option 4'], ['option 4', 'option 2\nOption 2'], ['option 4', 'option 2\nOption 2', 'option 1'], ['option 4', 'option 2\nOption 2', 'option 1', 'option 3'], ['option 4', 'option 2\nOption 2', 'option 3'], ['option 2\nOption 2', 'option 3'], ['option 2\nOption 2', 'option 3', 'option 1'], ['option 3', 'option 1'], ['option 3', 'option 1', 'option 4'], ['option 1', 'option 4']] npt.assert_equal(len(selected_options), len(expected)) assert_arrays_equal(selected_options, expected)