def dlTutAll(): msg = 'This will download all available tutorials as separate files.\nDo you wish to continue?' title = 'Download All?' if eg.ccbox(msg, title, image=imgTC): msg = 'Choose where you want the downloads to be kept:' path = eg.diropenbox(msg, default=os.getcwd() + os.sep + os.pardir) maker.makePDFfromList(tutList, path)
def dlTutSome(): # TODO title = 'Custom Range Download' msg = 'Download a custom ranges of tutorials.\nThe standard printer ranges should work. (For details see How-To)' rep = eg.enterbox(msg, title, strip=True) rep = re.split(r',+', rep) rep = [x.strip() for x in rep if x != ''] rep_ranges = [x for x in rep if re.match(r'\d+\s*-+\s*\d+', x) != None] rep_single = [x for x in rep if x not in rep_ranges and re.match(r'\d+', x) != None] rep_ranges = [re.sub(r'\s*', '', x) for x in rep_ranges] rep_ranges = set(rep_ranges) rep_single = set(rep_single) rep_new = set() for repp in rep_single: rep_new.add(int(repp)) for repp in rep_ranges: first, last = tuple(re.findall(r'\d+', repp)) first, last = int(first), int(last) if first > last: first, last = last, first # where python made my day for x in xrange(first, last+1): rep_new.add(x) rep_new = sorted(list(rep_new)) tutListNew = [] for repp in rep_new: tutListNew.append(tutList[repp-1]) # some cleanup del rep, rep_ranges, rep_single, rep_new re.purge() maker.makePDFfromList(tutListNew)