added auto-populate and pop-up dialogs

This commit is contained in:
Xiang Zhang 2018-11-13 15:23:17 -08:00
Родитель b7dd3e1f3f
Коммит 225708d5b2
5 изменённых файлов: 40 добавлений и 12 удалений

Просмотреть файл

@ -9,6 +9,7 @@ let mainWindow;
let aboutWindow;
log.transports.file.level = 'info'
log.transports.console.level = 'info'
if(require('electron-squirrel-startup'))
{

Просмотреть файл

@ -114,7 +114,7 @@ async function onSave() {
}
}
async function onOpen() {
export async function onOpen() {
const files = await showOpenDialog([
{ name: 'ONNX Model', extensions: [ 'onnx', 'pb' ] },
{ name: 'Keras Model', extensions: [ 'h5', 'json', 'keras' ] },

Просмотреть файл

@ -67,6 +67,16 @@ class ConvertView extends React.Component<IComponentProperties, IComponentState>
log.info("Convert view is created.");
}
public UNSAFE_componentWillReceiveProps(nextProps: IComponentProperties){
if(nextProps.file && nextProps.file.path) {
if(!nextProps.file.path.endsWith(".onnx")) {
this.setState({source: nextProps.file.path})
}
else {
this.setState({source: ''})
}
}
}
public render() {
const collabsibleRef: React.RefObject<Collapsible> = React.createRef();
return (
@ -184,7 +194,7 @@ class ConvertView extends React.Component<IComponentProperties, IComponentState>
return (
<div>
<div className='DisplayFlex ModelConvertBrowser'>
<TextField id='modelToConvert' placeholder='Path' value={this.state.source || this.props.file && this.props.file.path} label='Model to convert' onChanged={this.setSource} />
<TextField id='modelToConvert' placeholder='Path' value={this.state.source} label='Model to convert' onChanged={this.setSource} />
<DefaultButton id='ConverterModelInputBrowse' text='Browse' onClick={this.browseSource}/>
</div>
<div className='Frameworks'>
@ -238,6 +248,10 @@ class ConvertView extends React.Component<IComponentProperties, IComponentState>
if (!framework) {
return;
}
const convertDialogOptions = {
message: '',
title: 'convert result',
}
log.info("start to convert " + this.state.source);
this.setState({ currentStep: Step.Converting });
@ -245,12 +259,16 @@ class ConvertView extends React.Component<IComponentProperties, IComponentState>
await python([packagedFile('convert.py'), source, framework, destination], {}, this.outputListener);
} catch (e) {
log.info("Conversion of " + this.state.source + " failed.");
convertDialogOptions.message = 'convert failed!'
require('electron').remote.dialog.showMessageBox(convertDialogOptions)
this.printError(e);
return;
}
// Convert successfully
log.info(this.state.source + " is converted successfully.");
convertDialogOptions.message = 'convert successfully!'
require('electron').remote.dialog.showMessageBox(convertDialogOptions)
this.setState({ currentStep: Step.Idle, source: undefined, console:"convert successfully!!"});
// TODO Show dialog (https://developer.microsoft.com/en-us/fabric#/components/dialog) asking whether we should open the converted model
this.props.setFile(fileFromPath(destination));

Просмотреть файл

@ -46,7 +46,6 @@ interface IComponentState {
showPerf: boolean,
}
class RunView extends React.Component<IComponentProperties, IComponentState> {
private lastFile = '';
constructor(props: IComponentProperties) {
super(props);
this.state = {
@ -61,7 +60,16 @@ class RunView extends React.Component<IComponentProperties, IComponentState> {
}
log.info("Run view is created.");
}
public UNSAFE_componentWillReceiveProps(nextProps: IComponentProperties) {
if(nextProps.file.path && nextProps.file.path) {
if(!nextProps.file.path.endsWith(".onnx")){
return;
}
if(!(this.props.file && this.props.file.path) || this.props.file.path !== nextProps.file.path){
this.setState({model: nextProps.file.path}, () => {this.setParameters()})
}
}
}
public render() {
const collabsibleRef: React.RefObject<Collapsible> = React.createRef();
return (
@ -121,12 +129,6 @@ class RunView extends React.Component<IComponentProperties, IComponentState> {
{ value: 'GPUHighPerformance', label: 'GPUHighPerformance' },
{ value: "GPUMinPower", label: 'GPUMinPower' }
];
if(this.props.file && this.props.file.path && this.props.file.path !== this.lastFile) {
this.lastFile = this.props.file.path;
this.setState({model: this.props.file.path}, () => {this.setParameters()})
}
return (
<div className="Arguments">
<div className='DisplayFlex ModelPath'>
@ -263,7 +265,10 @@ class RunView extends React.Component<IComponentProperties, IComponentState> {
console: '',
currentStep: Step.Running,
});
// const paramters = ['-model', this.state.model];
const runDialogOptions = {
message: '',
title: 'run result',
}
try {
await execFilePromise(modelRunnerPath, this.state.parameters, {}, this.outputListener);
} catch (e) {
@ -272,11 +277,15 @@ class RunView extends React.Component<IComponentProperties, IComponentState> {
this.setState({
currentStep: Step.Idle,
});
runDialogOptions.message = 'run failed!'
require('electron').remote.dialog.showMessageBox(runDialogOptions)
return;
}
this.setState({
currentStep: Step.Success,
});
runDialogOptions.message = 'run successfully';
require('electron').remote.dialog.showMessageBox(runDialogOptions)
log.info(this.state.model + " run successfully");
}
}

Просмотреть файл

@ -14,7 +14,7 @@ var app = new Application({
})
describe("WinMLDashboard Tests", function () {
this.timeout(200000);
this.timeout(2000000);
// CSS selectors
const openModelButton = '#open-file-button';