2

I am trying to create a desktop application using Electron. My requirement is to use Angular for front-end and python for back-end (that should communicate with SQLite database).

This is what I have ready:

  1. I have the front-end web application created/designed by Angular 7 and Material
  2. I also have 10 pure python files (without any framework) that should do some back-end logic whenever buttons are clicked from the web application.
  3. Electron environment is ready and main.js is pointing to Angular index.html file.
  4. Python files are in a separate folder not connected to anything yet.

When I fire up the Electron, the app starts and I can see the Angular web interface. All I have left to do is to send the requests when the button is clicked to the backend (python files).


What I know and have tried so far:

  • Add ngx-electron module to my Angular component import { ElectronService } from "ngx-electron"
  • I use ipcRenderer.send('aaa', data) to send data and ipcRenderer.on('bbb', () => {}) to get the response from a MAIN process
  • In the MAIN process (main.js),

    ipcMain.on('aaa', (e, filename) => { // exec(pythonfile params); e.sender('bbb', response); })


Questions:

Is this the right way or there is a cleaner solution to send and receive data between Angular and python?

I feel like when you have lots of requests those listeners will become messy, not sure. I have always used HTTP requests that are cleaner but never used inter-process communication ...

Brian
  • 4,958
  • 8
  • 40
  • 56

1 Answers1

0

I've not done this, but I suspect it can be achieved thus:

You'll need Node to run a python script:

let process = spawn(‘python’, [“./d_alembert.py”]);

There are more answers here.

While an electron app will run on basically any OS, it's not clear that another user will have python installed (Mac OS comes with it, Windows doesn't). So it may work on your machine, but not on someone else's.

Boris Yakubchik
  • 3,861
  • 3
  • 34
  • 41