tadvi/winc

Refresh imageView in a goroutine

Opened this issue · 0 comments

I have a goroutine that takes care of updating data, loading info etc.
The goroutine updates a few Labels without problems, but it fails to replace images on a ImageView...
How can I have a image view that updates images from a go routine?

This works:

package main

import (
	"github.com/tadvi/winc"
)

func main() {
	mainWindow := winc.NewForm(nil)
	mainWindow.SetSize(1600, 1000) // (width, height)
	mainWindow.SetText("Ponto 2.0")
	mainWindow.EnableMaxButton(false)
	P2 := winc.NewGroupBox(mainWindow)
	P2.SetSize(1050, 800)
	P2.SetPos(520, 10)
	P2.SetText("Updating Screen")

	P2t := winc.NewImageView(P2)
	P2t.SetSize(1010, 760)
	P2t.SetPos(20, 20)
	P2t.SetMaxSize(1010, 760)
	P2t.DrawImageFile("./screen.png")
	mainWindow.Center()
	mainWindow.Show()
	mainWindow.OnClose().Bind(wndOnClose)

	winc.RunMainLoop() // Must call to start event loop.
}

func wndOnClose(arg *winc.Event) {
	winc.Exit()
}

But this does not:

package main

import (
	"github.com/tadvi/winc"
)

func main() {
	mainWindow := winc.NewForm(nil)
	mainWindow.SetSize(1600, 1000)
	mainWindow.SetText("Ponto 2.0")
	mainWindow.EnableMaxButton(false)
	P2 := winc.NewGroupBox(mainWindow)
	P2.SetSize(1050, 800)
	P2.SetPos(520, 10)
	P2.SetText("Updating Screen")

	P2t := winc.NewImageView(P2)
	P2t.SetSize(1010, 760)
	P2t.SetPos(20, 20)
	P2t.SetMaxSize(1010, 760)

	mainWindow.Center()
	mainWindow.Show()
	mainWindow.OnClose().Bind(wndOnClose)
	go func() {
	      for {
		      P2t.DrawImageFile("./screen.png")
		      time.Sleep(time.Second * 1)
	      }
	}()
	winc.RunMainLoop()
}

func wndOnClose(arg *winc.Event) {
	winc.Exit()
}

The file "screen.png" is updated from time to time, so I have a loop in the go routine that keeps reading the file to draw new updates..

How can I achieve this?

Thanks in advance!