Skip to content

Refresh imageView in a goroutine #13

Description

@wilsonmfaria

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions