Commit 0062ce8d authored by LIGNEUL CLEMENT's avatar LIGNEUL CLEMENT
Browse files

clean code

parent d61263cc
......@@ -15,7 +15,7 @@ all:
@echo "\n##### Copie du script de graphe #####\n"
find 'deploy/' -type d -name doc | sed 's/doc//' | xargs -n 1 cp -v src/plot.py
find 'deploy/' -type d -name doc | sed 's/doc//' | xargs -n 1 cp -v src/scripts/plot.py
@echo "\n##### Packaging terminé #####\n"
......
declare module "*.svg";
declare module "*.png";
declare module "*.jpg";
declare module "*.jpeg";
declare module "*.gif";
declare module "*.bmp";
import { QBoxLayout, QLabel, QLineEdit, QWidget } from "@nodegui/nodegui";
export class Advanced_option_widget{
label_text: string;
label: QLabel;
place_holder: string;
widget: QWidget;
layout: QBoxLayout;
text_edit: QLineEdit;
constructor(txt: string, alignement: number, place_hold?: string){
this.text_edit = new QLineEdit();
this.text_edit.setFixedSize(95,30);
this.label_text = txt;
this.label = new QLabel();
this.label.setText(this.label_text);
// this.label.setMaximumSize(150, 80);
this.widget = new QWidget();
this.layout = new QBoxLayout(alignement);
this.widget.setLayout(this.layout);
if(place_hold){
this.place_holder = place_hold;
} else {
this.place_holder = 'Default';
}
this.text_edit.setPlaceholderText(this.place_holder);
this.layout.addWidget(this.label);
this.layout.addWidget(this.text_edit);
this.widget.setMaximumSize(310, 100);
}
import { QBoxLayout, QLabel, QLineEdit, QWidget } from "@nodegui/nodegui";
import { exit } from "process";
export class Advanced_option_widget {
label_text: string;
label: QLabel;
place_holder: string;
widget: QWidget;
layout: QBoxLayout;
text_edit: QLineEdit;
constructor(txt: string, alignement: number, place_hold?: string) {
if (alignement < 0 || alignement > 3) {
console.log('bad parameters for advanced widget');
exit(1);
}
this.text_edit = new QLineEdit();
this.text_edit.setFixedSize(95, 30);
this.label_text = txt;
this.label = new QLabel();
this.label.setText(this.label_text);
this.widget = new QWidget();
this.layout = new QBoxLayout(alignement);
this.widget.setLayout(this.layout);
place_hold ? this.place_holder = place_hold : this.place_holder = 'Default';
this.text_edit.setPlaceholderText(this.place_holder);
this.layout.addWidget(this.label);
this.layout.addWidget(this.text_edit);
this.widget.setMaximumSize(310, 100);
}
}
\ No newline at end of file
const { QLabel, QFileDialog, QComboBox, QGridLayout, QPushButton, QBoxLayout } = require("@nodegui/nodegui");
import { Pseudo_term } from './pseudo_term';
import { Win_alert } from './win_alert';
import { run_obj } from './index';
import * as util from './utilities';
import { FileMode, QCheckBox, QWidget } from '@nodegui/nodegui';
import { FileMode, QCheckBox, QWidget, QLabel, QFileDialog, QGridLayout, QPushButton, QBoxLayout } from '@nodegui/nodegui';
export class Compile {
ez_file_address: string;
......@@ -35,7 +35,11 @@ export class Compile {
var global_layout = new QBoxLayout(2);
// output terminal
const widget_console = new QWidget();
const centered_console = new QGridLayout();
const output_compile = new Pseudo_term('Output :');
centered_console.addWidget(output_compile.window, 0, 0);
widget_console.setLayout(centered_console);
// grid of options
const option_layout = new QGridLayout();
......@@ -136,7 +140,7 @@ export class Compile {
option_layout.addWidget(check_cuda, 2, 3);
option_layout.addWidget(check_cuda_gp, 2, 4);
}
option_layout.addWidget(misc_label, 3, 0);
option_layout.addWidget(check_v, 4, 0);
option_layout.addWidget(check_tl, 4, 1);
......@@ -146,7 +150,7 @@ export class Compile {
// compile button
const compile_btn = new QPushButton();
compile_btn.setText("Compile");
compile_btn.setFixedSize(120,30);
compile_btn.setFixedSize(120, 30);
compile_btn.addEventListener('clicked', () => {
if (this.ez_file_address === '') {
new Win_alert("Please load a file");
......@@ -210,7 +214,6 @@ export class Compile {
});
run.on('exit', (code) => {
// console.log("exit " + code);
if (code === 0) {
output_compile.text.insertPlainText('\n');
var make = output_compile.compile('make', ['-f', ez_makefile], dir_path);
......@@ -243,7 +246,7 @@ export class Compile {
// make clean button
const make_clean_btn = new QPushButton();
make_clean_btn.setText("Make clean");
make_clean_btn.setFixedSize(120,30);
make_clean_btn.setFixedSize(120, 30);
make_clean_btn.addEventListener('clicked', () => {
if (this.ez_file_address === '') {
new Win_alert("Please load a file");
......@@ -262,7 +265,7 @@ export class Compile {
});
}
})
});
const label_loaded = new QLabel();
label_loaded.setText("File loaded : ");
......@@ -272,7 +275,7 @@ export class Compile {
// load file dialog
const file_select = new QPushButton();
file_select.setText("Load a file");
file_select.setFixedSize(120,30);
file_select.setFixedSize(120, 30);
file_select.addEventListener('clicked', () => {
const fileDialog = new QFileDialog();
fileDialog.setFileMode(FileMode.ExistingFile);
......@@ -316,7 +319,7 @@ export class Compile {
global_layout.addWidget(file_select);
global_layout.addWidget(option_widget);
global_layout.addWidget(widget_comp);
global_layout.addWidget(output_compile.window);
global_layout.addWidget(widget_console);
return global_layout;
}
......
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';
import * as util from './utilities';
import { QMenuBar, QAction, QGridLayout } from "@nodegui/nodegui";
import { Plot_result } from './plot_tab';
import fs from 'fs';
import os from 'os';
import { exit } from 'process';
// array of running child processes
export let running_proc: ChildProcess[] = [];
export let running_plot: ChildProcess[] = [];
// main window
const global_win = new QMainWindow();
global_win.setWindowTitle("EASEA Compiler");
// main widget
const centralWidget = new QWidget();
const general_layout = new QGridLayout();
centralWidget.setLayout(general_layout);
// menu
const main_menu = new QMenuBar();
const sub_menu = new QMenu();
sub_menu.setTitle('Help');
const help_action = new QAction();
help_action.setText('Documentation')
help_action.addEventListener('triggered', ()=>{
if(os.type() === 'Linux'){
spawn('sensible-browser', ['https://git.unistra.fr/ligneul/easea-compiler-app'], {detached:true});
} else if (os.type() === 'Darwin'){
spawn('open', ['https://git.unistra.fr/ligneul/easea-compiler-app'], {detached:true});
}
});
const EASEA_action = new QAction();
EASEA_action.setText('EASEA website');
EASEA_action.addEventListener('triggered', ()=>{
if(os.type() === 'Linux'){
spawn('sensible-browser', ['http://easea.unistra.fr/index.php/EASEA_platform'], {detached:true});
} else if (os.type() === 'Darwin'){
spawn('open', ['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());
const run = new QWidget();
export const run_obj = new Run_tab('', '');
run.setLayout(run_obj.generate());
const plot = new QWidget();
export const plot_obj = new Plot_result();
plot.setLayout(plot_obj.generate());
export const tab_menu = new QTabWidget();
tab_menu.addTab(compile, new QIcon(), 'Compile');
tab_menu.addTab(run, new QIcon(), 'Run');
tab_menu.addTab(plot, new QIcon(), 'Result Plot')
general_layout.addWidget(tab_menu);
global_win.setCentralWidget(centralWidget);
global_win.setLayout(general_layout);
global_win.setStyleSheet(general_css);
// global_win.setFixedSize(1300, 800);
// call at the end
global_win.addEventListener(WidgetEventTypes.Close, () => {
// console.log("On kill tout ici");
util.kill_all(running_proc);
fs.rmSync('./plotting', {recursive:true, force:true});
});
global_win.adjustSize();
global_win.setFixedSize(global_win.size().width(), global_win.size().height());
fs.mkdir('plotting/', (err)=>{
if(err && err.code !== 'EEXIST'){
console.log(err.message);
console.log(err);
exit(1);
}
});
global_win.show();
(global as any).global_win = global_win;
import { QTabWidget, QIcon, QMainWindow, QWidget, WidgetEventTypes, QMenu } 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';
import * as util from './utilities';
import { QMenuBar, QAction, QGridLayout } from "@nodegui/nodegui";
import { Plot_result } from './plot_tab';
import fs from 'fs';
import os from 'os';
import { exit } from 'process';
// arrays of running child processes
export let running_proc: ChildProcess[] = [];
export let running_plot: ChildProcess[] = [];
// main window
const global_win = new QMainWindow();
global_win.setWindowTitle("EASEA Compiler");
// main widget
const centralWidget = new QWidget();
const general_layout = new QGridLayout();
centralWidget.setLayout(general_layout);
// menu
const main_menu = new QMenuBar();
const sub_menu = new QMenu();
sub_menu.setTitle('Help');
const help_action = new QAction();
help_action.setText('Documentation')
help_action.addEventListener('triggered', () => {
var command = '';
if (os.type() === 'Linux') {
command = 'sensible-browser';
} else if (os.type() === 'Darwin') {
command = 'open';
}
spawn(command, ['https://git.unistra.fr/ligneul/easea-compiler-app'], { detached: true });
});
const EASEA_action = new QAction();
EASEA_action.setText('EASEA website');
EASEA_action.addEventListener('triggered', () => {
var command = '';
if (os.type() === 'Linux') {
command = 'sensible-browser';
} else if (os.type() === 'Darwin') {
command = 'open';
}
spawn(command, ['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());
const run = new QWidget();
export const run_obj = new Run_tab('', '');
run.setLayout(run_obj.generate());
const plot = new QWidget();
export const plot_obj = new Plot_result();
plot.setLayout(plot_obj.generate());
export const tab_menu = new QTabWidget();
tab_menu.addTab(compile, new QIcon(), 'Compile');
tab_menu.addTab(run, new QIcon(), 'Run');
tab_menu.addTab(plot, new QIcon(), 'Result Plot')
general_layout.addWidget(tab_menu);
global_win.setCentralWidget(centralWidget);
global_win.setLayout(general_layout);
global_win.setStyleSheet(general_css);
// global_win.setFixedSize(1300, 800);
// call at the end
global_win.addEventListener(WidgetEventTypes.Close, () => {
// console.log("On kill tout ici");
util.kill_all(running_proc);
fs.rmSync('./plotting', { recursive: true, force: true });
});
// global_win.adjustSize();
// global_win.setFixedSize(global_win.size().width(), global_win.size().height());
fs.mkdir('plotting/', (err) => {
if (err && err.code !== 'EEXIST') {
console.log(err.message);
console.log(err);
exit(1);
}
});
global_win.show();
(global as any).global_win = global_win;
import { Direction, QBoxLayout, QDialog, QCheckBox, QPushButton, QWidget, QLabel, QFileDialog, WindowType, FileMode } from "@nodegui/nodegui";
import { Advanced_option_widget } from "./advanced_option_widget";
import { general_css } from "./style";
import * as util from './utilities';
export class Island_options_win{
window: QDialog;
reevaluate: boolean;
ip_file: string;
migration_proba: number;
server_port: number;
constructor(){
this.window = new QDialog();
this.window.setWindowTitle('Island Model Options');
this.window.setWindowFlag(WindowType.CustomizeWindowHint, true);
this.window.setWindowFlag(WindowType.WindowCloseButtonHint, false);
this.reevaluate = false;
this.server_port = NaN;
this.migration_proba = NaN;
this.ip_file = '';
const main_layout = new QBoxLayout(Direction.TopToBottom);
const reevaluate_im = new QCheckBox();
reevaluate_im.setText('Evaluate Immigrants');
reevaluate_im.addEventListener('stateChanged', ()=>{
this.reevaluate = reevaluate_im.isChecked();
});
// à mettre dans remote island
const ip_widget = new QWidget();
const ip_layout = new QBoxLayout(Direction.LeftToRight);
ip_widget.setLayout(ip_layout);
const ip_file_btn = new QPushButton();
const file_loaded = new QLabel();
file_loaded.setText('IP file :');
ip_file_btn.setText("Load IP file");
ip_file_btn.setFixedSize(100, 25);
ip_file_btn.addEventListener('clicked', ()=> {
const fileDialog = new QFileDialog();
fileDialog.setFileMode(FileMode.ExistingFile);
if(fileDialog.exec()){
var file = fileDialog.selectedFiles().toString();
if(file){
this.ip_file = file
file_loaded.setText('IP file : ' + util.get_file_name(this.ip_file));
}
}
});
ip_layout.addWidget(file_loaded);
ip_layout.addWidget(ip_file_btn);
const proba_migration = new Advanced_option_widget('Migration Probability :', 0);
proba_migration.text_edit.addEventListener('textChanged', ()=>{
var text = proba_migration.text_edit.text();
var val = Number(text);
if(text === ''){
this.migration_proba = NaN;
return ;
}
if(!isNaN(val))
this.migration_proba = val;
});
const server_port = new Advanced_option_widget('Server Port :', 0);
server_port.text_edit.addEventListener('textChanged', ()=>{
var text = server_port.text_edit.text();
var val = Number(text);
if(text === ''){
this.server_port = NaN;
return ;
}
if(!isNaN(val))
this.server_port = val;
});
// close and save buttons
const btn_layout = new QBoxLayout(Direction.LeftToRight);
const btn_widget = new QWidget();
btn_widget.setLayout(btn_layout);
const save_btn = new QPushButton();
save_btn.setText('Save');
save_btn.addEventListener('clicked', ()=>{
var errors = [];
var ok = 1;
var proba_migr = Number(proba_migration.text_edit.text());
if(isNaN(proba_migr) || proba_migr < 0 || proba_migr > 1){
ok = 0;
errors.push('Migration Probability');
}
if(isNaN(Number(server_port.text_edit.text()))){
ok = 0;
errors.push('Server Port');
}
if(ok){
this.window.close();
} else {
util.print_errors(errors);
}
});
save_btn.setFixedSize(100, 25);
const reset_btn = new QPushButton();
reset_btn.setText('Reset');
reset_btn.addEventListener('clicked', ()=>{
file_loaded.setText('IP file :');
proba_migration.text_edit.clear();
reevaluate_im.setChecked(false);
server_port.text_edit.clear();
});
reset_btn.setFixedSize(100, 25);
btn_layout.addWidget(save_btn);
btn_layout.addWidget(reset_btn);
main_layout.addWidget(proba_migration.widget);
main_layout.addWidget(ip_widget);
main_layout.addWidget(server_port.widget);
main_layout.addWidget(reevaluate_im);
main_layout.addWidget(btn_widget);
this.window.setLayout(main_layout);
this.window.adjustSize();
this.window.setFixedSize(this.window.size().width(), this.window.size().height());
this.window.setStyleSheet(general_css);
}
execution(){
this.window.exec();
return this;
}
import { Direction, QBoxLayout, QDialog, QCheckBox, QPushButton, QWidget, QLabel, QFileDialog, WindowType, FileMode } from "@nodegui/nodegui";
import { Advanced_option_widget } from "./advanced_option_widget";
import { general_css } from "./style";
import * as util from './utilities';
export class Island_options_win {
window: QDialog;
reevaluate: boolean;
ip_file: string;
migration_proba: number;
server_port: number;
constructor() {
this.window = new QDialog();
this.window.setWindowTitle('Island Model Options');
this.window.setWindowFlag(WindowType.CustomizeWindowHint, true);
this.window.setWindowFlag(WindowType.WindowCloseButtonHint, false);
this.reevaluate = false;
this.server_port = NaN;
this.migration_proba = NaN;
this.ip_file = '';
const main_layout = new QBoxLayout(Direction.TopToBottom);
const reevaluate_im = new QCheckBox();
reevaluate_im.setText('Evaluate Immigrants');
reevaluate_im.addEventListener('stateChanged', () => {
this.reevaluate = reevaluate_im.isChecked();
});
const ip_widget = new QWidget();
const ip_layout = new QBoxLayout(Direction.LeftToRight);
ip_widget.setLayout(ip_layout);
const ip_file_btn = new QPushButton();
const file_loaded = new QLabel();
file_loaded.setText('IP file :');
ip_file_btn.setText("Load IP file");
ip_file_btn.setFixedSize(100, 25);
ip_file_btn.addEventListener('clicked', () => {
const fileDialog = new QFileDialog();
fileDialog.setFileMode(FileMode.ExistingFile);
if (fileDialog.exec()) {
var file = fileDialog.selectedFiles().toString();
if (file) {
this.ip_file = file
file_loaded.setText('IP file : ' + util.get_file_name(this.ip_file));
}
}
});
ip_layout.addWidget(file_loaded);
ip_layout.addWidget(ip_file_btn);
const proba_migration = new Advanced_option_widget('Migration Probability :', 0);