예제 #1
0
def test_ui_combobox_2d(interactive=False):
    filename = "test_ui_combobox_2d"
    recording_filename = pjoin(DATA_DIR, filename + ".log.gz")
    expected_events_counts_filename = pjoin(DATA_DIR, filename + ".json")

    values = ["An Item" + str(i) for i in range(0, 5)]
    new_values = ["An Item5", "An Item6"]

    combobox = ui.ComboBox2D(
        items=values, position=(400, 400), size=(300, 200))

    # Assign the counter callback to every possible event.
    event_counter = EventCounter()
    event_counter.monitor(combobox)

    current_size = (800, 800)
    show_manager = window.ShowManager(
        size=current_size, title="ComboBox UI Example")
    show_manager.scene.add(combobox)

    values.extend(new_values)
    combobox.append_item(*new_values)
    npt.assert_equal(values, combobox.items)

    values.append("An Item7")
    combobox.append_item("An Item7")
    npt.assert_equal(values, combobox.items)

    values.append("An Item8")
    values.append("An Item9")
    combobox.append_item("An Item8", "An Item9")
    npt.assert_equal(values, combobox.items)

    complex_list = [[0], (1, [[2, 3], 4], 5)]
    combobox.append_item(*complex_list)
    values.extend([str(i) for i in range(6)])
    npt.assert_equal(values, combobox.items)

    invalid_item = {"Hello": 1, "World": 2}
    npt.assert_raises(TypeError, combobox.append_item, invalid_item)

    npt.assert_equal(values, combobox.items)
    npt.assert_equal((60, 60), combobox.drop_button_size)
    npt.assert_equal([300, 140], combobox.drop_menu_size)
    npt.assert_equal([300, 200], combobox.size)

    ui.ComboBox2D(items=values, draggable=False)

    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("An Item1", combobox.selected_text)
    npt.assert_equal(1, combobox.selected_text_index)

    combobox.resize((450, 300))
    npt.assert_equal((360, 90), combobox.text_block_size)
    npt.assert_equal((90, 90), combobox.drop_button_size)
    npt.assert_equal((450, 210), combobox.drop_menu_size)
예제 #2
0
    "Indigo": (0.3, 0, 0.5),
    "Blue": (0, 0, 1),
    "Green": (0, 1, 0),
    "Yellow": (1, 1, 0),
    "Orange": (1, 0.5, 0),
    "Red": (1, 0, 0)
}

########################################################################
# ComboBox
# ===================
#
# Now we create a ComboBox UI component for selecting colors.

color_combobox = ui.ComboBox2D(items=list(colors.keys()),
                               placeholder="Choose Text Color",
                               position=(75, 50),
                               size=(250, 150))

########################################################################
# Callbacks
# ==================================
#
# Now we create a callback for setting the chosen color.


def change_color(combobox):
    label.color = colors[combobox.selected_text]


# `on_change` callback is set to `change_color` method so that
# it's called whenever a different option is selected.
예제 #3
0
                       justification="center",
                       vertical_justification="top",
                       text="FURY rocks!!!")

colors = {
    "Violet": (0.6, 0, 0.8),
    "Indigo": (0.3, 0, 0.5),
    "Blue": (0, 0, 1),
    "Green": (0, 1, 0),
    "Yellow": (1, 1, 0),
    "Orange": (1, 0.5, 0),
    "Red": (1, 0, 0)
}

color_combobox = ui.ComboBox2D(items=list(colors.keys()),
                               placeholder="Choose Text Color",
                               size=(250, 150),
                               draggable=True)


def change_color(combobox):
    label.color = colors[combobox.selected_text]


color_combobox.on_change = change_color

###############################################################################
# After defining content, we define properties for the tab.

tab_ui.tabs[2].title = "Colors"
tab_ui.add_element(2, color_combobox, (0.1, 0.3))
예제 #4
0
from fury import window, actor, ui

values = ["An Item" + str(i) for i in range(5)]
new_values = [str(i) for i in range(5)]

combobox = ui.ComboBox2D(
    items=values, position=(0, 100), size=(300, 200), draggable=True)
# disk = ui.Disk2D(10, center=(0, 100))

# count = 0
# def add_val(combobox):
#     global count
#     combobox.append_item("Test" + str(count))
#     count += 1

# def add_val_disk(i_ren, obj, element):
#     global count, combobox
#     combobox.append_item("Test" + str(count))
#     count += 1


# combobox.position = (0, 100)
# print(combobox.size)
# combobox.resize((150, 100))
# print(combobox.size)
# disk.on_left_mouse_button_clicked = add_val_disk
combobox.append_item(*new_values)
# combobox.on_change = add_val
showm = window.ShowManager(title="ComboBox UI Test")
showm.scene.add(combobox)
showm.start()
예제 #5
0
###############################################################################
# We also define a high resolution sphere to demonstrate the capability to
# dynamically change the sphere used for SH to SF projection.
sphere_high = get_sphere('symmetric362')

# We fix the order of the faces' three vertices to a clockwise winding. This
# ensures all faces have a normal going away from the center of the sphere.
sphere_high.faces = fix_winding_order(sphere_high.vertices,
                                      sphere_high.faces, True)
B_high = sh_to_sf_matrix(sphere_high, 8, return_inv=False)

###############################################################################
# We add a combobox for choosing the sphere resolution during execution.
sphere_dict = {'Low resolution': (sphere_low, B_low),
               'High resolution': (sphere_high, B_high)}
combobox = ui.ComboBox2D(items=list(sphere_dict))
scene.add(combobox)

###############################################################################
# Here we will write callbacks for the sliders and combo box and register them.


def change_slice_z(slider):
    i = int(np.round(slider.value))
    odf_actor_z.slice_along_axis(i)


def change_slice_y(slider):
    i = int(np.round(slider.value))
    odf_actor_y.slice_along_axis(i, 'yaxis')