Coder Social home page Coder Social logo

ultrasound / python-gui-with-electron Goto Github PK

View Code? Open in Web Editor NEW

This project forked from keybraker/python-gui-electron

0.0 2.0 0.0 152 KB

A simple example on how to create electron GUIs for python programs

License: GNU General Public License v3.0

CSS 36.34% JavaScript 43.35% Python 4.39% HTML 15.92%

python-gui-with-electron's Introduction

Electron GUI for Python

A simple representation for creating an electron GUI for a python program and interacting with it.

How does it work ( simple representation )

electron
--------> |------------|    python
          |            |-------------> |-------------------|
          |  electron  |  sub process  | python program    |
          |  --------  |               | --------------    |
          |   > html   |      std      |  takes requests   |
          |   > css    | <-----------> |  from js and      |
          |   > js     | communication |  respons to them  |
          |            |               |  in terminal      |
          |------------|               |-------------------|

Essentially no network is being created only one terminal is used when electron is launched and than from within js ( electron ) a python program is initiated as a subprocess. These two programs than communicate via terminal with js talking to python and python answering the requests which js listens too.

Structure of example

│ 
├── ui.html
├── jsExample.css
├── jsExample.js
├── package.json
├── main.js
│ 
├── config.json
│ 
├── jsPython.png
│ 
├── pythonExample.py
│ 
├── LICENSE
└── README.md

Installation Guide

  1. To download and install electron ( OS X or Linux ) you have to download it from npm-electron using :

    npm install electron --save-dev
    
    npm install -g electron
    

    ( if you don't have npm installed use this link to download it. )

  2. Clone this repository with ( or download zip ):

    git clone https://github.com/keybraker/electron-GUI-for-python.git
    

Execution Guide

Open a terminal window and cd to cloned project

cd .../electron-GUI-for-python

Run the project by simply typing

electron .

A page should spawn looking as follows:

alt text

Then, press:

LAUNCH PYTHON CODE
~ this will launch a python application with a loop inside,
  that is waiting for data to be send from js

Afterwards press:

INTERACT WITH PYTHON CODE
~ this will send a message named "hello" from js to python
  and python will read it and print a message

And in the end press

TERMINATE PYTHON CODE
~ finally js will send a termination message "exit" to python
  and python will terminate and then js will terminate python
  so that no processes run in the backround

Also if you want to access externals files there is one more example

HOW TO OPEN A FILE
~ from jsExample.js an ipc.send message is sent to the main.js
  which will then read and output config.json's values.
  (This is a very fast and usefull feature to store settings)

Interpretation Guide

After that you should open jsExample.js and pythonExample.js in order to see how the example works and what triggered every message you see in your terminal.

Authors

Versions used to achieve communication are the following

Python Version Electron Version OSX Version

python-gui-with-electron's People

Contributors

keybraker avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.