forked from agermanidis/livepython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainView.js
More file actions
113 lines (101 loc) · 3.05 KB
/
Copy pathMainView.js
File metadata and controls
113 lines (101 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import React, { Component } from 'react'
import { ipcRenderer } from 'electron'
import jq from 'jquery'
import mousetrap from 'mousetrap'
import CodeView from './CodeView'
function showIndicator(name) {
jq(".status-indicator").remove();
const src = `images/${name}.png`
var $img = jq("<img>");
$img.attr("src", src);
$img.addClass("status-indicator");
jq("body").append($img);
$img.fadeOut(1000, function() {
$img.remove();
});
}
class MainView extends Component {
constructor () {
super()
this.state = {
paused: false,
state: "running",
filename: null,
function_name: null,
lineno: 0,
locals: {},
source: "",
exception: null,
time: null,
fastForward: false
}
}
componentDidUpdate () {
document.title = 'Livepython - ' + this.state.filename;
}
componentWillMount () {
ipcRenderer.send('command', {
type: 'connected'
})
ipcRenderer.on('trace', (event, data) => {
const msg = JSON.parse(data.msg)
if (msg.type === 'call') {
this.setState(Object.assign(this.state, msg))
} else if (msg.type === 'switch') {
this.setState(Object.assign(this.state, msg));
} else if (msg.type === 'finish') {
this.setState({state: 'finished'})
} else if (msg.type === 'exception') {
this.setState({
state: 'failed',
exception: {
message: msg.exception_message,
type: msg.exception_type,
lineno: msg.lineno
}
})
}
})
mousetrap.bind("space", (evt) => {
const {paused} = this.state;
showIndicator(paused ? 'play' : 'pause');
ipcRenderer.send('command', {
type: "toggle_running_state",
value: !paused
});
this.setState({paused: !this.state.paused})
return false;
});
mousetrap.bind("right", evt => {
showIndicator('fastforward');
ipcRenderer.send('command', {
type: 'change_speed',
speed: 'fast'
});
this.setState({ fastForward: true });
return false;
});
mousetrap.bind("left", evt => {
showIndicator("play");
ipcRenderer.send('command', {
type: "change_speed",
speed: "slow"
});
this.setState({ fastForward: false });
return false;
});
mousetrap.bind("v", evt => {
ipcRenderer.send("toggle_variable_inspector");
return false;
});
}
render () {
if (!this.state.source) return <p>Loading</p>
return (
<div>
<CodeView {...this.state} />
</div>
)
}
}
export default MainView