# Then we'll make two text labels and place them on the panel. # Note that we specifiy the position with integer numbers of pixels. text = ui.TextBlock2D(text='Click me') text2 = ui.TextBlock2D(text='Me too') panel.add_element(text, (50, 100)) panel.add_element(text2, (180, 100)) ############################################################################### # Then we'll create two buttons and add them to the panel. # # Note that here we specify the positions with floats. In this case, these are # percentages of the panel size. button_example = ui.Button2D( icon_fnames=[('square', read_viz_icons(fname='stop2.png'))]) icon_files = [] icon_files.append(('down', read_viz_icons(fname='circle-down.png'))) icon_files.append(('left', read_viz_icons(fname='circle-left.png'))) icon_files.append(('up', read_viz_icons(fname='circle-up.png'))) icon_files.append(('right', read_viz_icons(fname='circle-right.png'))) second_button_example = ui.Button2D(icon_fnames=icon_files) panel.add_element(button_example, (0.25, 0.33)) panel.add_element(second_button_example, (0.66, 0.33)) ############################################################################### # We can add a callback to each button to perform some action.
from fury import ui, window from fury.data import read_viz_icons, fetch_viz_icons textbox1 = ui.TextBox2D(50, 20, position=(330, 300), text="Element 1" + " " * 8) button_right = ui.Button2D(icon_fnames=[ ('square', read_viz_icons(fname='circle-right.png')) ], position=(295, 295), size=(30, 30)) textbox2 = ui.TextBox2D(50, 20, position=(330, 270), text="Element 2" + " " * 8) button_down = ui.Button2D(icon_fnames=[ ('square', read_viz_icons(fname='circle-down.png')) ], position=(295, 265), size=(30, 30)) content = ui.Panel2D(size=(170, 100), color=(1, 1, 1), align="left") content.center = (330, 330) textbox = ui.TextBox2D(50, 10, text="Hello World!!") content.add_element(textbox, (20, 50)) elements = [textbox1, button_right, button_down, content, textbox2, textbox]
def test_ui_button_panel(recording=False): filename = "test_ui_button_panel" recording_filename = pjoin(DATA_DIR, filename + ".log.gz") expected_events_counts_filename = pjoin(DATA_DIR, filename + ".json") # Rectangle rectangle_test = ui.Rectangle2D(size=(10, 10)) another_rectangle_test = ui.Rectangle2D(size=(1, 1)) # Button fetch_viz_icons() icon_files = [] icon_files.append(('stop', read_viz_icons(fname='stop2.png'))) icon_files.append(('play', read_viz_icons(fname='play3.png'))) button_test = ui.Button2D(icon_fnames=icon_files) button_test.center = (20, 20) def make_invisible(i_ren, _obj, button): # i_ren: CustomInteractorStyle # obj: vtkActor picked # button: Button2D button.set_visibility(False) i_ren.force_render() i_ren.event.abort() def modify_button_callback(i_ren, _obj, button): # i_ren: CustomInteractorStyle # obj: vtkActor picked # button: Button2D button.next_icon() i_ren.force_render() button_test.on_right_mouse_button_pressed = make_invisible button_test.on_left_mouse_button_pressed = modify_button_callback button_test.scale((2, 2)) button_color = button_test.color button_test.color = button_color # TextBlock text_block_test = ui.TextBlock2D() text_block_test.message = 'TextBlock' text_block_test.color = (0, 0, 0) # Panel panel = ui.Panel2D(size=(300, 150), position=(290, 15), color=(1, 1, 1), align="right") panel.add_element(rectangle_test, (290, 135)) panel.add_element(button_test, (0.1, 0.1)) panel.add_element(text_block_test, (0.7, 0.7)) npt.assert_raises(ValueError, panel.add_element, another_rectangle_test, (10., 0.5)) npt.assert_raises(ValueError, panel.add_element, another_rectangle_test, (-0.5, 0.5)) # Assign the counter callback to every possible event. event_counter = EventCounter() event_counter.monitor(button_test) event_counter.monitor(panel.background) current_size = (600, 600) show_manager = window.ShowManager(size=current_size, title="FURY Button") show_manager.scene.add(panel) if recording: 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)
import numpy as np from fury import window, actor, utils, io, ui import itertools from fury.data import read_viz_textures, fetch_viz_textures, read_viz_icons ############################################################################## # Create a scene to start. scene = window.Scene() # Create a panel and the start/pause buttons panel = ui.Panel2D(size=(300, 100), color=(1, 1, 1), align="right") panel.center = (400, 50) pause_button = ui.Button2D(icon_fnames=[("square", read_viz_icons(fname="pause2.png"))]) start_button = ui.Button2D(icon_fnames=[("square", read_viz_icons(fname="play3.png"))]) # Add the buttons on the panel panel.add_element(pause_button, (0.25, 0.33)) panel.add_element(start_button, (0.66, 0.33)) ############################################################################## # Define information relevant for each planet actor including its # texture name, relative position, and scale. planets_data = [{ 'filename': '8k_mercury.jpg', 'position': 7,
############################################################################### # Then we'll make two text labels and place them on the panel. # Note that we specifiy the position with integer numbers of pixels. text = ui.TextBlock2D(text="Click me") text2 = ui.TextBlock2D(text="Me too") panel.add_element(text, (50, 100)) panel.add_element(text2, (180, 100)) ############################################################################### # Then we'll create two buttons and add them to the panel. # # Note that here we specify the positions with floats. In this case, these are # percentages of the panel size. button_example = ui.Button2D(icon_fnames=[("square", read_viz_icons(fname="stop2.png"))]) icon_files = [] icon_files.append(("down", read_viz_icons(fname="circle-down.png"))) icon_files.append(("left", read_viz_icons(fname="circle-left.png"))) icon_files.append(("up", read_viz_icons(fname="circle-up.png"))) icon_files.append(("right", read_viz_icons(fname="circle-right.png"))) second_button_example = ui.Button2D(icon_fnames=icon_files) panel.add_element(button_example, (0.25, 0.33)) panel.add_element(second_button_example, (0.66, 0.33)) ############################################################################### # We can add a callback to each button to perform some action.
from fury import ui, window from fury.data import read_viz_icons, fetch_viz_icons textbox = ui.TextBox2D(50, 20, position=(300, 400), text=" "*8 + "23") button_up = ui.Button2D(icon_fnames=[('square', read_viz_icons(fname='circle-up.png'))], position=(365,408), size=(15,15)) button_down = ui.Button2D(icon_fnames=[('square', read_viz_icons(fname='circle-down.png'))], position=(365,394), size=(15,15)) current_size = (800, 800) show_manager = window.ShowManager(size=current_size, title="Spinner UI Example") show_manager.scene.add(textbox) show_manager.scene.add(button_up) show_manager.scene.add(button_down) show_manager.start()
import os from fury import ui, window, actor import nibabel as nib from dipy.data import fetch_bundles_2_subjects panel = ui.Panel2D(size=(600, 400), color=(1, 1, 1), align="right") panel.center = (500, 400) icon_fnames = [('square', 'model_predictions.png'), ('square2', 'wmparc.png')] button = ui.Button2D(icon_fnames, size=(500, 300)) panel.add_element(button, coords=(0., 0.)) scene = window.Scene() showm = window.ShowManager(scene, size=(1000, 1000)) showm.initialize() scene.add(actor.axes()) scene.add(panel) def change_icon_callback(i_ren, _obj, _button): button.next_icon() showm.render() button.on_left_mouse_button_clicked = change_icon_callback
from fury.data import read_viz_icons from fury import ui, window button_example = ui.Button2D(icon_fnames=[ ('Up', read_viz_icons(fname='circle-up.png')) ], position=(50, 50), size=(30, 30)) current_size = (100, 100) show_manager = window.ShowManager(size=current_size, title="Inverted Image BUG") show_manager.scene.add(button_example) show_manager.start()