diff --git a/package/heron.py b/package/heron.py index 300152d5..77d5721a 100755 --- a/package/heron.py +++ b/package/heron.py @@ -16,6 +16,7 @@ import sys from HERON.src.main import main from ui import run_from_gui +from ui.utils import run_in_workbench from utils import add_local_bin_to_path @@ -41,6 +42,10 @@ sys.argv.remove('-w') if (args.w or not args.input) and not args.definition: # if asked to or if no file is passed, run the GUI + # try: + # run_in_workbench(args.input) + # except RuntimeError: + # run_from_gui(main) run_from_gui(main) else: main() diff --git a/package/ui/controllers/file_selection.py b/package/ui/controllers/file_selection.py index 23c2e0b0..6f026b89 100644 --- a/package/ui/controllers/file_selection.py +++ b/package/ui/controllers/file_selection.py @@ -6,7 +6,7 @@ from .file_location_persistence import FileLocationPersistence from .file_dialog import FileDialogController - +from ui.utils import run_in_workbench class FileSpec: """ Input/output file specification for a package. """ @@ -87,6 +87,11 @@ def __init__(self, model, view): self.persistence.set_location(filename) self.file_dialog_controllers[spec.description] = file_dialog_controller + # Set the action for the "Open in Workbench" button + if model_package_name == "heron": + workbench_func = lambda: run_in_workbench(self.file_dialog_controllers['HERON Input File'].get_filename()) + self.file_selection.add_open_in_workbench_button(workbench_func) + def get_sys_args_from_file_selection(self): """ Gets the files selected by the user and returns them as a list along with their diff --git a/package/ui/views/file_selection.py b/package/ui/views/file_selection.py index 3247c351..33c9c062 100644 --- a/package/ui/views/file_selection.py +++ b/package/ui/views/file_selection.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import Optional, Callable import os import tkinter as tk @@ -14,6 +14,7 @@ def __init__(self, master: tk.Widget, **kwargs): """ super().__init__(master, **kwargs) self.file_selectors = {} + self.open_in_workbench_button = None def new_file_selector(self, label: str): """ @@ -25,6 +26,17 @@ def new_file_selector(self, label: str): frame.grid(row=len(self.file_selectors), column=0, sticky='w') self.file_selectors[label] = frame + def add_open_in_workbench_button(self, command: Callable): + """ + Create a button to open the file in Workbench. This button is only created once the first + file selector is added to the widget. Not every application will need this button, so its + creation is deferred until it is needed and is called by the controller. + """ + self.open_in_workbench_button = tk.Button(self, text='Open in Workbench') + self.open_in_workbench_button.grid(row=0, column=1, sticky='se') + self.grid_columnconfigure(1, weight=1) + self.open_in_workbench_button.config(command=command) + class SelectAFile(tk.Frame): """ A widget for selecting one file and displaying the path after selection. """