从wx python中的事件处理程序打印/列出待处理事件队列?

时间:2014-12-29 16:08:31

标签: python wxpython

在下面的代码(Slow GUI update of a wx (Python) widget?)中,我怎样才能打印出当前排队的事件列表,让我们说从OnAngleChanged处理程序?

我已经看到存在例如wx.PyApp.ProcessPendingEvents(),所以必须有各种未决事件列表;但ProcessPendingEvents()似乎是一个C函数的接口(根据wx/_core.py),我无法真正找到该列表是什么,或者如何从Python打印它。

import wx
import wx.lib.agw.knobctrl as KC

# started from: http://wxpython.org/Phoenix/docs/html/lib.agw.knobctrl.html

class MyFrame(wx.Frame):

  def __init__(self, parent):

    wx.Frame.__init__(self, parent, -1, "KnobCtrl Demo")

    self.panel = wx.Panel(self)

    self.knob1 = KC.KnobCtrl(self, -1, size=(100, 100))
    self.knob1.SetTags(range(0, 151, 10))
    self.knob1.SetAngularRange(-45, 225)
    self.knob1.SetValue(45)

    # explicit sizes here - cannot figure out the expands ATM
    self.text_ctrl_1 = wx.TextCtrl(self, -1, "0", size=(50, -1))
    self.slider_1 = wx.Slider(self, -1, 0, -12, 12, style=wx.SL_HORIZONTAL|wx.SL_AUTOTICKS|wx.SL_INVERSE, size=(150, -1))
    self.text_ctrl_2 = wx.TextCtrl(self, -1, "0", size=(50, -1))

    main_sizer = wx.BoxSizer(wx.VERTICAL)
    main_sizer.Add(self.knob1, 0, wx.EXPAND | wx.ALL, 20)
    main_sizer.Add(self.text_ctrl_1, 0, wx.EXPAND, 20)
    main_sizer.Add(self.slider_1, 0, wx.EXPAND , 20)
    main_sizer.Add(self.text_ctrl_2, 0, wx.EXPAND, 20)

    self.panel.SetSizer(main_sizer)
    main_sizer.Layout()
    self.knob1.Bind(KC.EVT_KC_ANGLE_CHANGED, self.OnAngleChanged)
    self.slider_1.Bind(wx.EVT_SCROLL, self.OnSliderScroll)

  def OnAngleChanged(self, e):
    theknob = e.EventObject
    x = theknob._mousePosition.x
    y = theknob._mousePosition.y
    ang = theknob.GetAngleFromCoord(x, y)
    self.text_ctrl_1.SetValue("%.2f" % (ang))
    self.text_ctrl_1.Refresh() # no dice
  def OnSliderScroll(self, e):
    obj = e.GetEventObject()
    val = obj.GetValue()
    self.text_ctrl_2.SetValue(str(val))

# our normal wxApp-derived class, as usual

app = wx.App(0)

frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()

app.MainLoop()

0 个答案:

没有答案