Added muted

This commit is contained in:
obscuren 2014-04-28 23:24:42 +02:00
parent c0de11955b
commit 922974c760
7 changed files with 291 additions and 177 deletions

View File

@ -4,7 +4,7 @@
<style type="text/css">
html, body {
margin: 0; padding: 0;
min-height: 100%;
min-height: 100%;
}
#debugger {

View File

@ -7,20 +7,63 @@
<script src="lib/codemirror.js"></script>
<script src="lib/matchbrackets.js"></script>
<script src="lib/go.js"></script>
<script src="muted.js"></script>
<style type="text/css">
html, body {
margin: 0; padding: 0;
min-height: 100%;
}
#debugger {
height: 30%;
font-family: "Monaco";
border-top: 5px solid grey;
}
#debugger .line {
overflow: none;
}
#debugger .col1, #debugger .col2 {
float: left;
padding: 3px;
}
#debugger .col1 {
width: 10px;
padding-left: 10px
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
#debugger .col2 {
width: 90%;
}
.prompt {
color: "#5089D4";
}
.CodeMirror {
height: 100%;
height: 70%;
font-size: 14pt;
}
</style>
</head>
<body>
<textarea id="editor"></textarea>
<div id="debugger">
<div class="line">
<div class="col1 prompt">
&gt;
</div>
<div class="col2" contenteditable>
</div>
</div>
</div>
<script>
var textArea = document.querySelector("#editor")
var editor = CodeMirror.fromTextArea(textArea, {
@ -33,6 +76,5 @@
indentWithTabs: true,
});
</script>
</body>
</html>

View File

@ -0,0 +1,61 @@
// Helper function for generating pseudo callbacks and sending data to the QML part of the application
function postData(data, cb) {
data._seed = Math.floor(Math.random() * 1000000)
if(cb) {
Muted._callbacks[data._seed] = cb;
}
if(data.args === undefined) {
data.args = [];
}
navigator.qt.postMessage(JSON.stringify(data));
}
window.Muted = {
prototype: Object(),
}
window.Muted._callbacks = {}
window.Muted._onCallbacks = {}
function debug(/**/) {
console.log("hello world")
var args = arguments;
var msg = ""
for(var i = 0; i < args.length; i++){
if(typeof args[i] == "object") {
msg += " " + JSON.stringify(args[i])
} else {
msg += args[i]
}
}
document.querySelector("#debugger").innerHTML += "<div class='line'><div class='col1'></div><div class='col2'>"+msg+"</div></div>";
}
console.log = function() {
var args = []
for(var i = 0; i < arguments.length; i++) {
args.push(arguments[i]);
}
postData({call:"log", args:args})
}
navigator.qt.onmessage = function(ev) {
var data = JSON.parse(ev.data)
if(data._event !== undefined) {
Muted.trigger(data._event, data.data);
} else {
if(data._seed) {
var cb = Muted._callbacks[data._seed];
if(cb) {
// Call the callback
cb(data.data);
// Remove the "trigger" callback
delete Muted._callbacks[ev._seed];
}
}
}
}

View File

