Pythoncard Multiple components

A

Adrian Smith

I am using pythoncard 0.7.2 for windows.

I am trying to use the same code for a large number of buttons so
started out by using
def on_mouseDown(self,event):

but then I need to display the button that I pressed but you can only
have an absolute component name like:
self.component.Button1.label = "clicked"

How can I identify the button pressed and still use the same procedure
to update the clicked button? I tried self.component.label =
"clicked" with out the reference to the actual button used?

Any ideas, especially snippets of code if you have to start using
self.components.data etc.

A second question occurres: Is it possible to create a component at
run time? If so how would you start.
Thanks


"Python... the way C++ programming should be :)"
 
L

Lee Harr

I am using pythoncard 0.7.2 for windows.

I am trying to use the same code for a large number of buttons so
started out by using
def on_mouseDown(self,event):

but then I need to display the button that I pressed but you can only
have an absolute component name like:
self.component.Button1.label = "clicked"

How can I identify the button pressed and still use the same procedure
to update the clicked button? I tried self.component.label =
"clicked" with out the reference to the actual button used?

Any ideas, especially snippets of code if you have to start using
self.components.data etc.

I have a pythoncard app where I want to know which of a (large)
number of checkboxes gets clicked. I do something like:

def on_mouseClick(self, event):
name = event.target.name
if name in self.availability.times:
button = getattr(self.components, name)
avail = self.availability.avail[name]
#print dir(button)
if button.checked:
if button.backgroundColor == AVAIL:
self.availability.avail[name] = 1
else:
self.availability.avail[name] = 0
button.backgroundColor = (255, 255, 255)
else:
if self.availability.avail[name]:
button.backgroundColor = AVAIL
else:
button.backgroundColor = UNAVAIL


Notice my comment #print dir(button) I use those quite often
when doing pythoncard just to see what it is that I have a
handle on, and what I can do with it.



A second question occurres: Is it possible to create a component at
run time? If so how would you start.
Thanks

I am pretty sure that the pythoncard resource editor is written in
pythoncard, so I would say "yes" and "read the pythoncard source code".
 
A

Andy Todd

Lee said:
I am using pythoncard 0.7.2 for windows.

I am trying to use the same code for a large number of buttons so
started out by using
def on_mouseDown(self,event):

but then I need to display the button that I pressed but you can only
have an absolute component name like:
self.component.Button1.label = "clicked"

How can I identify the button pressed and still use the same procedure
to update the clicked button? I tried self.component.label =
"clicked" with out the reference to the actual button used?

Any ideas, especially snippets of code if you have to start using
self.components.data etc.


I have a pythoncard app where I want to know which of a (large)
number of checkboxes gets clicked. I do something like:

def on_mouseClick(self, event):
name = event.target.name
if name in self.availability.times:
button = getattr(self.components, name)
avail = self.availability.avail[name]
#print dir(button)
if button.checked:
if button.backgroundColor == AVAIL:
self.availability.avail[name] = 1
else:
self.availability.avail[name] = 0
button.backgroundColor = (255, 255, 255)
else:
if self.availability.avail[name]:
button.backgroundColor = AVAIL
else:
button.backgroundColor = UNAVAIL


Notice my comment #print dir(button) I use those quite often
when doing pythoncard just to see what it is that I have a
handle on, and what I can do with it.




A second question occurres: Is it possible to create a component at
run time? If so how would you start.
Thanks


I am pretty sure that the pythoncard resource editor is written in
pythoncard, so I would say "yes" and "read the pythoncard source code".

If in doubt, run your application with the shell (-s on the command
line) and have a look. Its a great tool and by far the best way to find
out what is going on 'under the hood'. With the message watcher (-m) and
the namespace viewer (-n) as well you have a full run time inspection
environment.

Yes, you can add components at run time, look at the example on the
documentation page
(http://pythoncard.sourceforge.net/text/addmethod.txt) and the dbBrowser
sample application.

As a final observation, PythonCard comes with its own logging module
(similar to the standard module in 2.3) and can be used instead of
'print' statements for a more persistent record of what your application
is doing. See log.py in the PythonCard distribution for information.

Regards,
Andy
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top