def test_ui_file_menu_2d(interactive=False): filename = "test_ui_file_menu_2d" recording_filename = pjoin(DATA_DIR, filename + ".log.gz") expected_events_counts_filename = pjoin(DATA_DIR, filename + ".json") # Create temporary directory and files os.mkdir(os.path.join(os.getcwd(), "testdir")) os.chdir("testdir") os.mkdir(os.path.join(os.getcwd(), "tempdir")) for i in range(10): open(os.path.join(os.getcwd(), "tempdir", "test" + str(i) + ".txt"), 'wt').close() open("testfile.txt", 'wt').close() filemenu = ui.FileMenu2D(size=(500, 500), extensions=["txt"], directory_path=os.getcwd()) # We will collect the sequence of files that have been selected. selected_files = [] def _on_change(): selected_files.append(list(filemenu.listbox.selected)) # Set up a callback when selection changes. filemenu.listbox.on_change = _on_change # Assign the counter callback to every possible event. event_counter = EventCounter() event_counter.monitor(filemenu) # Create a show manager and record/play events. show_manager = window.ShowManager(size=(600, 600), title="FURY FileMenu") show_manager.scene.add(filemenu) # Recorded events: # 1. Click on 'testfile.txt' # 2. Click on 'tempdir/' # 3. Click on 'test0.txt'. # 4. Shift + Click on 'test6.txt'. # 5. Click on '../'. # 2. Click on 'testfile.txt'. show_manager.play_events_from_file(recording_filename) expected = EventCounter.load(expected_events_counts_filename) event_counter.check_counts(expected) # Check if the right files were selected. expected = [["testfile.txt"], ["tempdir"], ["test0.txt"], ["test0.txt", "test1.txt", "test2.txt", "test3.txt", "test4.txt", "test5.txt", "test6.txt"], ["../"], ["testfile.txt"]] npt.assert_equal(len(selected_files), len(expected)) assert_arrays_equal(selected_files, expected) # Remove temporary directory and files os.remove("testfile.txt") for i in range(10): os.remove(os.path.join(os.getcwd(), "tempdir", "test" + str(i) + ".txt")) os.rmdir(os.path.join(os.getcwd(), "tempdir")) os.chdir("..") os.rmdir("testdir") if interactive: filemenu = ui.FileMenu2D(size=(500, 500), directory_path=os.getcwd()) show_manager = window.ShowManager(size=(600, 600), title="FURY FileMenu") show_manager.scene.add(filemenu) show_manager.start()
scene = window.Scene() scene.background((1, 1, 1)) open_static = ui.TextBlock2D() open_static.message = "Select template" use_dir = ui.TextBlock2D() use_dir.message = "Use directory" out_dir = ui.TextBlock2D() out_dir.message = "Output directory" from pathlib import Path home = str(Path.home()) file_menu = ui.FileMenu2D(home, size=(1200, 400)) panel = ui.Panel2D(size=(1800, 420)) class ProcessingObject(object): ftemplate = None dname = None out_dname = None po = ProcessingObject() def open_static_callback(obj, event):