@ -7,59 +7,68 @@ import QtQuick.Window 2.1;
import Ethereum 1.0
ApplicationWindow {
id: window
title: "muted"
width: 900
height: 600
minimumHeight: 300
id: window
title: "muted"
width: 900
height: 600
minimumHeight: 300
property alias url: webView.url
property alias debugUrl: debugView.url
property alias webView: webView
property alias url: webView.url
property alias webView: webView
Item {
id: root
anchors.fill: parent
WebView {
objectName: "webView"
id: webView
anchors {
top: root.top
right: root.right
left: root.left
bottom: sizeGrip.top
}
}
Item {
id: root
anchors.fill: parent
WebView {
objectName: "webView"
id: webView
anchors {
top: root.top
right: root.right
left: root.left
bottom: root.bottom
//bottom: sizeGrip.top
}
Rectangle {
id: sizeGrip
color: "gray"
height: 5
anchors {
left: root.left
right: root.right
}
y: Math.round(root.height * 2 / 3)
experimental.preferences.javascriptEnabled: true
experimental.preferences.navigatorQtObjectEnabled: true
experimental.onMessageReceived: {
var data = JSON.parse(message.data)
MouseArea {
anchors.fill: parent
drag.target: sizeGrip
drag.minimumY: 0
drag.maximumY: root.height - sizeGrip.height
drag.axis: Drag.YAxis
}
}
switch(data.call) {
case "log":
console.log.apply(this, data.args)
break;
}
}
function postData(seed, data) {
webview.experimental.postMessage(JSON.stringify({data: data, _seed: seed}))
}
function postEvent(event, data) {
webview.experimental.postMessage(JSON.stringify({data: data, _event: event}))
}
}
WebView {
id: debugView
objectName: "debugView"
anchors {
left: root.left
right: root.right
bottom: root.bottom
top: sizeGrip.bottom
}
}
}
/*
Rectangle {
id: sizeGrip
color: "gray"
height: 5
anchors {
left: root.left
right: root.right
}
y: Math.round(root.height * 2 / 3)
MouseArea {
anchors.fill: parent
drag.target: sizeGrip
drag.minimumY: 0
drag.maximumY: root.height - sizeGrip.height
drag.axis: Drag.YAxis
}
}
*/
}
}

View File

