Skip to content

Commit

Permalink
open Workbench from HERON launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
j-bryan committed Jun 10, 2024
1 parent 38bcf6f commit c5a5ca1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions package/heron.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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()
7 changes: 6 additions & 1 deletion package/ui/controllers/file_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. """
Expand Down Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion package/ui/views/file_selection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from typing import Optional, Callable
import os
import tkinter as tk

Expand All @@ -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):
"""
Expand All @@ -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. """
Expand Down

0 comments on commit c5a5ca1

Please sign in to comment.