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条)

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程