-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
68 lines (54 loc) · 1.69 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const { app, BrowserWindow, ipcMain, dialog } = require('electron')
const path = require('path');
const {PythonShell} = require('python-shell')
function createWindow () {
let win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js'), // provide path to preload.js
nodeIntegration: true,
contextIsolation: false, //uncomment this when you aren't testing
enableRemoteModule: true,
}
})
win.loadFile('dist/index.html')
}
app.whenReady().then(createWindow)
ipcMain.on('open-file-dialog-for-file', (event) => {
dialog.showOpenDialog({
properties: ['openFile'],
filters: [{ name: 'Videos', extensions: ['mp4', 'mov', 'ogv', 'gif'] }]
}).then(result => {
if (result.filePaths.length > 0) {
event.sender.send('selected-file', result.filePaths[0]);
} else {
event.sender.send('user-canceled-file-upload');
}
}).catch(err => {
console.log(err);
});
});
ipcMain.handle('run-python-script', (event, scriptName, args) => {
return new Promise((resolve, reject) => {
let options = {
mode: 'text',
pythonOptions: ['-u'],
scriptPath: './smaller_scripts/',
args: args
}
let shell = new PythonShell(scriptName, options); //'takeVideoCrossSection.py' is one script
let output = [];
shell.on('message', function(message) {
console.log(message); // This will print python print statements in node console
output.push(message);
});
shell.end(function (err) {
if (err) {
reject(err.toString());
} else {
resolve(output);
}
});
});
});