ui_lib.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package ethui
  2. import (
  3. "github.com/ethereum/eth-go"
  4. "github.com/ethereum/eth-go/ethutil"
  5. "github.com/go-qml/qml"
  6. "path"
  7. )
  8. type memAddr struct {
  9. Num string
  10. Value string
  11. }
  12. // UI Library that has some basic functionality exposed
  13. type UiLib struct {
  14. engine *qml.Engine
  15. eth *eth.Ethereum
  16. connected bool
  17. assetPath string
  18. // The main application window
  19. win *qml.Window
  20. Db *Debugger
  21. DbWindow *DebuggerWindow
  22. }
  23. func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib {
  24. return &UiLib{engine: engine, eth: eth, assetPath: assetPath}
  25. }
  26. func (ui *UiLib) OpenQml(path string) {
  27. container := NewQmlApplication(path[7:], ui)
  28. app := NewExtApplication(container, ui)
  29. go app.run()
  30. }
  31. func (ui *UiLib) OpenHtml(path string) {
  32. container := NewHtmlApplication(path, ui)
  33. app := NewExtApplication(container, ui)
  34. go app.run()
  35. }
  36. func (ui *UiLib) Muted(content string) {
  37. component, err := ui.engine.LoadFile(ui.AssetPath("qml/muted.qml"))
  38. if err != nil {
  39. logger.Debugln(err)
  40. return
  41. }
  42. win := component.CreateWindow(nil)
  43. go func() {
  44. path := "file://" + ui.AssetPath("muted/index.html")
  45. win.Set("url", path)
  46. win.Show()
  47. win.Wait()
  48. }()
  49. }
  50. func (ui *UiLib) Connect(button qml.Object) {
  51. if !ui.connected {
  52. ui.eth.Start(true)
  53. ui.connected = true
  54. button.Set("enabled", false)
  55. }
  56. }
  57. func (ui *UiLib) ConnectToPeer(addr string) {
  58. ui.eth.ConnectToPeer(addr)
  59. }
  60. func (ui *UiLib) AssetPath(p string) string {
  61. return path.Join(ui.assetPath, p)
  62. }
  63. func (self *UiLib) StartDbWithContractAndData(contractHash, data string) {
  64. dbWindow := NewDebuggerWindow(self)
  65. object := self.eth.StateManager().CurrentState().GetStateObject(ethutil.Hex2Bytes(contractHash))
  66. if len(object.Script()) > 0 {
  67. dbWindow.SetCode("0x" + ethutil.Bytes2Hex(object.Script()))
  68. }
  69. dbWindow.SetData("0x" + data)
  70. dbWindow.Show()
  71. }
  72. func (self *UiLib) StartDbWithCode(code string) {
  73. dbWindow := NewDebuggerWindow(self)
  74. dbWindow.SetCode("0x" + code)
  75. dbWindow.Show()
  76. }
  77. func (self *UiLib) StartDebugger() {
  78. dbWindow := NewDebuggerWindow(self)
  79. //self.DbWindow = dbWindow
  80. dbWindow.Show()
  81. }