Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions BrainSimMAC/BrainSimMACMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
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: ");
pythonPath = Console.ReadLine();
moduleHandler.PythonPath = pythonPath;
if (moduleHandler.InitPythonEngine())
{
Environment.SetEnvironmentVariable("PythonPath", pythonPath, EnvironmentVariableTarget.User);
Environment.SetEnvironmentVariable("PythonPath", pythonPath, EnvironmentVariableTarget.Process);
}
else
{
Expand Down
14 changes: 5 additions & 9 deletions BrainSimulator/ModuleHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public List<string> 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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions PythonProj/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")



Expand Down Expand Up @@ -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)
Expand Down
15 changes: 7 additions & 8 deletions PythonProj/module_uks_tree.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
## Global imports
from cgitb import text
import sys, os
#from tkinter.tix import MAX
from typing import List, Union
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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')


Expand Down