Re: regarding

From: Matt Shomphe <mshomphe_at_comcast_dot_net>
Date: Thu Jul 24 2003 - 11:05:22 CDT

I'm currently using Python 2.3rc1 -- Like Matteo said, it's stable & faster
than the 2.2 set.

I believe we may need to spend a little time designing the system. I have
an overall idea about the architecture that I'd like to run by the group:

(1) There are two user interface components: (i) the PC interface and (ii)
the Web interface
(2) There is a common output format from both (i) and (ii). Let's call it
the "Pre-Ballot". This should be in some format that's:
          a. text-based (preferably ASCII text)
                  - This will mean that it will be readable pretty much
anywhere (no special software needed)
                  - It also means it can be highly compressed, taking up
less memory on the system & less bandwith "on the wire" (if
it's being transmitted across the net)
          b. easily parse-able/translatable (like XML or LaTeX)
                  - Having a highly structured Pre-Ballot means that we
could translate it into other formats easily. If the ballot output has
to vary from state to state (or county to county), having a
common format means we would just have to write a translator
from the structured format into the target format. We'd spend
less time worrying about the output from the Web & PC interfaces.
                  - I would vote for XML in this case. There are a lot of
parsers out there, I've worked with it before, and it's a widely
used communication format. Here's an example:
          <?xml version=1.0?>
                  <ballot id="00000">
                                  <name>John Q. Public</name>
                                  <address>123 Fake Street</address>
                                  <president>Harry S Truman</president>
                                  <proposition id="a">yes</proposition>
                                  <proposition id="201">no</proposition>
This is human-readable, but also *very* easily parse-able by a machine
(pretty much every computer language has an XML parser). We'd get the
added benefit of separating the output of the program from the program
itself. So if someone didn't have Python available, they could use Java to
parse the data.

(3) The Pre-Ballot->Ballot converters. These would be specific to the

So the flow would be:
(PC, Web) -> Pre-Ballot -> Pre-Ballot Converter -> Ballot

Please give me your comments on this!

Regarding the "Print" functionality, I've done something, but I'm not sure
if it's what's wanted. It will print out an XML file called
"ballot<timestamp>.xml" to the same directory the script is running in with
an abbreviated version of the XML above.

I don't have documentation yet, but for those interested, this is how to
use it:

There is a VoteFrame object that is the main object to deal with. You
import the VoteFrame object, instantiate it, then populate the "candidate"
attribute with a list of candidates. Once that's done, call the "build()"
method, then the "run()" method.

          from vote import VoteFrame
          vf = VoteFrame()
          vf.candidates = ['Howard Dean',
                                  'George W. Bush',
                                  'John Kerry',
                                  'Richard Gephardt',
                                  'Bob Graham']

For those of you *using* this, first, double-click the file You
have to select a candidate, then push the "Vote" button. You'll get a
confirmation. Then push "Print".

Thanks for comments!

PS Matteo, I've studied pretty much every Romance language there is. The
good thing is that I can understand a lot of them. The bad thing is that I
get a mish-mash when I try speaking: "Ciao! Je devo andare aux cinema. Io
quiero muchas de popcorn." It's terrible :)

At 01:31 AM 7/24/2003 -0700, yu wang wrote:
>Hi Matteo,
> I think 2.3 is fine, you can choose whatever you are comfortable with.
> About the final release, we are not sure yet, we will see, :).
>Matteo Giacomazzi <> wrote:
>Hi Yu Wang,
>gioved?24 luglio 2003, hai scritto:
>AW> I just ran your code, it is pretty cool. I am wondering if you
>AW> would like to add one more print button to your code, which
>AW> provides printing function, then I will add your code to
>AW> as our first prototype. Thank you.
>What's the supported version of Python we are going to use?
>2.3 is a release candidate but it's pretty stable and many faster,
>although 2.2.3 is the officially stable one.
>I'm asking this because there are a few improvements in 2.3 that we
>could exploit (i.e. I'd appreciate if the final release will be
>written in Python too, not only the demo ;).
>Do you Yahoo!?
>SiteBuilder - Free, easy-to-use web site design software

