dsfw2154 2016-09-28 08:59
浏览 296
已采纳

如何在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 10: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条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部