On Sunday 16 January 2005 1:28 pm, Alan Gauld wrote:
> Some quick feedback based on a quick scim through.
>
> It looks like your pipe logic is all mixed up with the GUI vpde.
>
> It would be a god excercise to extract all the p[ipe code into
> a separate class and the GUI methods call those class methods
> to get the work done. THis would allow for a fairly easy port
> to a different GUI or even the creation of a command line
> version, so you could do:
>
> bash$ pipestats.py  --content-weight 15 12
> bash$ pipestats.py --summary 22 1/2
>
> If you then put that pipe object in a separate module you
> could extend it for future projects...
>
> Separating all GUI code from the logical functions is
> always a good idea. Simply get the GUI to reference an
> instance of the pipe(having selected the sizes and passed
> them in as constructor values maybe?)
>
> >     def galCalc(self):
> >         """Displays a running tally of the total gallons for all
> >            pipe entered into each lineEdit. Recalculates whenever
> >            the data changes in any of the lineEdits.
> >         """
> >         tmp = []
> >         for ins, name, typ, size, weight, ID in self.lineEdits:
> >             if name != "lineEditTotal":
> >                 length = ins.displayText()
> >                 if length:
> >                     length = int(str(length),10)
> >                     gal = self.volCalc(ID, length)
> >                     tmp.append(gal)
> >         total = sum(tmp)
> >         total = "%0.2f" % total
> >         self.lineEditTotal.setText(total)
>
> This is just an example, see how both the calculation and the
> display of the result(*) are mixed up in the same method?
> It would be good to split up the code to have a method
> that does the calculation and returns the result and
> another that calls the first and puts the result into
> the GUI. This may require that you pass more parameters
> into the calculation metjods but the gain in separation
> is worth it IMHO.
>
> (*)Not knowing Qt I'm assuming that the setText() is a GUI method!
> If it isn't I may be drawing invalid conclusions.

Alan,

You're exactly right setText() is a GUI method. I do have the pipe logic all
mixed up with the GUI code. Now that you point it out, most of my methods
don't have a return statement. They are completely dependant on the GUI
and wouldn't function without it. Virtually all the methods act directly upon
the GUI.

If I'm  understanding you correctly, I should have methods more along the
lines of this one (which is in my code now):

def volCalc(self, ID, length):
        """Calculates the volume/gallons of water inside of
           the various pipe.
        """
        from math import pi
        gal = ((ID*.5)**2)*pi*(12*length)/(230.9429931) 
        return gal

It does it's 'job', return a result and is not effected  by the GUI at all. I 
guess you could actually import this function into the interpreter and use it
without problems. But if you tried doing that with the other function above
(galCalc()) it wouldn't work out quite so well....

I'll have to see what I can do to take a step in this direction. It might take
my a little while :-)

Thank you for your help!

Bill







_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to