|
23 | 23 | import multiprocessing |
24 | 24 | from multiprocessing import Process |
25 | 25 |
|
26 | | -# Ensure this import exists in your project structure |
27 | | -from pica.utils.GPIB_Instrument_Scanner_GUI import GPIB_Instrument_Scanner_GUI |
| 26 | +# IMPORT THE UTILS MODULE TO FIND ITS PATH AUTOMATICALLY |
| 27 | +try: |
| 28 | + import pica.utils.GPIB_Instrument_Scanner_GUI as gpib_scanner_module |
| 29 | + import pica.utils.PlotterUtil_GUI as plotter_module |
| 30 | + UTILS_AVAILABLE = True |
| 31 | +except ImportError: |
| 32 | + UTILS_AVAILABLE = False |
28 | 33 |
|
29 | 34 | try: |
30 | 35 | from PIL import Image, ImageTk |
@@ -54,16 +59,44 @@ def run_script_process(script_path): |
54 | 59 | print("-------------------------") |
55 | 60 |
|
56 | 61 |
|
| 62 | +def launch_gpib_scanner(): |
| 63 | + """Finds and launches the GPIB scanner utility using the package path.""" |
| 64 | + if not UTILS_AVAILABLE: |
| 65 | + messagebox.showerror("Import Error", "Could not import pica.utils. Is the package installed?") |
| 66 | + return |
| 67 | + |
| 68 | + try: |
| 69 | + # Get the absolute path directly from the imported module |
| 70 | + scanner_path = os.path.abspath(gpib_scanner_module.__file__) |
| 71 | + |
| 72 | + if not os.path.exists(scanner_path): |
| 73 | + messagebox.showerror("File Not Found", f"Scanner not found at:\n{scanner_path}") |
| 74 | + return |
| 75 | + |
| 76 | + # Run it |
| 77 | + Process(target=run_script_process, args=(scanner_path,)).start() |
| 78 | + except Exception as e: |
| 79 | + messagebox.showerror("Launch Error", f"Failed to launch GPIB Scanner: {e}") |
| 80 | + |
| 81 | + |
57 | 82 | def launch_plotter_utility(): |
58 | | - """ |
59 | | - Finds and launches the plotter utility script in a new process. |
60 | | - """ |
| 83 | + """Finds and launches the plotter utility using the package path.""" |
| 84 | + if not UTILS_AVAILABLE: |
| 85 | + messagebox.showerror("Import Error", "Could not import pica.utils. Is the package installed?") |
| 86 | + return |
| 87 | + |
61 | 88 | try: |
62 | | - script_dir = os.path.dirname(os.path.abspath(__file__)) |
63 | | - plotter_path = os.path.join(script_dir, "utils", "PlotterUtil_GUI.py") |
| 89 | + # Get the absolute path directly from the imported module |
| 90 | + plotter_path = os.path.abspath(plotter_module.__file__) |
| 91 | + |
| 92 | + if not os.path.exists(plotter_path): |
| 93 | + messagebox.showerror("File Not Found", f"Plotter not found at:\n{plotter_path}") |
| 94 | + return |
| 95 | + |
| 96 | + # Run it |
64 | 97 | Process(target=run_script_process, args=(plotter_path,)).start() |
65 | 98 | except Exception as e: |
66 | | - print(f"Failed to launch plotter: {e}") |
| 99 | + messagebox.showerror("Launch Error", f"Failed to launch Plotter Utility: {e}") |
67 | 100 |
|
68 | 101 |
|
69 | 102 | def resource_path(relative_path): |
@@ -747,9 +780,7 @@ def run_gpib_test(self): |
747 | 780 | "Dependency Missing", |
748 | 781 | "The 'pyvisa' library is required.\n\nInstall via pip:\npip install pyvisa pyvisa-py") |
749 | 782 | return |
750 | | - # The GPIB scanner is now its own class, create a new window for it |
751 | | - scanner_window = Toplevel(self.root) |
752 | | - GPIB_Instrument_Scanner_GUI(scanner_window) |
| 783 | + launch_gpib_scanner() |
753 | 784 |
|
754 | 785 | def _pre_cache_markdown_files(self): |
755 | 786 | """ |
|
0 commit comments