def process_set_list(self, *args, text="", search=False): from kivymd.uix.progressbar import MDProgressBar pb = MDProgressBar(type="determinate", running_duration=1, catching_duration=1.5) status_bar = get_app().modellist_controller.screen.status_bar status_bar.clear_widgets() status_bar.add_widget(pb) pb.start() Clock.schedule_once( partial(self.set_list, self, *args, text=text, search=search)) pb.stop()
def pdfimages(pdfpath, cmds, instance, *args): pb = MDProgressBar(color=get_app().theme_cls.primary_color, type="indeterminate") status_bar = get_app().image_selection_controller.status_bar status_bar.clear_widgets() status_bar.add_widget(pb) pb.start() pdfdir = Path(pdfpath.split('.')[0]) makedirs(pdfdir, exist_ok=True) params = [] children = instance.parent.parent.parent.parent.content_cls.children process = cmds["pdfimages"] for idx, child in enumerate(reversed(children)): if idx == 6: for fileformat in child.children: if fileformat.state == 'down': params.extend([f"-{fileformat.text}"]) if idx == 2 and child.text != "": params.extend(["-f", child.text]) if idx == 4 and child.text != "": params.extend(["-l", child.text]) if idx == 9 and child.ids['_left_container'].children[0].active: params.extend(["-p"]) if idx == 8: for convprocess in child.children: if convprocess.state == 'down': if convprocess.text == "rendering": process = cmds["pdftoppm"] else: process = cmds["pdfimages"] fileformat.text = "j" if fileformat.text == "jpeg" else fileformat.text fileformat.text = "jpeg" if fileformat.text == "jp2" else fileformat.text p1 = Popen([process, *params, pdfpath, pdfdir.joinpath(pdfdir.name)]) p1.communicate() get_app().image_selection_controller.file_chooser._update_files() get_app().image_selection_controller.add_images([pdfdir]) pb.stop()
def pdfimages(pdfpath, cmds, instance, ocr, *args): """ Converts the pdf to images""" pb = MDProgressBar(color=get_app().theme_cls.primary_color, type="indeterminate") status_bar = get_app().image_selection_controller.status_bar status_bar.clear_widgets() status_bar.add_widget(pb) pb.start() if ocr: tmpdir = tempfile.TemporaryDirectory() pdfdir = Path(tmpdir.name) else: pdfdir = Path(pdfpath.split('.')[0]) makedirs(pdfdir, exist_ok=True) params = [] children = instance.parent.parent.parent.parent.content_cls.children process = cmds["pdfimages"] for idx, child in enumerate(reversed(children)): if idx == 6: for fileformat in child.children: if fileformat.state == 'down': params.extend([f"-{fileformat.text}"]) if idx == 2 and child.text != "": params.extend(["-f", child.text]) if idx == 4 and child.text != "": params.extend(["-l", child.text]) if idx == 9 and child.ids['_left_container'].children[0].active: params.extend(["-p"]) if idx == 8: for convprocess in child.children: if convprocess.state == 'down': if convprocess.text == "rendering": process = cmds["pdftoppm"] else: process = cmds["pdfimages"] params = " ;".join(params).replace('-jpeg', '-j').split(' ;') p1 = Popen([ process, *params, pdfpath, pdfdir.joinpath(Path(pdfpath.split('.')[0]).name) ]) p1.communicate() get_app().image_selection_controller.file_chooser._update_files() if not ocr: get_app().image_selection_controller.add_images([pdfdir]) else: images = list(pdfdir.glob('*.*')) tc_screen = get_app().tesseract_controller thread = tc_screen.recognize_thread(None, file_list=images, profile={ 'outputformats': ['pdf'], 'groupfolder': '', 'subforlder': False, 'print_on_screen': False }) thread.join() p2 = Popen([ cmds["pdfunite"], *sorted(list(pdfdir.glob('*.pdf'))), pdfpath[:-3] + "ocr.pdf" ]) p2.communicate() get_app().image_selection_controller.file_chooser._update_files() pb.stop()