Skip to content

Commit 7af34fb

Browse files
utilities fix
1 parent 4a9ca72 commit 7af34fb

1 file changed

Lines changed: 42 additions & 11 deletions

File tree

pica/main.py

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@
2323
import multiprocessing
2424
from multiprocessing import Process
2525

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
2833

2934
try:
3035
from PIL import Image, ImageTk
@@ -54,16 +59,44 @@ def run_script_process(script_path):
5459
print("-------------------------")
5560

5661

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+
5782
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+
6188
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
6497
Process(target=run_script_process, args=(plotter_path,)).start()
6598
except Exception as e:
66-
print(f"Failed to launch plotter: {e}")
99+
messagebox.showerror("Launch Error", f"Failed to launch Plotter Utility: {e}")
67100

68101

69102
def resource_path(relative_path):
@@ -747,9 +780,7 @@ def run_gpib_test(self):
747780
"Dependency Missing",
748781
"The 'pyvisa' library is required.\n\nInstall via pip:\npip install pyvisa pyvisa-py")
749782
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()
753784

754785
def _pre_cache_markdown_files(self):
755786
"""

0 commit comments

Comments
 (0)