Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createWindow () {
// run junction
PythonShell.run('electron.py', {}, function (err, results) {
if (err) console.log(err);
});
// open browser windows, visit junction
window = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nativeWindowOpen: true,
},
})
window.webContents.on('new-window', (event, url, frameName, disposition, options, additionalFeatures) => {
if (frameName === 'modal') {
// open window as modal
event.preventDefault()
(async () => {
let port = await getPort()
let script = getScriptPath()
global.port = port;
var options = {
args: [port]
};
console.log(script)
console.log(script)
if (guessPackaged()) {
global.py_proc = require('child_process').execFile(script, [port])
} else {
global.py_proc = PythonShell.run(script, options, function (err, results) {
if (err) console.log(err);
});
}
// PythonShell.run('./backend/engine.py', options, function (err, results) {
// if (err) console.log(err);
// });
window = new BrowserWindow({width: 800, height: 600,
frame: true,
webPreferences: {
webSecurity: false,
plugins: true
},
});
// window.webContents.openDevTools()
args.push("--filter");
args.push(
config.filter
.map(function(filter) {
return `-${filter}`;
})
.join(",")
);
}
const cppLintOptions = {
pythonPath,
scriptPath: __dirname,
args: args.concat(files)
};
PythonShell.run("cpplint.py", cppLintOptions, function(err) {
if (err) {
console.error(err.message);
process.exit(1);
}
});
} else {
console.error(`No files found matching ${config.files.join(", ")}`);
process.exit(1);
}
});
static list() {
var pythonPath = settings.read('midi') ? settings.read('midi').filter(x=>x.includes('path=')).map(x=>x.split('=')[1])[0] : undefined
PythonShell.run('python/list.py', Object.assign({pythonPath}, pythonOptions), function(err, results) {
if (err) console.error(err)
MidiConverter.parseIpc(results)
})
}
return new Promise((resolve, reject) => {
const options = {
mode: 'text',
pythonPath: 'python3',
scriptPath,
args
};
return PythonShell.run(scriptName, options, (err, results) => {
if (err) {
reject(new Error(`Python3 is missing or script not found: ${err}`));
}
try {
const result = JSON.parse(results[0]);
resolve(result);
} catch (err2) {
reject(new Error(`No valid JSON from Python script: ${err2}`));
}
});
});
} catch (err) {
message: 'Models Path Not Found',
details: 'Please enter a valid models repository path in the projects settings.',
});
return;
}
if (opts.samplePath !== null) {
const options: Options = {
mode: 'text',
pythonPath: opts.pythonPath,
scriptPath: opts.modelsPath,
args: [opts.samplePath],
};
PythonShell.run(opts.scriptPath, options, (err?: Error) => {
if (err) {
return opts.cb({
type: 'error',
message: 'Unknown Error',
details: err.message,
});
}
opts.cb({
type: 'success',
message: 'Model Ran Successfully',
details: 'Check the File Explorer for the model output.',
});
});
} else {
opts.cb({
let options = PythonShell.defaultOptions;
options.scriptPath = SCRIPT_PATH;
const pythonPath: string | undefined = vscode.workspace
.getConfiguration("python")
.get("pythonPath");
if (!!pythonPath) {
options.pythonPath = pythonPath;
}
let input = script;
options.args = PY_ARGS;
options.args[0] = input;
PythonShell.run(SCRIPT_NAME, options, (err, results) => {
if (err) {
onPythonError(err, uri);
} else {
callback(results);
}
});
}