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
 
@@ -112,19 +112,19 @@ class CommandFilePrinter(LabelPrinter):
 
                               edbob.local_time().strftime('%Y-%m-%d_%H-%M-%S'))
 
        labels_path = os.path.join(output_dir, fn)
 
        labels_file = open(labels_path, 'w')
 

	
 
        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
 

	
 

	
 
class LabelFormatter(edbob.Object):
 
@@ -146,12 +146,29 @@ class LabelFormatter(edbob.Object):
 
class CommandFormatter(LabelFormatter):
 
    """
 
    Generic subclass of :class:`LabelFormatter` which generates native printer
 
    (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
 
        to be interpreted by the printer.  These commands will immediately
 
        precede each *label* in one-up printing, and immediately precede each
 
        *label pair* in two-up printing.
 
@@ -196,28 +213,30 @@ class TwoUpCommandFormatter(CommandFormatter):
 
        fmt = StringIO()
 

	
 
        half_started = False
 
        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()
 
        return val
 
    
 

	
0 comments (0 inline, 0 general)