[Tutor] Request for Comments

Faulconer, Steven M. STEVEN.M.FAULCONER at saic.com
Fri Jul 30 21:29:30 CEST 2004


Michael,

Thank you very much for your comments. I'm going to work them into my
program. I had initially created a command-line version of this program that
contained the checkers in a dictionary, and ran them based on menu
selections. I didn't see a clean way of doing that in this program, but now
I do.

Thanks again.

-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On Behalf
Of Michael Lange
Sent: Thursday, July 29, 2004 6:12 AM
To: tutor at python.org
Subject: Re: [Tutor] Request for Comments


On Tue, 27 Jul 2004 11:23:16 -0700
"Faulconer, Steven M." <STEVEN.M.FAULCONER at saic.com> wrote:

> I'd like to have a better way of creating the gui elements. Since 
> there are currently 5 checkers, I've got a lengthy bit of code to 
> create the widgets. It would be nice to have a method that loops over 
> a data structure
> (dictionary/list) and builds the gui elements from the contents. I'll have
> to work on that for the next version.
> 
Hi, Steven,

you currently have five methods in your CheckerApp class that look all the
same; I think you might replace these with a single method like this:

def RunChecker(self, checkerName):
    if checker in self.checkerNames:# with self.checkerNames as a list that
contains the possible checkers
        # Build the commandline sequence
        command = self.SSBIN + self.BINPATH + checkerName + self.PROJPATH +
\
                  self.PROJECT + ".prj" + " " + path.joinpath( self.DBPATH,
self.DATABASE )

        # Build the path to the report file
        report = self.DBPATH.joinpath( self.DATABASE ) + ".cnt"

        # If the report file exists, remove it. The creation of the report
file
        # is used to determine if the program ran correctly.
        if exists( report ):
            remove( report )

        # Run the checker command
        CheckerWindow( self.newroot, self, checkerName, command, report )

The same should be possible for creating the gui elements if you add a class
that contains all the elements you need for the five checkers:

class CheckerGroup(Tkinter.Frame):
    def __init__(self, master, checkerName, **kw):
        Tkinter.Frame.__init__(self, master, **kw)

        # replace attributes of the CheckerApp class with something
appropriate in the code below

        self.fnd_dup_group = Pmw.Group( master, tag_text = title )
        self.fnd_dup_group.pack( pady = 2, padx = 2, expand = 'yes', fill =
'both' )
        self.fnd_dup_run = Tkinter.StringVar()

        if self.OPTIONS['find_dup_feat'][ 0 ] == "":
            self.fnd_dup_run.set( "Last ran on : Never" )
        else:
            self.fnd_dup_run.set( "Last ran on : " +
self.OPTIONS['find_dup_feat'][ 0 ] )
        Tkinter.Label( self.fnd_dup_group.interior(),
                       textvariable = self.fnd_dup_run ).pack( anchor =
Tkinter.W )
        self.fnd_dup_btns = Pmw.ButtonBox( self.fnd_dup_group.interior() )
        self.fnd_dup_btns.pack( fill = 'both', expand = 'yes', padx = 5,
pady = 5 )
        self.fnd_dup_btns.add( 'Run Checker',
                                 command = lambda
                                 arg1 = 'find_dup_feat':
                                 self.RunChecker( arg1 ) )
        self.fnd_dup_btns.add( 'View Report', command = lambda
                                              arg1 = "find_dup_feat":
                                              self.ViewReport( arg1 ) )

then you could write in the CheckerApp class something like:

self.checkers = {}# collect the CheckerGroups in a dictionary to keep a
reference for checker in self.checkerNames:
    newchecker = CheckerGroup(self.newroot, checker)
    newchecker.pack()
    self.checkers[checker] = newchecker

(now that I've written this I think that maybe a dictionary might be better
than a list for self.checkerNames, and maybe the RunChecker() method should
be an attribute of the CheckerGroup class rather than one of CheckerApp;
anyway, I guess you'll see my point.)

I hope this helps

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


More information about the Tutor mailing list