Admittedly, I have a hard time with object oriented anything. So I don't quite understand the self
declarations all over the place. That said, I have a panel with a number of the same types of widgets.
Is there a way to have a generic function receive a widget as an argument?
I'd like the function at the bottom to receive arguments from the self.Bind
, specifically, can I pass self.sliderZone1
and self.tc_ZONEVOL1
into the def
?
I'd like the def slider1Update
to look something like this:
def sliderUpdate(self, event, slider, textctrl):
textctrl.SetValue(str(slider.GetValue())
Is that possible?
Psuedo-code:
self.ck_ZONE1 = wx.CheckBox(self, -1, zoneNAME[0])
self.ck_ZONE1.SetToolTip(wx.ToolTip("Click here to monitor volume for this zone."))
self.tc_ZONEVOL1 = wx.TextCtrl(panel, -1, "", (0,0), (30,21))
self.tc_ZONEVOL1.SetToolTip(wx.ToolTip("Set max volume for the zone (0-100)"))
self.sliderZone1 = wx.Slider(self, -1, 50, 0, 100, size=(400,10), style=wx.SL_HORIZONTAL)
self.Bind(wx.EVT_SLIDER, self.slider1Update)
sizer.Add(self.ck_ZONE1, pos=(xIndex,0), flag=wx.EXPAND|wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=10)
sizer.Add(self.sliderZone1, pos=(xIndex,1), flag=wx.EXPAND|wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=10)
sizer.Add(self.tc_ZONEVOL1, pos=(xIndex,2), flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, border=10).SetMinSize((30,22))
# Read in config
if self.ck_ZONE1.Label == "":
self.ck_ZONE1.Label = zoneNAME[0]
if self.tc_ZONEVOL1.Value == "":
self.tc_ZONEVOL1.SetValue(str(self.sliderZone1.GetValue()))
xIndex +=1
pub.subscribe(self.setVolumePanel, 'setVolumePanel')
sizer.AddGrowableCol(1)
panel.SetSizer(sizer)
def slider1Update(self, event):
self.tc_ZONEVOL1.SetValue(str(self.sliderZone1.GetValue()))