Example #1
0
func run(filename string) error {
	qml.Init(nil)
	engine := qml.NewEngine()

	model, err := Read("model/gopher.obj")
	if err != nil {
		return err
	}

	qml.RegisterTypes("GoExtensions", 1, 0, []qml.TypeSpec{{
		Init: func(g *Gopher, obj qml.Object) {
			g.Object = obj
			g.model = model
		},
	}})

	component, err := engine.LoadFile(filename)
	if err != nil {
		return err
	}

	win := component.CreateWindow(nil)
	win.Set("x", 560)
	win.Set("y", 320)
	win.Show()
	win.Wait()
	return nil
}
Example #2
0
func (ui *Gui) Start(assetPath string) {
	defer ui.txDb.Close()

	// Register ethereum functions
	qml.RegisterTypes("Ethereum", 1, 0, []qml.TypeSpec{{
		Init: func(p *Block, obj qml.Object) { p.Number = 0; p.Hash = "" },
	}, {
		Init: func(p *Tx, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" },
	}})

	ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", "0.1"))
	ethutil.Config.Log.Infoln("[GUI] Starting GUI")
	// Create a new QML engine
	ui.engine = qml.NewEngine()
	context := ui.engine.Context()

	// Expose the eth library and the ui library to QML
	context.SetVar("eth", ui.lib)
	uiLib := NewUiLib(ui.engine, ui.eth, assetPath)
	context.SetVar("ui", uiLib)

	// Load the main QML interface
	component, err := ui.engine.LoadFile(uiLib.AssetPath("qml/wallet.qml"))
	if err != nil {
		ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'")
		panic(err)
	}
	ui.engine.LoadFile(uiLib.AssetPath("qml/transactions.qml"))

	ui.win = component.CreateWindow(nil)

	// Register the ui as a block processor
	//ui.eth.BlockManager.SecondaryBlockProcessor = ui
	//ui.eth.TxPool.SecondaryProcessor = ui

	// Add the ui as a log system so we can log directly to the UGI
	ethutil.Config.Log.AddLogSystem(ui)

	// Loads previous blocks
	go ui.setInitialBlockChain()
	go ui.readPreviousTransactions()
	go ui.update()

	ui.win.Show()
	ui.win.Wait()

	ui.eth.Stop()
}
Example #3
0
func run() error {
	qml.Init(nil)

	qml.RegisterTypes("GoExtensions", 1, 0, []qml.TypeSpec{{
		Init: func(r *GoRect, obj qml.Object) { r.Object = obj },
	}})

	engine := qml.NewEngine()
	component, err := engine.LoadFile("painting.qml")
	if err != nil {
		return err
	}

	win := component.CreateWindow(nil)
	win.Show()
	win.Wait()

	return nil
}
Example #4
0
func run() error {
	qml.Init(nil)

	qml.RegisterTypes("GoExtensions", 1, 0, []qml.TypeSpec{{
		Name: "GoRect",
		New:  func() interface{} { return &GoRect{} },
	}})

	engine := qml.NewEngine()
	component, err := engine.LoadFile("painting.qml")
	if err != nil {
		return err
	}

	win := component.CreateWindow(nil)
	win.Show()
	win.Wait()

	return nil
}
Example #5
0
func run() error {
	qml.Init(nil)

	qml.RegisterTypes("GoExtensions", 1, 0, []qml.TypeSpec{{
		Init: func(v *GoType, obj qml.Object) {},
	}, {
		Init: func(v *GoSingleton, obj qml.Object) { v.Event = "birthday" },

		Singleton: true,
	}})

	engine := qml.NewEngine()
	component, err := engine.LoadFile("customtype.qml")
	if err != nil {
		return err
	}

	value := component.Create(nil)
	fmt.Println("Text is:", value.Interface().(*GoType).Text)

	return nil
}
Example #6
0
func run() error {
	qml.Init(nil)

	qml.RegisterTypes("GoExtensions", 1, 0, []qml.TypeSpec{{
		Name: "GoType",
		New:  func() interface{} { return &GoType{} },
	}, {
		Name:      "GoSingleton",
		New:       func() interface{} { return &GoSingleton{Event: "birthday"} },
		Singleton: true,
	}})

	engine := qml.NewEngine()
	component, err := engine.LoadFile("customtype.qml")
	if err != nil {
		return err
	}

	value := component.Create(nil)
	fmt.Println("Text is:", value.Interface().(*GoType).Text)

	return nil
}
Example #7
0
func (s *S) TestTable(c *C) {
	var testData TestData

	types := []qml.TypeSpec{{
		Init: func(v *GoType, obj qml.Object) {
			v.object = obj
			v.StringValue = "<initial>"
			testData.createdValue = append(testData.createdValue, v)
		},
	}, {
		Name: "NamedGoType",
		Init: func(v *GoType, obj qml.Object) {
			v.object = obj
			v.StringValue = "<initial>"
			testData.createdValue = append(testData.createdValue, v)
		},
	}, {
		Name: "GoSingleton",
		Init: func(v *GoType, obj qml.Object) {
			v.object = obj
			v.StringValue = "<initial>"
			testData.createdSingleton = append(testData.createdSingleton, v)
		},
		Singleton: true,
	}, {
		Init: func(v *GoRect, obj qml.Object) {
			testData.createdRect = append(testData.createdRect, v)
		},
	}}

	qml.RegisterTypes("GoTypes", 4, 2, types)

	filter := regexp.MustCompile("")
	if tablef != nil {
		filter = regexp.MustCompile(*tablef)
	}

	for i := range tests {
		s.TearDownTest(c)
		t := &tests[i]
		header := fmt.Sprintf("----- Running table test %d: %s -----", i, t.Summary)
		if !filter.MatchString(header) {
			continue
		}
		c.Log(header)
		s.SetUpTest(c)

		value := t.Value
		s.context.SetVar("value", &value)

		testData = TestData{
			C:       c,
			value:   &value,
			engine:  s.engine,
			context: s.context,
		}

		if t.Init != nil {
			t.Init(&testData)
			if c.Failed() {
				c.FailNow()
			}
		}

		component, err := s.engine.LoadString("file.qml", "import QtQuick 2.0\nimport GoTypes 4.2\n"+strings.TrimSpace(t.QML))
		c.Assert(err, IsNil)

		logMark := c.GetTestLog()

		// The component instance is destroyed before the loop ends below,
		// but do a defer to ensure it will be destroyed if the test fails.
		root := component.Create(nil)
		defer root.Destroy()

		testData.component = component
		testData.root = root

		if t.QMLLog != "" {
			logged := c.GetTestLog()[len(logMark):]
			if t.QMLLog[0] == '!' {
				c.Check(logged, Not(Matches), "(?s).*"+t.QMLLog[1:]+".*")
			} else {
				c.Check(logged, Matches, "(?s).*"+t.QMLLog+".*")
			}
		}

		if !reflect.DeepEqual(t.QMLValue, GoType{}) {
			c.Check(value.StringValue, Equals, t.QMLValue.StringValue)
			c.Check(value.BoolValue, Equals, t.QMLValue.BoolValue)
			c.Check(value.IntValue, Equals, t.QMLValue.IntValue)
			c.Check(value.Int64Value, Equals, t.QMLValue.Int64Value)
			c.Check(value.Int32Value, Equals, t.QMLValue.Int32Value)
			c.Check(value.Float64Value, Equals, t.QMLValue.Float64Value)
			c.Check(value.Float32Value, Equals, t.QMLValue.Float32Value)
			c.Check(value.AnyValue, Equals, t.QMLValue.AnyValue)
			c.Check(value.IntsValue, DeepEquals, t.QMLValue.IntsValue)
		}

		if !c.Failed() {
			logMark := c.GetTestLog()

			if t.Done != nil {
				t.Done(&testData)
			}

			if t.DoneLog != "" {
				logged := c.GetTestLog()[len(logMark):]
				if t.DoneLog[0] == '!' {
					c.Check(logged, Not(Matches), "(?s).*"+t.DoneLog[1:]+".*")
				} else {
					c.Check(logged, Matches, "(?s).*"+t.DoneLog+".*")
				}
			}

			if !reflect.DeepEqual(t.DoneValue, GoType{}) {
				c.Check(value.StringValue, Equals, t.DoneValue.StringValue)
				c.Check(value.BoolValue, Equals, t.DoneValue.BoolValue)
				c.Check(value.IntValue, Equals, t.DoneValue.IntValue)
				c.Check(value.Int64Value, Equals, t.DoneValue.Int64Value)
				c.Check(value.Int32Value, Equals, t.DoneValue.Int32Value)
				c.Check(value.Float64Value, Equals, t.DoneValue.Float64Value)
				c.Check(value.Float32Value, Equals, t.DoneValue.Float32Value)
				c.Check(value.AnyValue, Equals, t.DoneValue.AnyValue)
				c.Check(value.IntsValue, DeepEquals, t.DoneValue.IntsValue)
			}
		}

		root.Destroy()

		if c.Failed() {
			c.FailNow() // So relevant logs are at the bottom.
		}
	}
}