[Tutor] Critique of program

Bill Burns billburns at pennswoods.net
Thu Nov 18 13:13:03 CET 2004


On Thursday 18 November 2004 6:08 am, Kent Johnson wrote:
> Bill,
>
> To me, it seems a little strange to be using introspection every time
> you want a list of all the lineEdits. I think it would be more
> straightforward to keep a list of all the lineEdits with their
> attributes and iterate the list. This would avoid searching through
> self.__dict__ and trying to figure out what is in it.
>

Introspection.........so that's what it's called. Yes, I also thought it was 
strange that I was doing self.__dict__ all over the place. I will take a look
at making a list to store the lineEdit attributes/information.

> I'll try to sketch out this solution:
>
> Start with a list of everything you need to know about a lineEdit. This
> includes ID, OD and maybe the label you use on the form -
>
> pipes = [
>      ( '1/2"', .622),
>      ('3/4"', .824),
>      ('1"',  1.049),
>      # etc
> ]
>
> You might divide this up into four pieces, one for each page.

Like you mention, I might need to split this into four pieces. I'm sure I will
if I use a dict as many of the keys would be the same. Every type of pipe
has a 1/2", 3/4", 1", etc.

>
> Now create the forms based on data in the list, and while you do it
> create a new list (or maybe a dict, if you ever need access to a data
> about a specific lineEdit) that keeps a reference to the lineEdit and
> the data about it:
>
> lineEdits = []
> for od, id in pipes:
>      lineEdit = ... # however you create this
>      lineEdits.append( (lineEdit, od, id) )
>      # or maybe lineEdits[lineEdit] = (od, id) for a dict
>
> Now you calc loop looks like this:
>
>          for w, od, id in lineEdits:
>              length = w.displayText()
>              if length:    # Note: this is same as if not length == ""
>                 length = int(length)  # No need for str or 10
>                 x = volCalc(id, length)
>                 stack.append(x)
>
> and the clear loop is just
>
>          for w, od, id in lineEdits:
>              w.clear()
>
> Kent
>

I'll try to make some of these changes tonight, after work.

Thank you for your help!

Bill


More information about the Tutor mailing list