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
 
@@ -139,13 +139,13 @@ class LabelFormatter(edbob.Object):
 
    Base class for all label formatters.
 
    """
 

	
 
    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.
 
        """
 

	
 
        pass
 

	
 
@@ -228,18 +228,23 @@ class TwoUpCommandFormatter(CommandFormatter):
 
        The X-coordinate value by which the second label should be offset, when
 
        two labels are printed side-by-side.
 
        """
 

	
 
        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)))
 
                    footer = self.label_footer_commands()
 
                    if footer:
 
                        fmt.write('%s\n' % '\n'.join(footer))
 
@@ -248,12 +253,22 @@ class TwoUpCommandFormatter(CommandFormatter):
 
                    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, 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()
 
            if footer:
 
                fmt.write('%s\n' % '\n'.join(footer))
 

	
0 comments (0 inline, 0 general)