示例#1
0
文件: test_ui.py 项目: raamana/dipy
def test_ui_file_select_menu_2d(recording=False):
    filename = "test_ui_file_select_menu_2d"
    recording_filename = pjoin(DATA_DIR, filename + ".log.gz")
    expected_events_counts_filename = pjoin(DATA_DIR, filename + ".pkl")
    with InTemporaryDirectory() as tmpdir:
        for i in range(10):
            _ = open("test" + str(i) + ".txt", 'wt').write('some text')

        file_select_menu = ui.FileSelectMenu2D(size=(500, 500),
                                               position=(300, 300),
                                               font_size=16,
                                               extensions=["txt"],
                                               directory_path=os.getcwd(),
                                               parent=None)
        file_select_menu.set_center((300, 300))

        npt.assert_equal(file_select_menu.text_item_list[1].file_name[:4],
                         "test")
        npt.assert_equal(file_select_menu.text_item_list[5].file_name[:4],
                         "test")

        event_counter = EventCounter()
        for event in event_counter.events_counts:
            file_select_menu.add_callback(file_select_menu.buttons["up"].actor,
                                          event, event_counter.count)
            file_select_menu.add_callback(
                file_select_menu.buttons["down"].actor, event,
                event_counter.count)
            file_select_menu.menu.add_callback(
                file_select_menu.menu.panel.actor, event, event_counter.count)
            for text_ui in file_select_menu.text_item_list:
                file_select_menu.add_callback(
                    text_ui.text_actor.get_actors()[0], event,
                    event_counter.count)

        current_size = (600, 600)
        show_manager = window.ShowManager(size=current_size,
                                          title="DIPY File Select Menu")
        show_manager.ren.add(file_select_menu)

        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)
示例#2
0
def rotate_red_cube(i_ren, obj, slider):
    angle = slider.value
    cube_actor_1.RotateY(0.005 * angle)


disk_slider = ui.DiskSlider2D()
disk_slider.set_center((200, 200))
disk_slider.add_callback(disk_slider.handle, "MouseMoveEvent", rotate_red_cube)
"""
2D File Select Menu
==============
"""

file_select_menu = ui.FileSelectMenu2D(size=(500, 500),
                                       position=(300, 300),
                                       font_size=16,
                                       extensions=["py", "png"],
                                       directory_path=os.getcwd(),
                                       parent=None)
"""
Adding Elements to the ShowManager
==================================

Once all elements have been initialised, they have
to be added to the show manager in the following manner.
"""

current_size = (600, 600)
show_manager = window.ShowManager(size=current_size, title="DIPY UI Example")

show_manager.ren.add(cube_actor_1)
show_manager.ren.add(cube_actor_2)
示例#3
0
def rotate_red_cube(i_ren, obj, slider):
    angle = slider.value
    roi1_actor[0].RotateY(0.005 * angle)


disk_slider = ui.DiskSlider2D()
disk_slider.set_center((200, 200))
disk_slider.add_callback(disk_slider.handle, "MouseMoveEvent", rotate_red_cube)
"""
2D File Select Menu
==============
"""

file_select_menu = ui.FileSelectMenu2D(size=(300, 500),
                                       position=(160, 595),
                                       font_size=16,
                                       extensions=["tck", "gz"],
                                       directory_path=os.getcwd(),
                                       parent=None)
print file_select_menu.text_item_list
print file_select_menu.current_directory


def left_button_clicked(i_ren, obj, file_select_text):
    """ A callback to handle left click for this UI element.

    Parameters
    ----------
    i_ren: :class:`CustomInteractorStyle`
    obj: :class:`vtkActor`
        The picked actor
    file_select_text: :class:`FileSelectMenuText2D`