Skip to content

Commit

Permalink
Ability to change output filename of BrotherQLReader
Browse files Browse the repository at this point in the history
The member variable filename_fmt now holds the relevant
format template and can be changed after instatiation.
  • Loading branch information
pklaus committed Aug 8, 2018
1 parent 6a94465 commit 9e93664
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions brother_ql/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def merge_specific_instructions(chunks, join_preamble=True, join_raster=True):
return new_instructions

class BrotherQLReader(object):
DEFAULT_FILENAME_FMT = 'label{counter:04d}.png'

def __init__(self, brother_file):
if type(brother_file) in (str,):
Expand All @@ -237,10 +238,11 @@ def __init__(self, brother_file):
self.black_rows = []
self.red_rows = []
self.compression = False
self.page = 1
self.page_counter = 1
self.two_color_printing = False
self.cut_at_end = False
self.high_resolution_printing = False
self.filename_fmt = self.DEFAULT_FILENAME_FMT

def analyse(self):
instructions = self.brother_file.read()
Expand Down Expand Up @@ -324,7 +326,7 @@ def get_im(rows):
im_red.paste(im_black, (0, 0), im_black)
im = im_red
im = im.transpose(Image.FLIP_LEFT_RIGHT)
img_name = 'page{:04d}.png'.format(self.page)
img_name = self.filename_fmt.format(counter=self.page_counter)
im.save(img_name)
print('Page saved as {}'.format(img_name))
self.page += 1
self.page_counter += 1

0 comments on commit 9e93664

Please sign in to comment.