Changeset - 4e81a4fc5cdf
[Not reviewed]
0 1 0
Lance Edgar (lance) - 12 years ago 2012-08-31 11:54:11
lance@edbob.org
add progress to labels.TwoUpCommandFormatter
1 file changed with 19 insertions and 4 deletions:
0 comments (0 inline, 0 general)
rattail/labels.py
Show inline comments
 
@@ -142,7 +142,7 @@ class LabelFormatter(edbob.Object):
 
    format = None
 

	
 
    @requires_impl()
 
    def format_labels(self, labels, *args, **kwargs):
 
    def format_labels(self, labels, progress=None, *args, **kwargs):
 
        """
 
        Formats ``labels`` and returns the result.
 
        """
 
@@ -231,12 +231,17 @@ class TwoUpCommandFormatter(CommandFormatter):
 

	
 
        pass
 

	
 
    def format_labels(self, labels):
 
    def format_labels(self, labels, progress=None):
 
        prog = None
 
        if progress:
 
            prog = progress("Formatting labels", len(labels))
 

	
 
        fmt = StringIO()
 

	
 
        cancel = False
 
        half_started = False
 
        for product, quantity in labels:
 
            for i in range(quantity):
 
        for i, (product, quantity) in enumerate(labels, 1):
 
            for j in range(quantity):
 
                if half_started:
 
                    fmt.write('%s\n' % '\n'.join(
 
                            self.label_body_commands(product, x=self.half_offset)))
 
@@ -251,6 +256,16 @@ class TwoUpCommandFormatter(CommandFormatter):
 
                    fmt.write('%s\n' % '\n'.join(
 
                            self.label_body_commands(product, x=0)))
 
                    half_started = True
 
            if prog and not prog.update(i):
 
                cancel = True
 
                break
 

	
 
        if prog:
 
            prog.destroy()
 

	
 
        if cancel:
 
            fmt.close()
 
            return None
 

	
 
        if half_started:
 
            footer = self.label_footer_commands()
0 comments (0 inline, 0 general)