Pythoncard Multiple components
Andy Todd
andy47 at halfcooked.com
Fri Oct 10 10:05:13 EDT 2003
Lee Harr wrote:
> In article <37152603.0310081227.64731a0f at 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/
More information about the Python-list
mailing list