- --=====================_5076379==_
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: attachment; filename=""

from Tkinter import *
from tkMessageBox import showinfo, askyesno, showerror
from random import random
from time import time
__version__ = '0.001'
There should be a collection of objects:
1. A Voter (data about the particular voter)
2. A VoteObject (a collection of data about a particular vote)
3. A VoteFrame (the interface which a voter uses)

[Note: There should also be a web interface, but this might have to
be different. It should
still generate a VoteObject.]

A VoteObject contains information about the Voter and the vote that
was recorded from the vote object.

Right now we just have the VoteFrame.

VoteFrame APIs:
(1) attributes
- - candidates -> A list or tuple of candidate names
- - actions -> This is the list of buttons and their associated
actions. [['text of button', action]]
It may be better if this isn't exposed.

(2) methods
- - build() -> creates the object
- - run() -> starts the object
- - onVote() -> Actions associated with "Vote" button
- - onQuit() -> quit behavior
- - onPrint() -> print behavior (undef right now).

class BallotObject:
     def __init__(self, voterid):
         self.voterid = voterid
         self.president = None = int(time())
     def ballot(self):
         s = '''
<?xml version="1.0"?>
     <vote id="%s">
         <voter id="%s"/>
         ''' % (, self.voterid, self.president)

class Voter:

class VoteFrame(Frame):
     def __init__(self, parent=None):
         Frame.__init__(self, parent)
         self.candidates = []
         self.actions = [['Vote', self.onVote],
                         ['Quit', self.onQuit],
                         ['Print', self.onPrint]]
         self.var =StringVar()
         self.otherstr ='Other'
         self.voter = str(random())[2:] # generate a random ID
         self.ballot = BallotObject(self.voter)
     def build(self):
         'Creates the VoteFrame object'
         Label(self, text='Vote For President!').pack()
         self.master.title('Voter v%s' %__version__)
     def run(self):
         'runs mainloop'
     def __buildCandidates(self, event=None):
         candidates = self.candidates
         if not candidates:
             raise ValueError, (1, 'Failed to provide the object with

         for candidate in candidates:
             row = Frame(self)
             Radiobutton(row, text=candidate, variable=self.var,
             row.pack(side=TOP, fill=BOTH)
         other = self.otherstr
         row = Frame(self)
         Radiobutton(row, text=other, variable=self.var,
         eRow = Entry(row)
         eRow.pack(side=RIGHT, fill=X, expand=YES)
         row.pack(fill=X, expand=YES)
     def __buildActions(self):
         actions = self.actions
         row = Frame(self)
         for action in actions:
             txt, act = action

             Button(row, text=txt, command=act).pack(side=LEFT)
     def onVote(self, event=None):
         Called when the "Vote" button is pressed. In theory,
         this should create a "VoteObject" that can be printed or handled
         in some way.
         v = self.var.get()
         if v == self.otherstr:
             v = self.other.get()
         if not v:
             showerror('Error!', 'You need to pick someone to vote for!')

         showinfo('You voted for...', v)
     def onQuit(self, event=None):
         if askyesno('Verify Quit', 'Really quit?'): Frame.quit(self)
     def onPrint(self, event=None):
         Prints to a file named "ballot<timestamp>"
         filename = 'ballot%s.xml'%int(time())
         open(filename, 'w').write(self.ballot.ballot())

if __name__ == '__main__':
     vf = VoteFrame()
     vf.candidates = ['Howard Dean',
                      'George W. Bush',
                      'John Kerry',
                      'Richard Gephardt',
                      'Bob Graham']

- --=====================_5076379==_--
Received on Thu, 24 Jul 2003 09:05:22 -0700

This archive was generated by hypermail 2.1.8 : Wed Aug 06 2003 - 12:50:26 CDT