Skip to content

Commit fabd3ff

Browse files
committed
rewrite of all modules. major changes.
1 parent 1b5a776 commit fabd3ff

File tree

18 files changed

+627
-689
lines changed

18 files changed

+627
-689
lines changed

scripts/setup.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ conda create -n tfgui python=3.5
88
conda activate tfgui
99
conda install --file .\..\requirements.txt
1010
conda install -c menpo opencv
11+
conda install -c conda-forge python-language-server
1112
conda deactivate
1213

1314
Set-Location .\..\src\

src/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ function createWindow() {
1414
height: 720,
1515
darkTheme: true,
1616
webPreferences: { nodeIntegration: true},
17+
show: false
1718
});
1819
win.loadFile('modules/index.html')
19-
win.on('closed', () => {
20-
win = null
21-
});
22-
20+
2321
var menu = Menu.buildFromTemplate([{
2422
label: 'File',
2523
submenu: [
@@ -40,12 +38,17 @@ function createWindow() {
4038
]
4139
}]);
4240
Menu.setApplicationMenu(menu);
41+
42+
win.once('ready-to-show', ()=>{
43+
win.show();
44+
});
4345

46+
win.on('closed', () => {
47+
win = null
48+
});
4449
}
4550

46-
// on ready, create the new browser window
4751
app.on('ready', createWindow);
48-
4952
app.on('window-all-closed', () => {
5053
let killtensorboard;
5154
if (process.platform == 'win32') {
@@ -60,7 +63,6 @@ app.on('window-all-closed', () => {
6063
});
6164
}
6265
});
63-
6466
app.on('activate', () => {
6567
if (win === null) {
6668
createWindow()

src/modules/codeeditor/codeeditor.html

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
<div id="right-draw-header">
1212
<div>
13-
<button id="backButton" class="btn btn-light p-2 btn-responsive">Back</button>
14-
<button id="saveProject" class="btn btn-light p-2 btn-responsive">Save</button>
15-
<button id="trainbutton" class="btn btn-light p-2 btn-responsive">Train</button>
13+
<button id="codeeditor-back-button" class="btn btn-light p-2 btn-responsive">Back</button>
14+
<button id="codeeditor-save-project-button" class="btn btn-light p-2 btn-responsive">Save</button>
15+
<button id="codeeditor-train-button" class="btn btn-light p-2 btn-responsive">Train</button>
1616
</div>
1717
</div>
1818
</header>
@@ -22,9 +22,4 @@
2222
<div id="code-editor" ></div>
2323
</div>
2424

25-
</div>
26-
27-
<script>
28-
delete require.cache[require.resolve('./codeeditor/codeeditor.js')]
29-
require("./codeeditor/codeeditor.js");
30-
</script>
25+
</div>
Lines changed: 33 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
const print = console.log;
2-
const swal = require('sweetalert');
3-
const global = require("../../lib/global.js")
4-
const childprocess = require('child_process');
5-
var fs = require('fs');
61
const pythonFunction = require("../../lib/datafunctions");
7-
const path = require('path');
82
const amdLoader = require('monaco-editor/min/vs/loader.js');
93
const amdRequire = amdLoader.require;
104
const amdDefine = amdLoader.require.define;
115

12-
13-
$("#project-name").text(global.projectDetails.name);
14-
$("#project-details").text(global.projectDetails.details.substr(0, 20) + "...");
15-
16-
let dir = global.projectDetails.name;
17-
let basepath = path.join(process.cwd(), "/../testing/Projects/");
18-
global.editorText = fs.readFileSync(path.join(basepath, dir, "editor.py"), "utf8");
6+
var codeeditor;
197

208
function uriFromPath(_path) {
219
var pathName = path.resolve(_path).replace(/\\/g, '/');
@@ -25,72 +13,40 @@ function uriFromPath(_path) {
2513
return encodeURI('file://' + pathName);
2614
}
2715

28-
amdRequire.config({
29-
baseUrl: uriFromPath(path.join(__dirname, '../../node_modules/monaco-editor/min'))
30-
});
31-
32-
33-
amdRequire(['vs/editor/editor.main'], () => {
34-
var codeeditor = monaco.editor.create(document.getElementById('code-editor'), {
35-
value: global.editorText,
36-
language: 'python',
37-
autoIndent: true
38-
});
39-
40-
function loadPage(page_path) {
41-
$("#main-content").html('');
42-
$("#main-content").load(page_path);
43-
}
44-
45-
function testPython() {
46-
let codepath = path.join(basepath, dir, "editor.py");
47-
try {
48-
fs.writeFileSync(codepath, codeeditor.getValue(), 'utf-8');
49-
} catch (e) {
50-
console.log('Failed to save the file !');
16+
function saveProject(isShow) {
17+
let dir = globaljs.projectDetails.name;
18+
globaljs.editorText = codeeditor.getValue();
19+
fs.writeFile(path.join(projects_path, dir, "editor.py"), globaljs.editorText, 'utf-8', err => {
20+
if (err) {
21+
swal("Saving Project", "Failed to save project.", "error");
22+
print("Error writing file", err);
23+
} else {
24+
if (isShow)
25+
swal("Saving Project", "Project saved successfully.", "success");
5126
}
52-
53-
var env = Object.create(process.env);
54-
console.log(env);
55-
var pythoncmd = process.platform == "win32"? path.join(env['CONDA_PREFIX'],'python.exe'): 'python3';
56-
var pythonprocess = childprocess.spawn(pythoncmd, ['-m', 'py_compile', codepath], {
57-
env: env
58-
});
59-
60-
pythonprocess.on('close', (code) => {
61-
if (code != 0) {
62-
swal("Oops!", "Error in code! Please correct the code and try again!", "error");
63-
} else {
64-
global.editorText = codeeditor.getValue();
65-
loadPage("training/training.html");
66-
}
67-
console.log(`child process exited with code ${code}`);
68-
});
69-
}
70-
71-
72-
function saveProject(isShow) {
73-
global.editorText = codeeditor.getValue();
74-
fs.writeFile(path.join(basepath, dir, "editor.py"), global.editorText, 'utf-8', err => {
75-
if (err) {
76-
swal("Saving Project", "Failed to save project.", "error");
77-
print("Error writing file", err);
78-
} else {
79-
if (isShow)
80-
swal("Saving Project", "Project saved successfully.", "success");
81-
}
82-
});
83-
}
84-
85-
$("#trainbutton").click(function () {
86-
testPython();
8727
});
28+
}
8829

89-
$("#saveProject").click(function () {
90-
saveProject(true);
30+
function init(){
31+
codeeditor = undefined;
32+
$("#project-name").text(globaljs.projectDetails.name);
33+
$("#project-details").text(globaljs.projectDetails.details.substr(0, 20) + "...");
34+
let dir = globaljs.projectDetails.name;
35+
globaljs.editorText = fs.readFileSync(path.join(projects_path, dir, "editor.py"), "utf8");
36+
amdRequire.config({
37+
baseUrl: uriFromPath(path.join(__dirname, '../../node_modules/monaco-editor/min'))
9138
});
92-
93-
$("#backButton").click(function () {
94-
loadPage("user/user.html");
39+
40+
amdRequire(['vs/editor/editor.main'], () => {
41+
codeeditor = monaco.editor.create(document.getElementById('code-editor'), {
42+
value: globaljs.editorText,
43+
language: 'python',
44+
autoIndent: true
45+
});
9546
});
96-
});
47+
}
48+
49+
module.exports = {
50+
init: init,
51+
saveProject: saveProject
52+
}

src/modules/index.html

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,20 @@
5959
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
6060
crossorigin="anonymous"></script>
6161
<script>
62-
// include a initial js file
62+
const path = require('path');
63+
const print = console.log;
64+
const swal = require('sweetalert');
65+
const fs = require('fs');
66+
const globaljs = require('../lib/global');
67+
const childprocess = require('child_process');
68+
69+
let projects_path = path.join(process.cwd(), "/../testing/Projects/");
70+
71+
function loadPage(page_path, onComplete) {
72+
$("#main-content").html('');
73+
$("#main-content").load(page_path, onComplete);
74+
}
75+
6376
require("./index.js");
6477
</script>
6578
</body>

src/modules/index.js

Lines changed: 143 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,147 @@
1-
// function for loading html pages by path
2-
function loadPage(page_path) {
3-
$("#main-content").html('');
4-
$("#main-content").load(page_path);
1+
const rimraf = require("rimraf");
2+
const userjs = require('./user/user');
3+
const settingsjs = require('./settings/settings');
4+
const projectjs = require('./project/project');
5+
const codeeditorjs = require('./codeeditor/codeeditor');
6+
const nodeeditorjs = require('./nodeeditor/nodeeditor');
7+
const trainingjs = require('./training/training');
8+
9+
function settingsBackButton(){
10+
$("#settings-back-button").click(() => {
11+
init();
12+
});
13+
}
14+
15+
function userSettingsButton(){
16+
$("#user-settings-button").click(() => {
17+
loadPage("settings/settings.html", ()=>{
18+
settingsBackButton();
19+
});
20+
});
21+
}
22+
23+
function projectBackButton(){
24+
$("#project-details-back-button").click(() => {
25+
init();
26+
});
27+
}
28+
29+
function projectDeleteButtons(){
30+
$(".deletebuttons").click((value) => {
31+
swal({
32+
title: "Are you sure?",
33+
text: `You are going to delete project named '${globaljs.projectDetails.name}'.Once deleted, you will not be able to recover this project!`,
34+
icon: "warning",
35+
buttons: true,
36+
dangerMode: true,
37+
}).then((willDelete) => {
38+
if (willDelete) {
39+
try {
40+
rimraf.sync(path.join(projects_path,globaljs.projectDetails.name));
41+
swal(`Your project '${globaljs.projectDetails.name}' has been deleted!`, {
42+
icon: "success",
43+
});
44+
} catch (err) {
45+
swal(`Failed to delete project.`, {
46+
icon: "error",
47+
});
48+
}
49+
init();
50+
}
51+
});
52+
});
53+
}
54+
55+
function userProjectButtons(){
56+
$(".settingsbuttons").click((value) => {
57+
userjs.setProject(value);
58+
loadPage("project/project.html", ()=>{
59+
projectjs.init();
60+
projectDeleteButtons();
61+
projectBackButton();
62+
});
63+
});
64+
65+
$(".opencodeeditor").click((value) => {
66+
userjs.setProject(value);
67+
userjs.startTensorboard(globaljs.projectDetails.name);
68+
loadPage("codeeditor/codeeditor.html", ()=>{
69+
codeeditorjs.init();
70+
codeeditorTrainButton();
71+
codeeditorBackButton();
72+
codeeditorSaveButton();
73+
});
74+
});
75+
76+
$(".opennodeeditor").click((value) => {
77+
userjs.setProject(value);
78+
loadPage("nodeeditor/nodeeditor.html", ()=>{
79+
nodeeditorjs.init();
80+
nodeeditorGenerateCodeButton();
81+
});
82+
});
83+
}
84+
85+
86+
function nodeeditorGenerateCodeButton(){
87+
$("#nodeeditor-train-button").click(()=> {
88+
nodeeditorjs.generateCode();
89+
loadPage("codeeditor/codeeditor.html", ()=>{
90+
codeeditorjs.init();
91+
codeeditorTrainButton();
92+
codeeditorBackButton();
93+
codeeditorSaveButton();
94+
});
95+
});
96+
}
97+
98+
function trainingBackButton(){
99+
$("#training-back-button").click(()=> {
100+
if (trainingjs.pythonclosed) {
101+
swal("Info", "Model training is in progress. Stop the training or let it finish to go back!", "info");
102+
} else {
103+
loadPage("codeeditor/codeeditor.html", ()=>{
104+
codeeditorjs.init();
105+
codeeditorTrainButton();
106+
codeeditorBackButton();
107+
codeeditorSaveButton();
108+
});
109+
}
110+
});
111+
}
112+
113+
function codeeditorTrainButton(){
114+
$("#codeeditor-train-button").click(() =>{
115+
codeeditorjs.saveProject(false);
116+
loadPage("training/training.html", ()=>{
117+
trainingjs.init();
118+
trainingBackButton();
119+
});
120+
});
121+
}
122+
123+
function codeeditorSaveButton(){
124+
$("#codeeditor-save-project-button").click(()=> {
125+
codeeditorjs.saveProject(true);
126+
});
127+
}
128+
129+
function codeeditorBackButton(){
130+
$("#codeeditor-back-button").click(()=> {
131+
init();
132+
});
133+
}
134+
135+
function init(){
136+
userjs.killTensorboard();
137+
loadPage("user/user.html", ()=>{
138+
userjs.init();
139+
userjs.loadProjects();
140+
userSettingsButton();
141+
userProjectButtons();
142+
});
5143
}
6144

7-
// load initial page
8145
$(document).ready(() => {
9-
loadPage("user/user.html");
146+
init();
10147
});

0 commit comments

Comments
 (0)