Ejemplo n.º 1
0
func run() error {
	qml.Init(nil)
	engine := qml.NewEngine()
	engine.AddImageProvider("pwd", func(id string, width, height int) image.Image {
		f, err := os.Open(id)
		if err != nil {
			panic(err)
		}
		defer f.Close()
		image, err := png.Decode(f)
		if err != nil {
			panic(err)
		}
		return image
	})

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

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

	return nil
}
Ejemplo n.º 2
0
Archivo: gopher.go Proyecto: RickyS/qml
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
}
Ejemplo n.º 3
0
func (s *S) SetUpTest(c *C) {
	qml.SetLogger(c)
	qml.CollectStats(true)
	qml.ResetStats()

	stats := qml.Stats()
	if stats.EnginesAlive > 0 || stats.ValuesAlive > 0 || stats.ConnectionsAlive > 0 {
		panic(fmt.Sprintf("Test started with values alive: %#v\n", stats))
	}

	s.engine = qml.NewEngine()
	s.context = s.engine.Context()
}
Ejemplo n.º 4
0
func run() error {
	qml.Init(nil)
	engine := qml.NewEngine()

	engine.On("quit", func() { os.Exit(0) })

	component, err := engine.LoadFile(os.Args[1])
	if err != nil {
		return err
	}
	window := component.CreateWindow(nil)
	window.Show()
	window.Wait()
	return nil
}
Ejemplo n.º 5
0
func run() error {
	qml.Init(nil)
	engine := qml.NewEngine()
	context = engine.Context()

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

	game = &Game{}
	context.SetVar("game", game)

	context.SetVar("jobModel", job_model)
	context.SetVar("invModel", inv_model)
	context.SetVar("craftModel", craft_model)
	context.SetVar("buildModel", build_model)

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

	cspriteComponent, err := engine.LoadFile("CSprite.qml")
	if err != nil {
		return err
	}

	csprite := &CSprite{Component: cspriteComponent}
	game.CSprite = csprite

	win = component.CreateWindow(nil)
	// win.On("widthChanged", func(width int) {
	// 	fmt.Printf("New width: %d\n", width)
	// })
	win.Show()

	// win.Wait()
	go func() {
		win.Wait()
		quit <- true
	}()

	return nil
}
Ejemplo n.º 6
0
func run() error {
	qml.Init(nil)
	engine := qml.NewEngine()
	component, err := engine.LoadString("webview.qml", webview)
	if err != nil {
		return err
	}
	ctrl := &Control{
		done: make(chan error),
		win:  component.CreateWindow(nil),
	}
	engine.Context().SetVar("ctrl", ctrl)
	root := ctrl.win.Root()
	root.On("loadingChanged", ctrl.Snapshot)
	root.Set("url", os.Args[1])
	ctrl.win.Show()
	return <-ctrl.done
}
Ejemplo n.º 7
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
}
Ejemplo n.º 8
0
func run() error {
	qml.Init(nil)
	engine := qml.NewEngine()
	colors := &Colors{}
	engine.Context().SetVar("colors", colors)
	component, err := engine.LoadFile("delegate.qml")
	if err != nil {
		return err
	}
	window := component.CreateWindow(nil)
	window.Show()
	go func() {
		n := func() uint8 { return uint8(rand.Intn(256)) }
		for i := 0; i < 100; i++ {
			colors.Add(color.RGBA{n(), n(), n(), 0xff})
			time.Sleep(1 * time.Second)
		}
	}()
	window.Wait()
	return nil
}
Ejemplo n.º 9
0
func main() {

	// Profiling -->
	// f, err := os.Create("cpu.prof")
	// if err != nil {
	// 	log.Fatal(err)
	// }
	// pprof.StartCPUProfile(f)
	// defer pprof.StopCPUProfile()
	// <-- Profiling

	// Watching busy status
	busy = make(chan bool)
	go func() {
		for {
			ctrl.Busy = <-busy
			qml.Changed(ctrl, &ctrl.Busy)
		}
	}()

	qml.Init(nil)
	engine := qml.NewEngine()
	component, err := engine.LoadFile("qmldict.qml")
	if err != nil {
		panic(err)
	}

	ctrl.DictionariesList = GetDictList(DICT_PATH)
	ctrl.Len = len(ctrl.DictionariesList)
	context := engine.Context()
	context.SetVar("ctrl", ctrl)

	// log.Println(ctrl.DictionariesList)

	window := component.CreateWindow(nil)
	ctrl.Root = window.Root()

	window.Show()
	window.Wait()
}
Ejemplo n.º 10
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
}
Ejemplo n.º 11
0
Archivo: main.go Proyecto: RickyS/qml
func main() {
	qml.Init(nil)
	engine := qml.NewEngine()
	component, err := engine.LoadFile("particle.qml")
	if err != nil {
		panic(err)
	}

	ctrl := Control{Message: "Hello from Go!"}

	context := engine.Context()
	context.SetVar("ctrl", &ctrl)

	window := component.CreateWindow(nil)

	ctrl.Root = window.Root()

	rand.Seed(time.Now().Unix())

	window.Show()
	window.Wait()
}
Ejemplo n.º 12
0
func run() error {
	qml.Init(nil)

	engine := qml.NewEngine()

	base, err := engine.LoadFile("base.qml")
	if err != nil {
		return err
	}
	rect, err := engine.LoadFile("rect.qml")
	if err != nil {
		return err
	}

	win := base.CreateWindow(nil)
	obj := rect.Create(nil)

	obj.Set("parent", win.Root())

	win.Show()
	win.Wait()

	return nil
}