dsfw2154 2016-09-28 16:59
浏览 295
已采纳

如何在MacOS上制作wxWidgets(使用golang)重绘窗口?

Here's some sample code that puts a Gauge on the screen and make the progress bar increase 1 value every second. On MacOS I don't see the progress bar update unless I drag the window around or resize it manually with the mouse. Any idea how to force the whole thing to repaint? I'm calling f.Refresh() and f.Update()

package main

import "github.com/dontpanic92/wxGo/wx"
import "time"

var g wx.Gauge

type MyFrame struct {
    wx.Frame
}

func (f *MyFrame) startUpload() {
    for {
        time.Sleep(time.Second)
        g.SetValue(g.GetValue() + 1)
        f.Refresh()
        f.Update()
    }
}

func NewMyFrame() MyFrame {
    f := MyFrame{}
    f.Frame = wx.NewFrame(wx.NullWindow, -1, "Test Thread")
    mainSizer := wx.NewBoxSizer(wx.HORIZONTAL)
    g = wx.NewGauge(f, wx.ID_ANY, 100, wx.DefaultPosition, wx.NewSize(600, 40), 0)
    f.SetSizer(mainSizer)
    mainSizer.Add(g, 100, wx.ALL|wx.EXPAND, 50)
    f.Layout()
    go f.startUpload()
    return f
}

func main() {
    wx1 := wx.NewApp()
    f := NewMyFrame()
    f.Show()
    wx1.MainLoop()
    return
}

Update: I've been reading http://docs.wxwidgets.org/trunk/overview_thread.html and I'm trying code like:

b := wx.NewPaintEvent()
f.GetEventHandler().QueueEvent(b)

instead of calling Refresh and Update but my wx.NewPaintEvent doesn't do anything. Maybe I'm making the wx.NewPaintEvent wrong? Or I'm adding it to the wrong EventHandler?

  • 写回答

2条回答 默认 最新

  • dsx666666 2016-09-30 18:44
    关注

    author of wxGo fixed it:

    https://github.com/dontpanic92/wxGo/issues/10

      wx.Bind(f, wx.EVT_THREAD, func(e wx.Event) {
        threadEvent := wx.ToThreadEvent(e)
        the_gauge.SetValue(threadEvent.GetInt())
      }, UPLOAD_WORKER_ID)
    

    then in the thread:

    threadEvent := wx.NewThreadEvent(wx.EVT_THREAD, UPLOAD_WORKER_ID)
    threadEvent.SetInt(50)
    f.QueueEvent(threadEvent)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?