[Tutor] Posting a large amount of code?
Alan Gauld
alan.gauld at freenet.co.uk
Sun Jan 16 19:28:36 CET 2005
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 G.
More information about the Tutor
mailing list