Re: regarding vote.py

From: Adrianne Wang <xinxin_2000_at_yahoo_dot_com>
Date: Fri Jul 25 2003 - 03:04:29 CDT

Adrianne

Matt Shomphe wrote:

> 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">
> <voter>
> <name>John Q. Public</name>
> <address>123 Fake Street</address>
> <city>Somewhere</city>
> <state>CA</state>
> <zipcode>00001</zipcode>
> </voter>
> <vote>
> <president>Harry S Truman</president>
> <proposition id="a">yes</proposition>
> <proposition id="201">no</proposition>
> <vote>
> </ballot>
> 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
> district.
>
> 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.
>
> Example:
> from vote import VoteFrame
> vf = VoteFrame()
> vf.candidates = ['Howard Dean',
> 'George W. Bush',
> 'John Kerry',
> 'Richard Gephardt',
> 'Bob Graham']
>
> vf.build().run()
>
> For those of you *using* this, first, double-click the file vote.py.
> You have to select a candidate, then push the "Vote" button. You'll
> get a confirmation. Then push "Print".
>
> Thanks for comments!
> Matt
>
> 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, :).
>>
>>
>> Adrianne
>>
>> Matteo Giacomazzi <giacomazzi@programmazione.it> 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> sourceforge.net 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 ;).
>>
>> --
>> Ciao,
>> Matteo
>> mailto:giacomazzi@programmazione.it
>>
>>
>> Do you Yahoo!?
>> <http://us.rd.yahoo.com/evt=10469/*http://sitebuilder.yahoo.com>Yahoo!
>> SiteBuilder - Free, easy-to-use web site design software
>
>------------------------------------------------------------------------
>
>from Tkinter import *
>from tkMessageBox import showinfo, askyesno, showerror
>from random import random
>from time import time
>__version__ = '0.001'
>COMMENTS = '''
>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
> self.id = int(time())
> def ballot(self):
> s = '''
><?xml version="1.0"?>
> <vote id="%s">
> <voter id="%s"/>
> <ballot>
> <president>%s</president>
> </ballot>
> </vote>
> ''' % (self.id, self.voterid, self.president)
> return(s.strip())
>
>
>class Voter:
> pass
>
>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.other=None
> 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.__buildCandidates()
> self.__buildActions()
> self.master.title('Voter v%s' %__version__)
> self.pack()
> return(self)
> def run(self):
> 'runs mainloop'
> self.mainloop()
> def __buildCandidates(self, event=None):
> candidates = self.candidates
> if not candidates:
> raise ValueError, (1, 'Failed to provide the object with
>cadidates')
>
> for candidate in candidates:
> row = Frame(self)
> Radiobutton(row, text=candidate, variable=self.var,
>value=candidate).pack(side=LEFT,fill=X)
> row.pack(side=TOP, fill=BOTH)
> other = self.otherstr
> row = Frame(self)
> Radiobutton(row, text=other, variable=self.var,
>value=other).pack(side=LEFT)
> eRow = Entry(row)
> eRow.pack(side=RIGHT, fill=X, expand=YES)
> row.pack(fill=X, expand=YES)
> self.other=eRow
> 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)
> row.pack()
> return(None)
> 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()
> self.other.delete(0,END)
> if not v:
> showerror('Error!', 'You need to pick someone to vote for!')
> return(None)
>
> showinfo('You voted for...', v)
> self.ballot.president=v
> return(None)
> 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())
> return(None)
>
>if __name__ == '__main__':
> vf = VoteFrame()
> vf.candidates = ['Howard Dean',
> 'George W. Bush',
> 'John Kerry',
> 'Richard Gephardt',
> 'Bob Graham']
>
> vf.build().run()
>
>
Received on Fri, 25 Jul 2003 01:04:29 -0700

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