event lists

Maybe this example helps? It's pretty self explanatory.

import wx

class MyFrame( wx.Frame ):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)

        # Now add 3 text controls
        szr = wx.BoxSizer(wx.VERTICAL)

        self.txtbox1 = wx.TextCtrl(self, -1)
        self.txtbox2 = wx.TextCtrl(self, -1)
        self.txtbox3 = wx.TextCtrl(self, -1)

        szr.Add(self.txtbox1, 1, wx.EXPAND)
        szr.Add(self.txtbox2, 1, wx.EXPAND)
        szr.Add(self.txtbox3, 1, wx.EXPAND)
        self.SetSizer(szr)

        # Bind events to 1 handler
        self.Bind(wx.EVT_TEXT, self.on_text_evt)
        
        self.CenterOnScreen()
        self.Show(True)

        # Setup a dictionary of event handlers
        self.evt_hndlrs = { self.txtbox1 : self.on_txtbox1_enter,
                            self.txtbox2 : self.on_txtbox2_enter,
                            self.txtbox3 : self.on_txtbox3_enter }

    def on_text_evt(self, e):
        self.evt_hndlrs[e.GetEventObject()](e)

    def on_txtbox1_enter(self, e):
        print "tb1"

    def on_txtbox2_enter(self, e):
        print "tb2"
        
    def on_txtbox3_enter(self, e):
        print "tb3"
        
class MyApp( wx.PySimpleApp ):
    def OnInit( self ):
        win = MyFrame( None, -1, "Handle events")
        return True

if __name__ == "__main__":
    app = MyApp()
    app.MainLoop()

jw

-->-----Original Message-----
-->From: Fisher, Michael L [mailto:fisherml@BATTELLE.ORG]
-->Sent: Thursday, June 16, 2005 6:16 AM
-->To: wxPython-users@lists.wxwidgets.org
-->Subject: [wxPython-users] event lists
-->
-->I have a series of text boxes, combos boxes and text controls for users
-->to enter data...
-->
--> self.statictext = ['','','','','','','','']
--> self.editeos = ['','','','','','','','']
--> self.editgamma = ['','','','','','','','']
--> self.editzones = ['','','','','','','','']
--> self.editrho = ['','','','','','','','']
--> self.editpressure = ['','','','','','','','']
--> self.edittemperature = ['','','','','','','','']
--> self.eoscombo =
-->[self.EvtEOS1Combo,self.EvtEOS2Combo,self.EvtEOS3Combo,self.EvtEOS4Combo
-->,self.EvtEOS5Combo,
-->
-->self.EvtEOS6Combo,self.EvtEOS7Combo,self.EvtEOS8Combo]
--> self.gammatext =
-->[self.EvtGamma1Text,self.EvtGamma2Text,self.EvtGamma3Text,self.EvtGamma4
-->Text,self.EvtGamma5Text,
-->
-->self.EvtGamma6Text,self.EvtGamma7Text,self.EvtGamma8Text]
--> self.zonestext =
-->[self.EvtZones1Text,self.EvtZones2Text,self.EvtZones3Text,self.EvtZones4
-->Text,self.EvtZones5Text,
-->
-->self.EvtZones6Text,self.EvtZones7Text,self.EvtZones8Text]
--> self.rhotext =
-->[self.EvtRhoText1,self.EvtRhoText2,self.EvtRhoText3,self.EvtRhoText4,sel
-->f.EvtRhoText5,self.EvtRhoText6,
--> self.EvtRhoText7,self.EvtRhoText8]
--> self.pressuretext =
-->[self.EvtPressureText1,self.EvtPressureText2,self.EvtPressureText3,self.
-->EvtPressureText4,self.EvtPressureText5,
-->
-->self.EvtPressureText6,self.EvtPressureText7,self.EvtPressureText8]
--> self.temperaturetext =
-->[self.EvtTemperatureText1,self.EvtTemperatureText2,self.EvtTemperatureTe
-->xt3,self.EvtTemperatureText4,
-->
-->self.EvtTemperatureText5,self.EvtTemperatureText6,self.EvtTemperatureTex
-->t7,self.EvtTemperatureText8]
-->
--> gs.Add(wx.StaticText(self, -1, ''),0,wx.EXPAND)
--> gs.Add(wx.StaticText(self, -1,'EOS for Region'),0,wx.EXPAND)
--> gs.Add(wx.StaticText(self, -1,'Ratio of Specific
-->Heats'),0,wx.EXPAND)
--> gs.Add(wx.StaticText(self, -1,'Number of Zones'),0,wx.EXPAND)
--> gs.Add(wx.StaticText(self, -1, 'Density of region (gm/cm^3'), 0,
-->wx.EXPAND)
--> gs.Add(wx.StaticText(self, -1, 'Prefill pressure of gas
-->(psig)'), 0, wx.EXPAND)
--> gs.Add(wx.StaticText(self, -1, 'Prefill temperature of gas
-->(F)'), 0, wx.EXPAND)
-->
--> for i in range(0,8):
--> self.statictext[i] = wx.StaticText(self, i, 'EOS for
-->material #' + str(i+1))
--> self.statictext[i].Show(True)
--> gs.Add(self.statictext[i],0,wx.EXPAND)
--> self.editeos[i] = wx.ComboBox(self, i+8,
-->config.eosmat[i],wx.Point(-1,-1),wx.Size(-1,-1),self.eosList,
-->wx.CB_DROPDOWN)
--> self.editeos[i].Show(True)
--> gs.Add(self.editeos[i], 0, wx.EXPAND)
--> self.Bind(wx.EVT_COMBOBOX, self.eoscombo[i],self.editeos[i])
--> self.editgamma[i] = wx.TextCtrl(self,i+16,config.gamma[i])
--> self.editgamma[i].Show(True)
--> gs.Add(self.editgamma[i], 0, wx.EXPAND)
--> self.Bind(wx.EVT_TEXT, self.gammatext[i], self.editgamma[i])
--> self.editzones[i] = wx.TextCtrl(self,i+24,config.zones[i])
--> self.editzones[i].Show(True)
--> gs.Add(self.editzones[i], 0, wx.EXPAND)
--> self.Bind(wx.EVT_TEXT, self.zonestext[i], self.editzones[i])
-->
-->I have used a clunky method of handling the multiple events. Is there a
-->way to index the events also so that I can write one def for
-->self.eoscombo that notes the index or the event id and acts accordingly?
-->The ways I have tried do not work.
-->
-->Thanks,
-->
-->
-->
-->Michael Fisher, Ph.D.
-->Senior Research Scientist
-->Battelle
-->505 King Avenue
-->Columbus, OH 43201-2693
-->
-->fisherml@battelle.org
-->Tel: 614.424.7871
-->Fax: 614.424.3918
-->
-->
-->---------------------------------------------------------------------
-->To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
-->For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org