From 1cc341bce504f0c3b092f55f46737a53e018a432 Mon Sep 17 00:00:00 2001 From: Tanner Hoffman <41430668+qwertyuiop1379@users.noreply.github.com> Date: Wed, 25 Feb 2026 00:41:31 -0700 Subject: [PATCH] Fix issues with Mac environment --- BrainSimMAC/BrainSimMACMain.cs | 4 ++-- BrainSimulator/ModuleHandler.cs | 14 +++++--------- PythonProj/MainWindow.py | 12 ++++++------ PythonProj/module_uks_tree.py | 15 +++++++-------- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/BrainSimMAC/BrainSimMACMain.cs b/BrainSimMAC/BrainSimMACMain.cs index f7f1655..ed83f08 100644 --- a/BrainSimMAC/BrainSimMACMain.cs +++ b/BrainSimMAC/BrainSimMACMain.cs @@ -18,7 +18,7 @@ moduleHandler.CreateEmptyUKS(); //setup the python path -string? pythonPath = (string?)Environment.GetEnvironmentVariable("PythonPath", EnvironmentVariableTarget.User); +string? pythonPath = (string?)Environment.GetEnvironmentVariable("PythonPath", EnvironmentVariableTarget.Process); if (string.IsNullOrEmpty(pythonPath)) { Console.Write("Path to Python .dll must be set: "); @@ -26,7 +26,7 @@ moduleHandler.PythonPath = pythonPath; if (moduleHandler.InitPythonEngine()) { - Environment.SetEnvironmentVariable("PythonPath", pythonPath, EnvironmentVariableTarget.User); + Environment.SetEnvironmentVariable("PythonPath", pythonPath, EnvironmentVariableTarget.Process); } else { diff --git a/BrainSimulator/ModuleHandler.cs b/BrainSimulator/ModuleHandler.cs index db66f6f..a423610 100644 --- a/BrainSimulator/ModuleHandler.cs +++ b/BrainSimulator/ModuleHandler.cs @@ -87,7 +87,7 @@ public List GetListOfExistingPythonModuleTypes() if (pythonPath == "no") return pythonFiles; try { - var filesInDir = Directory.GetFiles(@".", "m*.py").ToList(); + var filesInDir = Directory.GetFiles(AppContext.BaseDirectory, "m*.py").ToList(); foreach (var file in filesInDir) { if (file.StartsWith("utils")) continue; @@ -116,10 +116,8 @@ public bool InitPythonEngine() if (!PythonEngine.IsInitialized) PythonEngine.Initialize(); dynamic sys = Py.Import("sys"); - dynamic os = Py.Import("os"); - string desiredPath = os.path.join(os.getcwd(), "./bin/Debug/net8.0/"); - sys.path.append(desiredPath); // enables finding scriptName module - sys.path.append(os.getcwd() + "\\pythonModules"); + sys.path.append(AppContext.BaseDirectory); + sys.path.append(Path.Combine(Environment.CurrentDirectory, "pythonModules")); Console.WriteLine("PythonEngine init succeeded\n"); } catch (Exception ex) @@ -166,10 +164,8 @@ public void RunScript(string moduleLabel) Runtime.PythonDLL = PythonPath;// @"python310"; // Charles's Windows PythonEngine.Initialize(); dynamic sys = Py.Import("sys"); - dynamic os = Py.Import("os"); - string desiredPath = os.path.join(os.getcwd(), "./bin/Debug/net8.0/"); - sys.path.append(desiredPath); // enables finding scriptName module - sys.path.append(os.getcwd() + "\\pythonModules"); + sys.path.append(AppContext.BaseDirectory); + sys.path.append(Path.Combine(Environment.CurrentDirectory, "pythonModules")); Console.WriteLine("PythonEngine init succeeded\n"); } catch diff --git a/PythonProj/MainWindow.py b/PythonProj/MainWindow.py index f5422e5..e466d1e 100644 --- a/PythonProj/MainWindow.py +++ b/PythonProj/MainWindow.py @@ -73,7 +73,7 @@ def openFile(self): self.uks.LoadUKSfromXMLFile(fileName) self.setupUKS() if self.uks.Labeled("MainWindow.py") == None: - self.uks.AddThing("MainWindow.py", self.uks.Labeled("AvailableModule")); + self.uks.AddThought("MainWindow.py", self.uks.Labeled("AvailableModule")); self.activateModule("MainWindow.py") self.level.title(titleBase +' -- ' +os.path.basename(fileName)) self.setupcontent() @@ -82,14 +82,14 @@ def openFile(self): #Add necessary status info to older UKS if needed def setupUKS(self): if self.uks.Labeled("BrainSim") == None: - self.uks.AddThing("BrainSim",None) - self.uks.GetOrAddThing("AvailableModule","BrainSim") - self.uks.GetOrAddThing("ActiveeModule","BrainSim") + self.uks.AddThought("BrainSim",None) + self.uks.GetOrAddThought("AvailableModule","BrainSim") + self.uks.GetOrAddThought("ActiveModule","BrainSim") if self.uks.Labeled("AvailableModule").Children.Count == 0: python_modules = os.listdir(".") for module in python_modules: if module.startswith("m") and module.endswith(".py"): - self.uks.GetOrAddThing(module,"AvailableModule") + self.uks.GetOrAddThought(module,"AvailableModule") @@ -135,7 +135,7 @@ def deactivateModule(self,moduleLabel): thingToDeactivate= self.uks.Labeled(moduleLabel) if thingToDeactivate != None: self.uks.DeleteAllChildren(thingToDeactivate) - self.uks.DeleteThing(thingToDeactivate) + self.uks.DeleteThought(thingToDeactivate) def activateModule(self,moduleTypeLabel): print ("activating ",moduleTypeLabel) thingToActivate= self.uks.Labeled(moduleTypeLabel) diff --git a/PythonProj/module_uks_tree.py b/PythonProj/module_uks_tree.py index 17232c1..6325923 100644 --- a/PythonProj/module_uks_tree.py +++ b/PythonProj/module_uks_tree.py @@ -1,5 +1,4 @@ ## Global imports -from cgitb import text import sys, os #from tkinter.tix import MAX from typing import List, Union @@ -47,12 +46,12 @@ def add_children(self, parent_id: str, item_label: str) -> None: if parent_thing is None: # safety return children = parent_thing.Children - for child in children: + for idx, child in enumerate(children): try: - #todo, randomize the iid in order to allow duplicates - iid: str = self.tree_view.insert(parent=parent_id, + iid: str = f"{parent_id}_{idx}" + self.tree_view.insert(parent=parent_id, index="end", - iid=child.ToString(), + iid=iid, text=child.ToString()) if parent_id in self.open_items: self.tree_view.item(parent_id, open=True) @@ -117,9 +116,9 @@ def build(self) -> None: self.style.theme_use("clam") self.tree_view.pack(expand=True, fill=tk.BOTH, padx=10, pady=10) ## Inserted at the root: - iid: str = self.tree_view.insert("", "end", "Thing", text="Thing") + iid: str = self.tree_view.insert("", "end", "Thought", text="Thought") self.curr_depth = 1 - self.add_children(iid, "Thing") + self.add_children(iid, "Thought") ## Add REFRESH button self.refresh_button = tk.Button(master=self.level, @@ -129,7 +128,7 @@ def build(self) -> None: root_label = tk.Label(master=self.level, text="Root:") root_label.pack(side='left',padx=10) self.rootBox = tk.Entry(master=self.level,width=20) - self.rootBox.insert(tk.END,"Thing") + self.rootBox.insert(tk.END,"Thought") self.rootBox.pack(side='left')