SpinControl & Slider Demo

Folks,

I am trying to create a SpinControl and a Slider functionality such that
changing the slider should affect the spincontrol and vice-versa. I know
this should be handled by events, so I have an event handler for the
slider that should set the value of the spincontrol on the appropriate
slider event. The code below doesn't yield the expected result. In fact,
the slider event handler in the implemenation below doesn't seem able to
process events. Who has a better idea how to achieve the aforementioned
functionality?

Thanks in anticipation,
Ashu Akoachere

class MainWindow(wxFrame):
    """ Define a new frame class"""
    def __init__(self,parent,id,title):
        wxFrame.__init__(self,parent,-4,title, size = (560,300),
style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)

        # Adding functionality for spin control
        self.spincontrol = wxSpinCtrl(self,1,"",wxDefaultPosition,
                            wxDefaultSize,wxSP_VERTICAL|wxSP_ARROW_KEYS)
        self.spincontrol.SetRange(1,230)
        self.spincontrol.SetValue(12)
        self.spincontrol.SetValue(56)

        # Adding functionality for slider control
        self.slidercontrol = wxSlider(self,-1,16,0,232,wxDefaultPosition,
                                wxDefaultSize,wxSL_HORIZONTAL|wxSL_LABELS)

        # Multi-line text control functionality
        #self.control = wxTextCtrl(self, ID_TextCtrl, "",
wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE)

        # Putting the above controls into a sizer
        self.sizer = wxBoxSizer(wxVERTICAL)
        self.sizer.Add(self.spincontrol,1,wxEXPAND)
        self.sizer.Add(self.slidercontrol,1,wxEXPAND)
        #self.sizer.Add(self.control,1,wxEXPAND)

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

        EVT_COMMAND_SCROLL(self, ID_Name, self.OnSliderControl)

        self.Show(true)

    def OnSliderControl(self, event):
        #self.spincontrol.SetValue(self.slidercontrol.GetValue())
        self.spincontrol.SetValue(34)
        #self.selfcontrol.SetValue(self.slidercontrol.GetValue() + 10)

app = wxPySimpleApp()
frame = MainWindow(None,-1,"Demo of the Spin Control and Slider
Functionality")
frame.Show()
app.MainLoop()

welll.... it works... :smiley:
I changed 2 lines :smiley:
        EVT_COMMAND_SCROLL(self, ID_Name, self.OnSliderControl)
became
        EVT_COMMAND_SCROLL(self, self.slidercontrol.GetId(), self.OnSliderControl)
and
        self.spincontrol.SetValue(34)
became
        self.spincontrol.SetValue(event.GetPosition())

I think is best to use the data that comes with the event object...
also... pay attention to the IDs of the controls.

Respect,
Peter.

from wxPython.wx import *

class MainWindow(wxFrame):
     """ Define a new frame class"""
     def __init__(self,parent,id,title):
         wxFrame.__init__(self,parent,-4,title, size = (560,300), style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)

         # Adding functionality for spin control
         self.spincontrol = wxSpinCtrl(self,1,"",wxDefaultPosition,
                             wxDefaultSize,wxSP_VERTICAL|wxSP_ARROW_KEYS)
         self.spincontrol.SetRange(1,230)
         self.spincontrol.SetValue(12)
         self.spincontrol.SetValue(56)

         # Adding functionality for slider control
         self.slidercontrol = wxSlider(self,-1,16,0,232,wxDefaultPosition, wxDefaultSize,wxSL_HORIZONTAL|wxSL_LABELS)

         # Multi-line text control functionality
         #self.control = wxTextCtrl(self, ID_TextCtrl, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE)

         # Putting the above controls into a sizer
         self.sizer = wxBoxSizer(wxVERTICAL)
         self.sizer.Add(self.spincontrol,1,wxEXPAND)
         self.sizer.Add(self.slidercontrol,1,wxEXPAND)
         #self.sizer.Add(self.control,1,wxEXPAND)

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

         EVT_COMMAND_SCROLL(self, self.slidercontrol.GetId(), self.OnSliderControl)

         self.Show(true)

     def OnSliderControl(self, event):
         #self.spincontrol.SetValue(self.slidercontrol.GetValue())
         self.spincontrol.SetValue(event.GetPosition())
         #self.selfcontrol.SetValue(self.slidercontrol.GetValue() + 10)

app = wxPySimpleApp()
frame = MainWindow(None,-1,"Demo of the Spin Control and Slider Functionality")
frame.Show()
app.MainLoop()