Commit dbb41f14 authored by LIGNEUL CLEMENT's avatar LIGNEUL CLEMENT
Browse files

add help + improve error windows

parent fd3082d9
......@@ -12,7 +12,8 @@
"update-modules": "ncu -u && npm install"
},
"dependencies": {
"@nodegui/nodegui": "^0.31.0"
"@nodegui/nodegui": "^0.31.0",
"opn": "^6.0.0"
},
"devDependencies": {
"@nodegui/packer": "^1.4.1",
......
import { QTabWidget, QIcon, QMainWindow, QWidget, WidgetEventTypes } from '@nodegui/nodegui';
import { ChildProcess } from 'child_process';
import { QTabWidget, QIcon, QMainWindow, QWidget, WidgetEventTypes, QMenu, QSystemTrayIconActivationReason } from '@nodegui/nodegui';
import { spawn, ChildProcess } from 'child_process';
import { Compile } from './compile_tab';
import { general_css } from './style';
import { Run_tab } from './run_tab';
......@@ -8,6 +8,7 @@ import { QMenuBar, QAction, QGridLayout } from "@nodegui/nodegui";
import { Plot_result } from './plot_tab';
import fs from 'fs';
import { exit } from 'process';
import { EventWidget } from '@nodegui/nodegui/dist/lib/core/EventWidget';
// array of running child processes
export let running_proc: ChildProcess[] = [];
......@@ -25,13 +26,30 @@ const general_layout = new QGridLayout();
centralWidget.setLayout(general_layout);
// top menu
// const menu = new QMenuBar();
// const action = new QAction();
// action.setText('Du blabla');
// menu.addAction(action);
// global_win.setMenuBar(menu);
// menu
const main_menu = new QMenuBar();
const sub_menu = new QMenu();
sub_menu.setTitle('Help');
const help_action = new QAction();
help_action.setText('Instruction manual')
help_action.addEventListener('triggered', ()=>{
spawn('sensible-browser', ['https://git.unistra.fr/ligneul/easea-compiler-app'], {detached:true});
});
const EASEA_action = new QAction();
EASEA_action.setText('EASEA website');
EASEA_action.addEventListener('triggered', ()=>{
spawn('sensible-browser', ['http://easea.unistra.fr/index.php/EASEA_platform'], {detached:true});
});
sub_menu.addAction(help_action);
sub_menu.addAction(EASEA_action);
main_menu.addMenu(sub_menu);
global_win.setMenuBar(main_menu);
// objects
const compile = new QWidget();
export const compile_obj = new Compile('', '');
compile.setLayout(compile_obj.generate_compile_tab());
......
import { AcceptMode, AlignmentFlag, FileMode, QBoxLayout, QFileDialog, QGridLayout, QLabel, QPixmap, QPushButton, QScrollArea, QTextEdit, QWidget, TransformationMode, WidgetEventTypes } from "@nodegui/nodegui";
import fs, { existsSync } from 'fs';
import { exec, execSync, spawnSync, spawn, ChildProcess } from "child_process";
import * as util from './utilities';
import { running_plot, running_proc } from "./index";
import { run_obj } from './index'
import { Win_alert } from "./win_alert";
export class Plot_result{
widget: QWidget;
layout: QGridLayout;
image_path: string;
image: QPixmap;
image_label: QLabel;
btn_widget: QWidget; //widget with save buttons
save_static_btn: QPushButton;
save_interactive_btn: QPushButton;
scroll_image: QScrollArea;
constructor(){
this.widget = new QWidget();
this.layout = new QGridLayout();
this.image_path = '';
this.image = new QPixmap();
this.image_label = new QLabel();
this.save_static_btn = new QPushButton();
this.save_interactive_btn = new QPushButton();
this.scroll_image = new QScrollArea();
this.btn_widget = new QWidget();
}
update_plot(path: string, plot_size: number){
// this.image_label.setText('');
var run: ChildProcess;
// tester l'existence du fichier
var nb_gen = run_obj.option_obj.nb_gen
var plot_path = '';
if(existsSync('src/plot.py')){
plot_path = 'src/plot.py';
} else if(existsSync('plot.py')){
plot_path = 'plot.py';
} else {
this.image_label.setText('Error : plot script not found');
return;
}
if(isNaN(nb_gen)){
var val = this.get_generations(run_obj.ez_file_address);
console.log('nb gen detected in file : ' + val);
val === -1? nb_gen = 30: nb_gen = val;
}
run = spawn('python3', [plot_path, nb_gen.toString(), plot_size.toString()] , {timeout:20000});
running_plot.push(run);
run.on('exit', (code)=>{
const index = running_plot.indexOf(run, 0);
if(index > -1){
if(running_plot.length === 1){
running_proc.pop();
} else {
running_plot.splice(index, 1);
}
}
if(code === 0){
this.image_path = path;
if(this.image.load(path)){
this.image_label.setPixmap(this.image.scaled(800,500)); // 1 keep ratio
// this.scroll_image.setWidgetResizable(false);
this.image_label.setFixedSize(800,500);
this.btn_widget.show();
} else {
this.image_label.setText('Error : graph not found');
}
} else {
this.image_label.setText('This graph can\'t be displayed');
}
if(running_plot.length === 0){
run_obj.running_label.hide();
}
});
}
get_generations(filename: string): number{
var text_file = fs.readFileSync(filename, 'utf-8');
var lines = text_file.split('\n');
for(var i = 0; i < lines.length; i++){
// remove all spaces at the beginning
while(lines[i][0] === ' ' || lines[i][0] === '\t')
lines[i] = lines[i].substring(1, lines[i].length);
var col = lines[i].split(' ');
if (col[0].toLowerCase() === 'number' && col[1].toLowerCase() === 'of'){
if (col[2].toLowerCase() === 'generations:'){
return Number(col[3]);
} else if (col[2].toLowerCase() === 'generations'){
return Number(col[4]);
}
}
}
return -1;
}
generate(){
this.widget.setLayout(this.layout);
// save btns
const btn_layout = new QBoxLayout(0);
this.btn_widget.setLayout(btn_layout);
this.save_static_btn.setText('Save static plot')
this.save_static_btn.setFixedSize(130,30);
this.save_static_btn.addEventListener('clicked', ()=> {
const fileDialog = new QFileDialog();
fileDialog.setNameFilter('*.svg');
fileDialog.setAcceptMode(AcceptMode.AcceptSave);
if(fileDialog.exec()){
var path_file = fileDialog.selectedFiles().toString();
if(!path_file.endsWith('.svg'))
path_file = path_file + '.svg';
try{
fs.copyFileSync('plotting/fig.svg', path_file);
} catch(e){
if(e){
new Win_alert(e, 'Save Static Plot');
}
}
}
});
this.save_interactive_btn.setText('Save interactive plot')
this.save_interactive_btn.setFixedSize(150,30);
this.save_interactive_btn.addEventListener('clicked', ()=> {
const fileDialog = new QFileDialog();
fileDialog.setNameFilter('*.html');
fileDialog.setAcceptMode(AcceptMode.AcceptSave);
if(fileDialog.exec()){
var path_file = fileDialog.selectedFiles().toString();
try{
if(!path_file.endsWith('.html'))
path_file = path_file + '.html';
fs.copyFileSync('plotting/fig.html', path_file);
} catch(e){
if(e){
new Win_alert(e, 'Save Interactive Plot');
}
}
}
});
btn_layout.addWidget(this.save_static_btn);
btn_layout.addWidget(this.save_interactive_btn);
this.btn_widget.hide();
// graph
// this.image.load(this.image_path);
this.image_label.setPixmap(this.image);
this.image_label.setText('No graph to display');
this.image_label.addEventListener(WidgetEventTypes.MouseButtonDblClick, ()=>{
spawn('open', ['plotting/fig.html'], {detached:true});
})
this.scroll_image.setWidget(this.image_label);
this.scroll_image.setAlignment(AlignmentFlag.AlignCenter);
this.layout.addWidget(this.scroll_image,0,0);
this.layout.addWidget(this.btn_widget,1,0);
// this.layout.addStretch();
return this.layout;
}
import { AcceptMode, AlignmentFlag, FileMode, QBoxLayout, QFileDialog, QGridLayout, QLabel, QPixmap, QPushButton, QScrollArea, QTextEdit, QWidget, TransformationMode, WidgetEventTypes } from "@nodegui/nodegui";
import fs, { existsSync } from 'fs';
import { exec, execSync, spawnSync, spawn, ChildProcess } from "child_process";
import * as util from './utilities';
import { running_plot, running_proc } from "./index";
import { run_obj } from './index'
import { Win_alert } from "./win_alert";
export class Plot_result {
widget: QWidget;
layout: QGridLayout;
image_path: string;
image: QPixmap;
image_label: QLabel;
btn_widget: QWidget; //widget with save buttons
save_static_btn: QPushButton;
save_interactive_btn: QPushButton;
scroll_image: QScrollArea;
constructor() {
this.widget = new QWidget();
this.layout = new QGridLayout();
this.image_path = '';
this.image = new QPixmap();
this.image_label = new QLabel();
this.save_static_btn = new QPushButton();
this.save_interactive_btn = new QPushButton();
this.scroll_image = new QScrollArea();
this.btn_widget = new QWidget();
}
update_plot(path: string, plot_size: number) {
var run: ChildProcess;
// tester l'existence du fichier
var nb_gen = run_obj.option_obj.nb_gen
var plot_path = '';
if (existsSync('src/plot.py')) {
plot_path = 'src/plot.py';
} else if (existsSync('plot.py')) {
plot_path = 'plot.py';
} else {
this.image_label.setText('Error : plot script not found');
return;
}
if (isNaN(nb_gen)) {
var val = this.get_generations(run_obj.ez_file_address);
console.log('nb gen detected in file : ' + val);
val === -1 ? nb_gen = 30 : nb_gen = val;
}
run = spawn('python3', [plot_path, nb_gen.toString(), plot_size.toString()], { timeout: 20000 });
running_plot.push(run);
run.on('exit', (code) => {
const index = running_plot.indexOf(run, 0);
if (index > -1) {
if (running_plot.length === 1) {
running_proc.pop();
} else {
running_plot.splice(index, 1);
}
}
if (code === 0) {
this.image_path = path;
if (this.image.load(path)) {
this.image_label.setPixmap(this.image.scaled(800, 500));
this.image_label.setFixedSize(800, 500);
this.btn_widget.show();
} else {
this.image_label.setText('Error : graph not found');
}
} else {
this.image_label.setText('This graph can\'t be displayed');
}
if (running_plot.length === 0) {
run_obj.running_label.hide();
}
});
}
get_generations(filename: string): number {
var text_file = fs.readFileSync(filename, 'utf-8');
var lines = text_file.split('\n');
for (var i = 0; i < lines.length; i++) {
// remove all spaces at the beginning
while (lines[i][0] === ' ' || lines[i][0] === '\t')
lines[i] = lines[i].substring(1, lines[i].length);
var col = lines[i].split(' ');
if (col[0].toLowerCase() === 'number' && col[1].toLowerCase() === 'of') {
if (col[2].toLowerCase() === 'generations:') {
return Number(col[3]);
} else if (col[2].toLowerCase() === 'generations') {
return Number(col[4]);
}
}
}
return -1;
}
generate() {
this.widget.setLayout(this.layout);
// save btns
const btn_layout = new QBoxLayout(0);
this.btn_widget.setLayout(btn_layout);
this.save_static_btn.setText('Save static plot');
this.save_static_btn.setFixedSize(130, 30);
this.save_static_btn.addEventListener('clicked', () => {
const fileDialog = new QFileDialog();
fileDialog.setNameFilter('*.svg');
fileDialog.setAcceptMode(AcceptMode.AcceptSave);
if (fileDialog.exec()) {
var path_file = fileDialog.selectedFiles().toString();
if (!path_file.endsWith('.svg'))
path_file += '.svg';
try {
fs.copyFileSync('plotting/fig.svg', path_file);
} catch (e) {
if(e)
new Win_alert(e, 'Save Static Plot');
return;
}
new Win_alert('Plot Saved', 'Save Static Plot');
}
});
this.save_interactive_btn.setText('Save interactive plot')
this.save_interactive_btn.setFixedSize(150, 30);
this.save_interactive_btn.addEventListener('clicked', () => {
const fileDialog = new QFileDialog();
fileDialog.setNameFilter('*.html');
fileDialog.setAcceptMode(AcceptMode.AcceptSave);
if (fileDialog.exec()) {
var path_file = fileDialog.selectedFiles().toString();
try {
if (!path_file.endsWith('.html'))
path_file += '.html';
fs.copyFileSync('plotting/fig.html', path_file);
} catch (e) {
if(e)
new Win_alert(e, 'Save Interactive Plot');
return;
}
new Win_alert('Plot Saved', 'Save Interactive Plot');
}
});
btn_layout.addWidget(this.save_static_btn);
btn_layout.addWidget(this.save_interactive_btn);
this.btn_widget.hide();
// graph
// this.image.load(this.image_path);
this.image_label.setPixmap(this.image);
this.image_label.setText('No graph to display');
this.image_label.addEventListener(WidgetEventTypes.MouseButtonDblClick, () => {
spawn('sensible-browser', ['plotting/fig.html']);
})
this.scroll_image.setWidget(this.image_label);
this.scroll_image.setAlignment(AlignmentFlag.AlignCenter);
this.layout.addWidget(this.scroll_image, 0, 0);
this.layout.addWidget(this.btn_widget, 1, 0);
// this.layout.addStretch();
return this.layout;
}
}
\ No newline at end of file
import { QDialog, QBoxLayout, QLabel, QPushButton, FlexLayout, AlignmentFlag, QWidget, QGridLayout } from '@nodegui/nodegui';
import { QDialog, QBoxLayout, QLabel, QPushButton, FlexLayout, AlignmentFlag, QWidget, QGridLayout, WindowType } from '@nodegui/nodegui';
export class Win_alert {
message: string;
......@@ -9,6 +9,8 @@ export class Win_alert {
this.window = new QDialog();
this.window.setObjectName("window");
this.window.setWindowFlag(WindowType.CustomizeWindowHint, true);
this.window.setWindowFlag(WindowType.WindowCloseButtonHint, false);
if(window_name){
this.window.setWindowTitle(window_name);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment