Eel exposed python function called from js doesnt work when called from a local window

12 Views Asked by At

I have a web app that opens another window when pressing a button, this is the code which is called when pressing this button:

async function OpenLocalWindowForParamSetup(row_index) 
{
  var chosen_test = GetTestNameByRowIndex(row_index);
  
  if (chosen_test == '-- Select test --')
  {
    eel.ShowAlert("Please choose a test first.");
    return;
  }

 

  const localWindow = window.open("", "_blank", "|width=700,height=400");
  var param_dict = await RunPythonExtractParams(row_index);
  str ="";

  // Create a new local window
  str += "<!DOCTYPE html>";
  str += "<html lang='en'>";  
  str += "<head>";
  str += "<link rel='stylesheet' href='/index.css'>";
  str += "<script type='text/javascript' src='/eel.js'></script>";
  str += "<script type='text/javascript' src='/index.js'></script>";
  str += "<title> Parameters</title>";
  str += "</head>"; 
  str += "<body style='background-color:#3F4A59'>";
  str += "<h3> Set paremeters for " + chosen_test + "</h3>";
  str += "<div id='param_container_" + row_index + "'>";
  default_state_dict = {};
  let param_row = 0;
  for (const [key, value] of Object.entries(param_dict))
  {
    str += CreteParameterRow(param_row, key, value);
    default_state_dict[key] = value;              // we save the initial default state for the discard button
    param_row++;
  }

  str += "</div>";

  str += "<button class='ParamEditButtons'    role='button' title='Discard current changes' onclick='DiscardParamEdit(" + default_state_dict+" )'> Discard changes </button>"; //create discard button
  str += "<button class='ParamEditButtons'    role='button' title='Save current changes'    onclick='RunPythonSaveParamEdit("+row_index+",\""+chosen_test+"\")'> Save Changes</button>"; //create save button
  
  str += "</body>";
  str += "</html>";

  localWindow.document.write(str);
}

For better understanding, this is a screenshot of the new window: enter image description here

When I press the Save changes button the called function is RunPythonSaveParamEdit, this is the function:

function RunPythonSaveParamEdit(row_index, chosen_test)
{
  edited_param_dict = ExtractEditedParameters('param_container_'+ row_index);
  dict_with_test_name = {};
  dict_with_test_name[chosen_test] = edited_param_dict;
  eel.SaveParamEditButton(dict_with_test_name);
}

The problem is that this line doesnt do anything:

eel.SaveParamEditButton(dict_with_test_name);

this function is exposed by eel:

 @eel.expose
    def SaveParamEditButton(edited_param_dict):
        Engine.SaveParamEditButton(edited_param_dict)

The error I get when I try to inspect it is :

No resource with given URL found

All functions work properly when called from the main html window and when I tried to call the same function from the main window it worked so it has to be something about the new local window. How can I make it work?

0

There are 0 best solutions below