|
41 | 41 | """
|
42 | 42 | ETSConfig.toolkit = "qt"
|
43 | 43 |
|
| 44 | +class FilteredFileBrowserExample(HasTraits): |
| 45 | + """ |
| 46 | + An example showing how to filter for specific file types. |
| 47 | + """ |
| 48 | + file_path = File() |
| 49 | + |
| 50 | + view = View( |
| 51 | + Item('file_path', |
| 52 | + label="Select a YAML File", |
| 53 | + editor=FileEditor(filter=['*.yaml','*.yml']), |
| 54 | + ), |
| 55 | + title="YAML File Browser", |
| 56 | + buttons=['OK', 'Cancel'], |
| 57 | + resizable=True |
| 58 | + ) |
44 | 59 |
|
45 | 60 | class Clicker(ImageInspectorTool):
|
46 | 61 | """
|
@@ -134,7 +149,7 @@ def attach_tools(self):
|
134 | 149 |
|
135 | 150 | pan = PanTool(self._plot, drag_button="middle")
|
136 | 151 | zoom_tool = ZoomTool(self._plot, tool_mode="box", always_on=False)
|
137 |
| - zoom_tool.max_zoom_out_factor = 1.0 # Disable "bird view" zoom out |
| 152 | + # zoom_tool.max_zoom_out_factor = 1.0 # Disable "bird view" zoom out |
138 | 153 | self._img_plot.overlays.append(zoom_tool)
|
139 | 154 | self._img_plot.tools.append(pan)
|
140 | 155 | # print(self._img_plot.tools)
|
@@ -437,31 +452,20 @@ def new_action(self, info):
|
437 | 452 | print("not implemented")
|
438 | 453 |
|
439 | 454 | def open_action(self, info):
|
440 |
| - from tkinter import filedialog |
441 |
| - import tkinter as tk |
442 |
| - |
443 |
| - root = tk.Tk() |
444 |
| - root.withdraw() |
445 |
| - file_path = filedialog.askopenfilename( |
446 |
| - title="Select YAML parameter file", |
447 |
| - filetypes=[("YAML files", "*.yaml *.yml")] |
448 |
| - ) |
449 |
| - if file_path: |
450 |
| - try: |
451 |
| - yaml_file = Path(file_path) |
452 |
| - # Re-initialize MainGUI with the new YAML file |
453 |
| - # Close the current GUI and open a new one |
454 |
| - print(f"Opening new experiment from {yaml_file}") |
455 |
| - # Save current working directory |
456 |
| - cwd = Path.cwd() |
457 |
| - os.chdir(yaml_file.parent) |
458 |
| - new_gui = MainGUI(yaml_file) |
459 |
| - new_gui.configure_traits() |
460 |
| - os.chdir(cwd) |
461 |
| - except Exception as e: |
462 |
| - print(f"Failed to open YAML file: {e}") |
463 |
| - else: |
464 |
| - print("No YAML file selected.") |
| 455 | + |
| 456 | + filtered_browser_instance = FilteredFileBrowserExample() |
| 457 | + filtered_browser_instance.configure_traits() |
| 458 | + if filtered_browser_instance.file_path: |
| 459 | + print(f"\nYou selected the YAML file: {filtered_browser_instance.file_path}") |
| 460 | + yaml_path = Path(filtered_browser_instance.file_path) |
| 461 | + if yaml_path.is_file() and yaml_path.suffix in {".yaml", ".yml"}: |
| 462 | + print(f"Initializing MainGUI with selected YAML: {yaml_path}") |
| 463 | + os.chdir(yaml_path.parent) # Change to the directory of the YAML file |
| 464 | + main_gui = MainGUI(yaml_path) |
| 465 | + main_gui.configure_traits() |
| 466 | + else: |
| 467 | + print("\nNo file was selected.") |
| 468 | + |
465 | 469 |
|
466 | 470 | def exit_action(self, info):
|
467 | 471 | print("not implemented")
|
|
0 commit comments