Returning Ref. to Runtime Created Control

G

Gary

Good afternoon:

I've playing with dynamically created buttons in Boa Constructor using
wxPython:

def OnBtnButton(self, event):
btnIds = []
self.btn2 = []
xx = 24; yy = 42
for cntr in range(168):
self.btn2.append(wxButton(self.panel1, -1, str(cntr + 1),
wxPoint(xx, yy), wxSize(23, 23), 0))
rr = self.btn2[cntr].GetId()

yy += 26

if (yy + 44) > 380: # Nearing bottom of frame
yy = 42 # Back to top of frame
xx += 26 # starts new column

btnIds.append(str(rr))

func = ['self.BtnFunc1', 'self.BtnFunc2', 'self.BtnFunc3'..]

for ew in range(24):
EVT_BUTTON(self, self.btn2[ew].GetId(), eval(func[ew]))

def BtnFunc1(self, event):
self.t1.SetValue("btnOne")

def BtnFunc2(self, event):
self.t1.SetValue("btnTwo")

def BtnFunc3(self, event):
self.t1.SetValue("btnThree")

# etc…

How can I press one of the buttons and have it return a reference to
itself? (Some other languages have something like root._name or
self._name). Thanks.
--
 
F

F. GEIGER

Gary said:
Good afternoon:

I've playing with dynamically created buttons in Boa Constructor using
wxPython:

def OnBtnButton(self, event):
btnIds = []
self.btn2 = []
xx = 24; yy = 42
for cntr in range(168):
self.btn2.append(wxButton(self.panel1, -1, str(cntr + 1),
wxPoint(xx, yy), wxSize(23, 23), 0))
rr = self.btn2[cntr].GetId()

yy += 26

if (yy + 44) > 380: # Nearing bottom of frame
yy = 42 # Back to top of frame
xx += 26 # starts new column

btnIds.append(str(rr))

func = ['self.BtnFunc1', 'self.BtnFunc2', 'self.BtnFunc3'..]

for ew in range(24):
EVT_BUTTON(self, self.btn2[ew].GetId(), eval(func[ew]))

def BtnFunc1(self, event):
self.t1.SetValue("btnOne")

def BtnFunc2(self, event):
self.t1.SetValue("btnTwo")

def BtnFunc3(self, event):
self.t1.SetValue("btnThree")

# etc.

How can I press one of the buttons and have it return a reference to
itself? (Some other languages have something like root._name or
self._name). Thanks.
--

def _onAnyOfMyButtons_(self, event):
theResponsibleButton = event.GetEventObject()
return

This way you only need *one* handler for hundreds of buttons.

You could derive your own button so that you could write:

def _onAnyOfMyButtons_(self, event):
theResponsibleButton = event.GetEventObject()
theResponsibleButton.writeYourDataToMyControl(self.t1)
return

Or if your subclassed button own an attribute 'index':

def _onAnyOfMyButtons_(self, event):
theResponsibleButton = event.GetEventObject()
self.t1.SetValue("Button %d was pressed. " % theResponsibleButton.index)
return

HTH
Franz GEIGER
 
G

Gary

Gary said:
Good afternoon:

I've playing with dynamically created buttons in Boa Constructor using
wxPython:

def OnBtnButton(self, event):
btnIds = []
self.btn2 = []
xx = 24; yy = 42
for cntr in range(168):
self.btn2.append(wxButton(self.panel1, -1, str(cntr + 1),
wxPoint(xx, yy), wxSize(23, 23), 0))
rr = self.btn2[cntr].GetId()

yy += 26

if (yy + 44) > 380: # Nearing bottom of frame
yy = 42 # Back to top of frame
xx += 26 # starts new column

btnIds.append(str(rr))

func = ['self.BtnFunc1', 'self.BtnFunc2', 'self.BtnFunc3'..]

for ew in range(24):
EVT_BUTTON(self, self.btn2[ew].GetId(), eval(func[ew]))

def BtnFunc1(self, event):
self.t1.SetValue("btnOne")

def BtnFunc2(self, event):
self.t1.SetValue("btnTwo")

def BtnFunc3(self, event):
self.t1.SetValue("btnThree")

# etc.

How can I press one of the buttons and have it return a reference to
itself? (Some other languages have something like root._name or
self._name). Thanks.
--

def _onAnyOfMyButtons_(self, event):
theResponsibleButton = event.GetEventObject()
return

This way you only need *one* handler for hundreds of buttons.

You could derive your own button so that you could write:

def _onAnyOfMyButtons_(self, event):
theResponsibleButton = event.GetEventObject()
theResponsibleButton.writeYourDataToMyControl(self.t1)
return

Or if your subclassed button own an attribute 'index':

def _onAnyOfMyButtons_(self, event):
theResponsibleButton = event.GetEventObject()
self.t1.SetValue("Button %d was pressed. " % theResponsibleButton.index)
return

HTH
Franz GEIGER

Thanks Franz, that broke the mental logjam.
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,206
Messages
2,571,069
Members
47,675
Latest member
RollandKna

Latest Threads

Top