Changeset - e88fc272862c
[Not reviewed]
0 1 0
Lance Edgar (lance) - 12 years ago 2012-08-20 11:28:43
lance@edbob.org
add (basic) "one-up" label printing support
1 file changed with 27 insertions and 8 deletions:
0 comments (0 inline, 0 general)
rattail/labels.py
Show inline comments
 
@@ -115,13 +115,13 @@ class CommandFilePrinter(LabelPrinter):
 

	
 
        header = self.batch_header_commands()
 
        if header:
 
            print >> labels_file, '\n'.join(header)
 
            labels_file.write('%s\n' % '\n'.join(header))
 

	
 
        print >> labels_file, self.formatter.format_labels(labels)
 
        labels_file.write(self.formatter.format_labels(labels))
 

	
 
        footer = self.batch_footer_commands()
 
        if footer:
 
            print >> labels_file, '\n'.join(footer)
 
            labels_file.write('%s\n' % '\n'.join(footer))
 

	
 
        labels_file.close()
 
        return labels_path
 
@@ -149,6 +149,23 @@ class CommandFormatter(LabelFormatter):
 
    (textual) commands.
 
    """
 

	
 
    def format_labels(self, labels):
 
        fmt = StringIO()
 

	
 
        for product, quantity in labels:
 
            for i in range(quantity):
 
                header = self.label_header_commands()
 
                if header:
 
                    fmt.write('%s\n' % '\n'.join(header))
 
                fmt.write('%s\n' % '\n'.join(self.label_body_commands(product)))
 
                footer = self.label_footer_commands()
 
                if footer:
 
                    fmt.write('%s\n' % '\n'.join(footer))
 

	
 
        val = fmt.getvalue()
 
        fmt.close()
 
        return val
 

	
 
    def label_header_commands(self):
 
        """
 
        This method, if implemented, must return a sequence of string commands
 
@@ -199,22 +216,24 @@ class TwoUpCommandFormatter(CommandFormatter):
 
        for product, quantity in labels:
 
            for i in range(quantity):
 
                if half_started:
 
                    print >> fmt, '\n'.join(self.label_body_commands(product, x=self.half_offset))
 
                    fmt.write('%s\n' % '\n'.join(
 
                            self.label_body_commands(product, x=self.half_offset)))
 
                    footer = self.label_footer_commands()
 
                    if footer:
 
                        print >> fmt, '\n'.join(footer)
 
                        fmt.write('%s\n' % '\n'.join(footer))
 
                    half_started = False
 
                else:
 
                    header = self.label_header_commands()
 
                    if header:
 
                        print >> fmt, '\n'.join(header)
 
                    print >> fmt, '\n'.join(self.label_body_commands(product, x=0))
 
                        fmt.write('%s\n' % '\n'.join(header))
 
                    fmt.write('%s\n' % '\n'.join(
 
                            self.label_body_commands(product, x=0)))
 
                    half_started = True
 

	
 
        if half_started:
 
            footer = self.label_footer_commands()
 
            if footer:
 
                print >> fmt, '\n'.join(footer)
 
                fmt.write('%s\n' % '\n'.join(footer))
 

	
 
        val = fmt.getvalue()
 
        fmt.close()
0 comments (0 inline, 0 general)