Skip to content

Commit

Permalink
Add: in useage
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghanbing committed Feb 28, 2018
1 parent 09c1786 commit 94341f6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
4 changes: 4 additions & 0 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ export function get_label_from_path(path) {

export function get_label_from_final_data(data, index) {
return data[index].label;
}

export function get_use_from_final_data(data, index) {
return data[index].use;
}
3 changes: 2 additions & 1 deletion src/component/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class FileList extends Component {
}

render() {
console.log("table", this.props);
let render_file_list = (
<Paper className="paper">
<Typography align="center" variant="title" className="fileListTitle">
Expand All @@ -40,6 +39,7 @@ class FileList extends Component {
<TableCell>ID</TableCell>
<TableCell>Filename</TableCell>
<TableCell>Label</TableCell>
<TableCell>In-Use</TableCell>
</TableRow>
</TableHead>
<TableBody>
Expand All @@ -49,6 +49,7 @@ class FileList extends Component {
<TableCell>{n.id}</TableCell>
<TableCell>{n.path}</TableCell>
<TableCell>{n.label}</TableCell>
<TableCell>{n.use}</TableCell>
</TableRow>
);
})}
Expand Down
28 changes: 21 additions & 7 deletions src/component/imageviewer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import React, {Component} from 'react';
import {withStyles} from 'material-ui/styles';
import Paper from 'material-ui/Paper';
import Typography from 'material-ui/Typography';
import TextField from 'material-ui/TextField';
import {get_filename_from_path, get_label_from_path, get_label_from_final_data} from '../common';
import Button from 'material-ui/Button';
import Switch from 'material-ui/Switch';
import TextField from 'material-ui/TextField';
import Typography from 'material-ui/Typography';

import {withStyles} from 'material-ui/styles';
import {
get_filename_from_path,
get_label_from_final_data,
get_use_from_final_data
} from '../common';

const styles = {
card: {
Expand All @@ -18,17 +24,16 @@ const styles = {
class ImageViewer extends Component {
constructor(props) {
super(props);
console.log('init', this.state, this.props);
this.state = {
current_index: this.props.current_index,
current_label: undefined
};
this.handleChange = this.handleChange.bind(this);
this.handleClick = this.handleClick.bind(this);
this.handleSwitch = this.handleSwitch.bind(this);
}

componentDidMount() {
console.log('did mount', this.state, this.props);
this.setState({
current_index: this.props.current_index,
current_label: undefined
Expand All @@ -39,8 +44,11 @@ class ImageViewer extends Component {
this.setState({current_label: event.target.value});
}

handleSwitch(event, checked) {
this.props.handleSwitchChange(checked, this.props.current_index);
}

handleClick() {
console.log(this.state, this.props);
this.props.handleLabelChange(this.state.current_label, this.props.current_index);
}

Expand Down Expand Up @@ -80,6 +88,12 @@ class ImageViewer extends Component {
onClick={this.handleClick}>
Correct
</Button>
<Switch onChange={this.handleSwitch}
defaultChecked={1 === get_use_from_final_data(this.props.final_data, this.props.current_index)}
key={1 === get_use_from_final_data(this.props.final_data, this.props.current_index)}
label="In-Use"
color="primary">
</Switch>
</Paper>
);
}
Expand Down
31 changes: 19 additions & 12 deletions src/mainview.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MainView extends Component {

this.listener = this.listener.bind(this);
this.labelChange = this.labelChange.bind(this);
this.switchChange = this.switchChange.bind(this);
ipcRenderer.on('action', this.listener);
}

Expand All @@ -45,7 +46,7 @@ class MainView extends Component {
if (files) {
let final_data = [];
for (let i = 0; i < files.length; i++) {
final_data.push({id: i, path: files[i], label: get_label_from_path(files[i])})
final_data.push({id: i, path: files[i], use: 1, label: get_label_from_path(files[i])})
}
this.setState({final_data: final_data, current_index: 0});
document.title = "Labeling Tool - loaded new image files";
Expand All @@ -64,11 +65,17 @@ class MainView extends Component {
});
if (ljson_file) {
let json_info = JSON.parse(MainView.readText(ljson_file[0]));
console.log(json_info);
this.current_file = ljson_file[0];

let current_index = json_info.meta.current_index;

if (json_info.data[0].use === undefined) {
json_info.data.map((t) => {
t.use = 1;
return t
});
}

this.setState({final_data: json_info.data, current_index: current_index});
document.title = "Labeling Tool - " + ljson_file;
}
Expand All @@ -82,43 +89,36 @@ class MainView extends Component {
if (this.state.final_data.length !== 0 && this.state.current_index - 1 >= 0) {
this.setState({current_index: this.state.current_index - 1})
}
console.log("prev", this.state);
break;
case 'prev10':
if (this.state.final_data.length !== 0 && this.state.current_index - 10 >= 0) {
this.setState({current_index: this.state.current_index - 10})
}
console.log("prev", this.state);
break;
case 'prev100':
if (this.state.final_data.length !== 0 && this.state.current_index - 100 >= 0) {
this.setState({current_index: this.state.current_index - 100})
}
console.log("prev", this.state);
break;
case 'next':
if (this.state.final_data.length !== 0 && this.state.current_index + 1 < this.state.final_data.length) {
this.setState({current_index: this.state.current_index + 1})
}
console.log("next", this.state);
break;
case 'next10':
if (this.state.final_data.length !== 0 && this.state.current_index + 10 < this.state.final_data.length) {
this.setState({current_index: this.state.current_index + 10})
}
console.log("next", this.state);
break;
case 'next100':
if (this.state.final_data.length !== 0 && this.state.current_index + 100 < this.state.final_data.length) {
this.setState({current_index: this.state.current_index + 100})
}
console.log("next", this.state);
break;
case 'correct':
if (this.state.final_data.length !== 0 && this.state.current_index + 1 < this.state.final_data.length) {
this.setState({current_index: this.state.current_index + 1})
}
console.log("correct", this.state);
break;
case 'exiting':
this.askSaveIfNeed();
Expand Down Expand Up @@ -149,7 +149,6 @@ class MainView extends Component {
}

saveCurrentDoc() {
console.log(this.current_file);
if (this.current_file === undefined) {
const file = remote.dialog.showSaveDialog(remote.getCurrentWindow(), {
filters: [
Expand All @@ -163,7 +162,6 @@ class MainView extends Component {
meta: {"current_index": this.state.current_index},
data: this.state.final_data
});
console.log(save_data);
MainView.saveText(save_data, this.current_file);
self.isSaved = true;
document.title = "Labeling - " + this.current_file;
Expand All @@ -178,6 +176,14 @@ class MainView extends Component {
}
}

switchChange(new_switch, index) {
if (new_switch !== undefined) {
let final_data_copy = this.state.final_data;
final_data_copy[index].use = new_switch ? 1 : 0;
this.setState({final_data: final_data_copy});
}
}

render() {
return (
<Grid container className="root">
Expand All @@ -190,7 +196,8 @@ class MainView extends Component {
<Grid item xs={12}>
<ImageViewer final_data={this.state.final_data}
current_index={this.state.current_index}
handleLabelChange={this.labelChange}/>
handleLabelChange={this.labelChange}
handleSwitchChange={this.switchChange}/>
</Grid>
</Grid>
</Grid>
Expand Down

0 comments on commit 94341f6

Please sign in to comment.