@ -7,134 +7,135 @@ import QtQuick.Window 2.1;
import Ethereum 1.0
ApplicationWindow {
id: window
title: "Ethereum"
width: 900
height: 600
minimumHeight: 300
id: window
title: "Ethereum"
width: 900
height: 600
minimumHeight: 300
property alias url: webview.url
property alias webView: webview
property alias url: webview.url
property alias webView: webview
Item {
objectName: "root"
id: root
anchors.fill: parent
state: "inspectorShown"
Item {
objectName: "root"
id: root
anchors.fill: parent
state: "inspectorShown"
WebView {
objectName: "webView"
id: webview
anchors.fill: parent
/*
anchors {
left: parent.left
right: parent.right
bottom: sizeGrip.top
top: parent.top
WebView {
objectName: "webView"
id: webview
anchors.fill: parent
/*
anchors {
left: parent.left
right: parent.right
bottom: sizeGrip.top
top: parent.top
}
*/
onTitleChanged: { window.title = title }
experimental.preferences.javascriptEnabled: true
experimental.preferences.navigatorQtObjectEnabled: true
experimental.preferences.developerExtrasEnabled: true
experimental.userScripts: [ui.assetPath("ethereum.js")]
experimental.onMessageReceived: {
//console.log("[onMessageReceived]: ", message.data)
var data = JSON.parse(message.data)
switch(data.call) {
case "getBlockByNumber":
var block = eth.getBlock("b9b56cf6f907fbee21db0cd7cbc0e6fea2fe29503a3943e275c5e467d649cb06")
postData(data._seed, block)
break
case "getBlockByHash":
var block = eth.getBlock("b9b56cf6f907fbee21db0cd7cbc0e6fea2fe29503a3943e275c5e467d649cb06")
postData(data._seed, block)
break
case "createTx":
if(data.args.length < 5) {
postData(data._seed, null)
} else {
var tx = eth.createTx(data.args[0], data.args[1],data.args[2],data.args[3],data.args[4])
postData(data._seed, tx)
}
*/
onTitleChanged: { window.title = title }
experimental.preferences.javascriptEnabled: true
experimental.preferences.navigatorQtObjectEnabled: true
experimental.preferences.developerExtrasEnabled: true
experimental.userScripts: [ui.assetPath("ethereum.js")]
experimental.onMessageReceived: {
//console.log("[onMessageReceived]: ", message.data)
var data = JSON.parse(message.data)
switch(data.call) {
case "getBlockByNumber":
var block = eth.getBlock("b9b56cf6f907fbee21db0cd7cbc0e6fea2fe29503a3943e275c5e467d649cb06")
postData(data._seed, block)
break
case "getBlockByHash":
var block = eth.getBlock("b9b56cf6f907fbee21db0cd7cbc0e6fea2fe29503a3943e275c5e467d649cb06")
postData(data._seed, block)
break
case "createTx":
if(data.args.length < 5) {
postData(data._seed, null)
} else {
var tx = eth.createTx(data.args[0], data.args[1],data.args[2],data.args[3],data.args[4])
postData(data._seed, tx)
}
break
case "getStorage":
if(data.args.length < 2) {
postData(data._seed, null)
} else {
var stateObject = eth.getStateObject(data.args[0])
var storage = stateObject.getStorage(data.args[1])
postData(data._seed, storage)
}
break
case "getKey":
var keys = eth.getKey()
postData(data._seed, keys)
break
case "watch":
if(data.args.length > 0) {
eth.watch(data.args[0]);
}
}
break
case "getStorage":
if(data.args.length < 2) {
postData(data._seed, null)
} else {
var stateObject = eth.getStateObject(data.args[0])
var storage = stateObject.getStorage(data.args[1])
postData(data._seed, storage)
}
function postData(seed, data) {
webview.experimental.postMessage(JSON.stringify({data: data, _seed: seed}))
}
function postEvent(event, data) {
webview.experimental.postMessage(JSON.stringify({data: data, _event: event}))
}
function onNewBlockCb(block) {
postEvent("block:new", block)
}
function onObjectChangeCb(stateObject) {
postEvent("object:change", stateObject)
}
break
case "getKey":
var keys = eth.getKey()
postData(data._seed, keys)
break
case "watch":
if(data.args.length > 0) {
eth.watch(data.args[0]);
}
break
}
}
function postData(seed, data) {
webview.experimental.postMessage(JSON.stringify({data: data, _seed: seed}))
}
function postEvent(event, data) {
webview.experimental.postMessage(JSON.stringify({data: data, _event: event}))
}
Rectangle {
id: sizeGrip
color: "gray"
visible: false
height: 10
anchors {
left: root.left
right: root.right
}
y: Math.round(root.height * 2 / 3)
MouseArea {
anchors.fill: parent
drag.target: sizeGrip
drag.minimumY: 0
drag.maximumY: root.height
drag.axis: Drag.YAxis
}
}
WebView {
id: inspector
visible: false
url: webview.experimental.remoteInspectorUrl
anchors {
left: root.left
right: root.right
top: sizeGrip.bottom
bottom: root.bottom
}
}
states: [
State {
name: "inspectorShown"
PropertyChanges {
target: inspector
url: webview.experimental.remoteInspectorUrl
}
}
]
function onNewBlockCb(block) {
postEvent("block:new", block)
}
function onObjectChangeCb(stateObject) {
postEvent("object:change", stateObject)
}
}
Rectangle {
id: sizeGrip
color: "gray"
visible: false
height: 10
anchors {
left: root.left
right: root.right
}
y: Math.round(root.height * 2 / 3)
MouseArea {
anchors.fill: parent
drag.target: sizeGrip
drag.minimumY: 0
drag.maximumY: root.height
drag.axis: Drag.YAxis
}
}
WebView {
id: inspector
visible: false
url: webview.experimental.remoteInspectorUrl
anchors {
left: root.left
right: root.right
top: sizeGrip.bottom
bottom: root.bottom
}
}
states: [
State {
name: "inspectorShown"
PropertyChanges {
target: inspector
url: webview.experimental.remoteInspectorUrl
}
}
]
}
}

View File

@ -120,8 +120,8 @@ func (ui *UiLib) Muted(content string) {
go func() {
path := "file://" + ui.AssetPath("muted/index.html")
win.Set("url", path)
debuggerPath := "file://" + ui.AssetPath("muted/debugger.html")
win.Set("debugUrl", debuggerPath)
//debuggerPath := "file://" + ui.AssetPath("muted/debugger.html")
//win.Set("debugUrl", debuggerPath)
win.Show()
win.Wait()

View File

@ -12,6 +12,7 @@ import (
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire"
"github.com/ethereum/go-ethereum/utils"
"github.com/obscuren/mutan"
"os"
"strings"
)
@ -190,7 +191,7 @@ func (i *Console) ParseInput(input string) bool {
case "contract":
fmt.Println("Contract editor (Ctrl-D = done)")
mainInput, initInput := ethutil.PreProcess(i.Editor())
mainInput, initInput := mutan.PreProcess(i.Editor())
mainScript, err := utils.Compile(mainInput)
if err != nil {
fmt.Println(err)