Pvote 1.0b: Printer.py

 
 
1 
2 
3 
 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 

# $ Id: Printer.py,v 1.1 2008/09/08 09:40:03 ping Exp $

class Printer:
    def __init__(self, text):
        self.text = text

    def write(self, selections):
        for [group_i, selection] in enumerate(selections):
            group = self.text.groups[group_i]
            if group.writein:
                if len(selection):
                    print "\n+ " + group.name
                    line = ""
                    for option_i in selection:
                        if len(line) + len(group.options[option_i]) + 1 > 60:
                            print "= " + line
                            line = ""
                        line = line + group.options[option_i] + "~"
                    print "= " + line
            else:
                if len(selection):
                    print "\n* " + group.name
                    for [option_i, option] in enumerate(group.options):
                        if option_i in selection:
                            print "- " + option
                else:
                    print "\n* " + group.name + " ~ NO SELECTION"
        print "\n~\f"