469,304 Members | 2,303 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,304 developers. It's quick & easy.

Pythoncard Multiple components

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 :)"
Jul 18 '05 #1
2 1941
In article <37**************************@posting.google.com >, 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.

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".

Jul 18 '05 #2
Lee Harr wrote:
In article <37**************************@posting.google.com >, 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.

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
--
--------------------------------------------------------------------------------
From the desk of Andrew J Todd esq - http://www.halfcooked.com/

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Oriana | last post: by
2 posts views Thread by PipedreamerGrey | last post: by
reply views Thread by fiddlehead | last post: by
1 post views Thread by DarkBlue | last post: by
4 posts views Thread by Tequila | last post: by
8 posts views Thread by king kikapu | last post: by
8 posts views Thread by Kevin Walzer | last post: by
3 posts views Thread by Michal Lipinski | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.