Problems with current value of wx.SpinCtrl and EVT_SPIN

blackno666 f.petri at steinbichler.de
Sun Apr 9 14:47:17 EDT 2006


Hello,

I am new to Python/wxPython and am experiencing first problems. I have
a dialog which includes a SpinCtrl and a Slider. I want the Slider to
affect the SpinCtrl and vice versa
(http://wiki.wxpython.org/index.cgi/ChallengeDemos#Part1).

The code I wrote does, however, not work correctly. The event EVT_SPIN
is never handled (even though I wrote a handler), and in the handler of
EVT_SCROLL_CHANGED I do not obtain the modified value, but the value
before the control has changed.

Any feedback would be greatly appreciated.
To clarify my problem, here's the code (Python2.4, wxPython 2.6) :

import wx

class AppFrame(wx.Frame):
    def OnSpinGeneral(self, event):
        b = wx.MessageBox("never reached")

    def OnSpin(self, event):
        # I tried to use Skip so that the changing of the value would
take place before
        # I invoke GetValue(), however this has no effect
        event.Skip()

        print self.spin.GetValue()
        self.slider.SetValue(self.spin.GetValue())

    def OnScrollChanged(self, event):
        self.spin.SetValue(self.slider.GetValue())

    def __init__(self):
        wx.Frame.__init__( self,
                          None, -1, "",
                          #size=FRAME_SIZE,
                          style=wx.DEFAULT_FRAME_STYLE )
        self.sizer = wx.BoxSizer( wx.VERTICAL )



        self.spin = wx.SpinCtrl(self, min = 0, max = 50)
        self.slider = wx.Slider(self, 1, 6, 0, 50)

        self.sizer.Add(self.spin)
        self.sizer.Add(self.slider)

        self.Bind(wx.EVT_SCROLL_CHANGED, self.OnScrollChanged,
self.slider)
        self.Bind(wx.EVT_SPIN_UP, self.OnSpin, self.spin)
        self.Bind(wx.EVT_SPIN_DOWN, self.OnSpin, self.spin)
        self.Bind(wx.EVT_SPIN, self.OnSpinGeneral, self.spin)

        self.SetSizer(self.sizer)
        self.SetAutoLayout(1)
        self.Show(1)

app = wx.PySimpleApp()
frame = AppFrame()
app.MainLoop()




More information about the Python-list mailing list