Up to date

This commit is contained in:
Atilla
2024-03-05 11:10:23 +01:00
parent f28973f46c
commit 928429b75d
12 changed files with 1167 additions and 244 deletions

58
app.js
View File

@@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron'); /* TYPE IN TERMINAL: "npm install electron" */
const { app, BrowserWindow,ipcMain } = require('electron'); /* TYPE IN TERMINAL: "npm install electron" */
const express = require('express'); /* TYPE IN TERMINAL: "npm install express" */
const bodyParser = require('body-parser'); /* TYPE IN TERMINAL: "npm install body-parser" */
const { PythonShell } = require('python-shell'); /* TYPE IN TERMINAL: "npm install python-shell" */
@@ -16,19 +16,31 @@ server.post('/submit-form', (req, res) => {
let options = {
mode: 'text',
args: [plant_naam, plantensoort, plant_geteelt] // Zet hier een variable bij om de data toe te voegen aan de database
args: [plant_naam, plantensoort, plant_geteelt], // Zet hier een variable bij om de data toe te voegen aan de databas
};
// Voer Python script uit met de plant_naam als argument
PythonShell.run('./script/db_connect_form.py', options, (err, results) => {
if (err) {
console.error(err);
res.send('Er is een fout opgetreden');
} else {
console.log('Python script uitvoering resultaten:', results);
res.send('Formulier succesvol verwerkt');
}
});
/*Om python te gebruiken*/
// ipcMain.on('request-update-temp', (event, args) => {
// let options = {
// mode: 'text',
// scriptPath: 'path/to/your/python/script',
// args: args
// };
// PythonShell.run('calculate.py', options, (err, results) => {
// if (err) {
// console.error('Error running python script', err);
// event.reply('update-temp-result', 'error');
// } else {
// console.log('Python script results:', results);
// event.reply('update-temp-result', results[0]); // Verstuur het resultaat terug naar de renderer proces
// }
// });
// });
// En dan in je renderer proces, stuur je een bericht om de update te verzoeken
ipcRenderer.send('request-update-temp', [/* hier kunnen argumenten komen die je Python script nodig heeft */]);
});
// Start de server voor verbinding met de database
@@ -42,6 +54,7 @@ function createWindow() {
const mainWindow = new BrowserWindow({
width: 1280,
height: 800,
frame: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
@@ -49,6 +62,27 @@ function createWindow() {
});
mainWindow.loadURL(urlElectron);
/*Is om het Python script te kunnen gebruiken*/
ipcMain.on('run-python-script', (event, args) => {
let options = {
mode: 'text',
args: args
};
PythonShell.run('../src/py/calculate.py', options, (err, results) => {
if (err)
{
console.error('Error running python script', err);
event.reply('python-script-response', 'error');
}
else
{
console.log('Python script results:', results);
event.reply('python-script-response', results);
}
});
});
}
app.whenReady().then(createWindow);