aboutsummaryrefslogtreecommitdiffstats
path: root/ui/gui.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-02-21 19:37:40 +0800
committerobscuren <geffobscura@gmail.com>2014-02-21 19:37:40 +0800
commit05c353eca0c4e01457412dd643529200816ab159 (patch)
tree2294ad6c7976dcf4880dae5d7544a99c22947b74 /ui/gui.go
parentd7ecc92c4134e3987b2b370bb53b0cd560fc0f7b (diff)
downloadgo-tangerine-05c353eca0c4e01457412dd643529200816ab159.tar.gz
go-tangerine-05c353eca0c4e01457412dd643529200816ab159.tar.zst
go-tangerine-05c353eca0c4e01457412dd643529200816ab159.zip
Added a basic <UNSTABLE> UI
Diffstat (limited to 'ui/gui.go')
-rw-r--r--ui/gui.go83
1 files changed, 83 insertions, 0 deletions
diff --git a/ui/gui.go b/ui/gui.go
new file mode 100644
index 000000000..b2a8dad73
--- /dev/null
+++ b/ui/gui.go
@@ -0,0 +1,83 @@
+package ethui
+
+import (
+ "bufio"
+ "encoding/hex"
+ "fmt"
+ "github.com/ethereum/eth-go"
+ "github.com/ethereum/eth-go/ethchain"
+ "github.com/ethereum/eth-go/ethutil"
+ "github.com/niemeyer/qml"
+ "strings"
+)
+
+type Gui struct {
+ win *qml.Window
+ engine *qml.Engine
+ component *qml.Common
+ eth *eth.Ethereum
+}
+
+func New(ethereum *eth.Ethereum) *Gui {
+ return &Gui{eth: ethereum}
+}
+
+type Block struct {
+ Number int
+ Hash string
+}
+
+func NewBlockFromBlock(block *ethchain.Block) *Block {
+ info := block.BlockInfo()
+ hash := hex.EncodeToString(block.Hash())
+
+ return &Block{Number: int(info.Number), Hash: hash}
+}
+
+func (ui *Gui) Start() {
+ qml.RegisterTypes("GoExtensions", 1, 0, []qml.TypeSpec{{
+ Init: func(p *Block, obj qml.Object) { p.Number = 0; p.Hash = "" },
+ }})
+
+ ethutil.Config.Log.Infoln("[GUI] Starting GUI")
+ ui.engine = qml.NewEngine()
+ component, err := ui.engine.LoadFile("wallet.qml")
+ if err != nil {
+ panic(err)
+ }
+
+ ui.win = component.CreateWindow(nil)
+ root := ui.win.Root()
+
+ context := ui.engine.Context()
+ context.SetVar("tester", &Tester{root: root})
+
+ ui.eth.BlockManager.SecondaryBlockProcessor = ui
+ ui.eth.Start()
+
+ ui.win.Show()
+ ui.win.Wait()
+}
+
+func (ui *Gui) ProcessBlock(block *ethchain.Block) {
+ ui.win.Root().Call("addBlock", NewBlockFromBlock(block))
+}
+
+type Tester struct {
+ root qml.Object
+}
+
+func (t *Tester) Compile(area qml.Object) {
+ fmt.Println(area)
+ ethutil.Config.Log.Infoln("[TESTER] Compiling")
+
+ code := area.String("text")
+
+ scanner := bufio.NewScanner(strings.NewReader(code))
+ scanner.Split(bufio.ScanLines)
+
+ var lines []string
+ for scanner.Scan() {
+ lines = append(lines, scanner.Text())
+ }
+}