AdSense

Wednesday, February 21, 2018

Python Desktop Application Mock-up on macOS

Before you start, please refer to the following page to set up your Python environment.
http://thefjg.blogspot.com/2018/02/python-machine-learning-deep-learning.html

Start Terminal on macOS.

Install a light Web framework Flask:
pip3 install Flask

Install the latest version of node.js:
brew uninstall node
brew install node
brew link --overwrite --dry-run node


Check the installation of node.js.
which node
which npm


Install Electron for desktop applications backed by Web technologies like HTML, CSS, JavaScript.
npm install -g electron-prebuilt

Check the installation of Electron.
which electron

Creat a ElectronApp holder.
Move to the holder on Terminal, by using cd commands.
npm init -y

Now package.json file is created.


Start Atom.

File > Add Project Holder > (Select your ElectronApp holder.)

Update the package.json file as follows:

{
  "name": "ElectronApp",
  "version": "0.0.0",
  "main": "main.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": ""
}


Create (Atom > File > New File) and save the main.js file (Atom > File > Save As...) as follows:

'use strict';

// Modules for application control
var electron = require('electron');
var app = electron.app;
var BrowserWindow = electron.BrowserWindow;

// to avoid GC (Gabage Collection) of mainWindow, make it global
let mainWindow;

// Terminate if all the windows are closed
app.on('window-all-closed', function() {
  if (process.platform != 'darwin') {
    app.quit();
  }
});

// Execute after the Electron's initialization
app.on('ready', function() {
  // Show main screen
  mainWindow = new BrowserWindow({
    width: 800,
    height: 600
  });
  mainWindow.loadURL('file://' + __dirname + '/index.html');

  //Terminate the application when closing the window
  mainWindow.on('closed', function() {
    mainWindow = null;
  });
});


Create (Atom > File > New File) and save the index.html file (Atom > File > Save As... > index.html) for the desktop application's interface as follows:

Back to your Terminal on macOS.

Move up the directory and select/run the ElectronApp holder.
cd ..
electron ElectronApp/


No comments:

Post a Comment

Deep Learning (Regression, Multiple Features/Explanatory Variables, Supervised Learning): Impelementation and Showing Biases and Weights

Deep Learning (Regression, Multiple Features/Explanatory Variables, Supervised Learning): Impelementation and Showing Biases and Weights ...