Example #1
0
def processmanager(processname:str):
    """ Displaying active background process to the user"""
    pm = ProcessManagerItem()
    boxlayout = BoxLayout(orientation="vertical")
    main_label = MDLabel(
        text="Process running",
        theme_text_color= "Custom",
        text_color= (1, 1, 1, 1),
        size_hint_y= None,
        adaptive_height= True,
        )
    boxlayout.add_widget(main_label)
    sep = MDSeparator(height= "1dp", color='cyan')
    boxlayout.add_widget(sep)
    process_label = MDLabel(text= processname,
                            theme_text_color= "Custom",
                            text_color= (1, 1, 1, 1),)
    boxlayout.add_widget(process_label)
    boxlayout2 = BoxLayout(orientation= "vertical")
    pb = MDProgressBar(type= "determinate", running_duration= 1, catching_duration= 1.5)
    boxlayout2.add_widget(pb)
    pb.start()
    boxlayout.add_widget(boxlayout2)
    pm.add_widget(boxlayout)
    return pm
 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()
Example #3
0
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()
Example #4
0
def download_with_progress(url, file_path, on_success, color="#54B3FF"):
    """ Downloader helper customized for the needs """
    pb = MDProgressBar(color=color)
    status_bar = get_app().image_selection_controller.status_bar
    status_bar.clear_widgets()
    status_bar.add_widget(pb)
    pb.max = 1
    pb.min = 0
    pb.start()

    def update_progress(request, current_size, total_size):
        pb.value = current_size / total_size
        if pb.value == 1:
            pb.stop()

    try:
        UrlRequest(url=requests.get(url).url,
                   on_progress=update_progress,
                   chunk_size=1024,
                   on_success=on_success,
                   on_failure=download_error,
                   file_path=file_path)
    except:
        download_error()
Example #5
0
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()