473,385 Members | 1,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Returning Ref. to Runtime Created Control

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.
--
Jul 18 '05 #1
2 1252

"Gary" <pr**********************@wi.rr.com> schrieb im Newsbeitrag
news:di********************************@4ax.com...
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
Jul 18 '05 #2
On Sun, 12 Sep 2004 20:57:42 +0200, "F. GEIGER" <fg*****@datec.at> ,
created a minor stir when he wrote:

"Gary" <pr**********************@wi.rr.com> schrieb im Newsbeitrag
news:di********************************@4ax.com.. .
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.
--
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andrei Pociu | last post by:
Inside a method some controls are created at runtime. I added an event handler to one of these controls: tracker.Scroll += new System.EventHandler(this.tracker_Scroll); So in the event handler...
2
by: HealsJnr | last post by:
Hi all, Just wondering if there is any way to return a vector from a mixed mode dll? I understand that it is quite easy to pass by reference to achieve the same end, but i'd like to know if it...
1
by: DJ Dev | last post by:
Hi, I am stuck at a problem for 3 days now. I create runtime datagrids depending on the user selections and they may vary from 2-10 depending on user selection at runtime. The datagrids are...
1
by: Leo | last post by:
I created a user control which is some text contained in a HtmlTable. I put this control into main form. I would like to have the ability to move this control around in the main form. I think one...
1
by: Andy Slovak | last post by:
Hello! I am instantiating webbrowser control objects and runtime and have successfully been able to have the event handled by a shared delegate. In the event handling code, I would like to...
3
by: Developer in California | last post by:
I am working on developing a generic Web framework using Master Pages in ASP.NET 2.0. What I have done is created a PageRenderer class which has a public method which will retrieve the path of the...
4
by: rushikesh.joshi | last post by:
Hi All, I have created my own WebControl and want to add it in my aspx page at runtime. it's compiling perfectly, but when i m going to execute, it gives me error of "Object reference not set...
0
by: Rich | last post by:
Hello, I started using the Reportviewer control (very nice) for generating Reporting Services type reports in my VB2005 app. I have been experimenting using a designer Reportviewer control from...
0
by: Steven Samuel Cole | last post by:
Hello, I am writing an application that controls robots. Different robots can do different kinds of movements, such as e.g. open gripper, rotate gripper, etc. My RobotControl class should...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.