Changeset 17757 in niluje


Ignore:
Timestamp:
Sep 10, 2020, 2:49:39 PM (10 days ago)
Author:
NiLuJe
Message:

Make it an actual progressbar ;).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Configs/trunk/Kindle/Kobo_Hacks/Patches/koreader_to_nickel.py

    r17756 r17757  
    2424print("Loaded FBInk {}".format(ffi.string(FBInk.fbink_version()).decode("ascii")))
    2525
     26# We'll need to know the amount of available rows, in order to not stomp on the progress bar...
     27fbink_state = ffi.new("FBInkState *")
     28FBInk.fbink_get_state(fbink_cfg, fbink_state)
     29
    2630# Display msg on screen & in terminal
    2731def log(msg):
     
    3135        if lines > 0:
    3236                fbink_cfg.row += lines
     37
     38        # If we'd be stomping on the progress bar, add one more line to skip over it ;)
     39        if fbink_cfg.row % (fbink_state.max_rows - 1) == 0:
     40                fbink_cfg.row += 1
     41
     42# Display a progress bar on the last row, without forgetting our current actual row
     43def progressbar(value):
     44        cur_row = fbink_cfg.row
     45        fbink_cfg.row = -1
     46        FBInk.fbink_print_progress_bar(fbfd, value, fbink_cfg)
     47        fbink_cfg.row = cur_row
    3348
    3449# Where KOReader lives
     
    94109book_total = len(history)
    95110for book in history.values():
    96         book_i+=1
     111        # Make the counter a percentage
     112        book_i += 1
     113        spinner = int(book_i / book_total * 100)
    97114
    98115        f = book["file"]
    99         print("* Checking `{}`".format(f))
     116        print("[{:3d}%] Checking `{}`".format(spinner, f))
     117        # And update the progressbar...
     118        progressbar(spinner)
    100119
    101120        # Get metadata sidecar file...
     
    120139                continue
    121140
    122         # Make the counter a percentage
    123         spinner = int(book_i / book_total * 100)
    124141        # Okay!
    125142        if "authors" in meta["doc_props"].keys():
     
    129146                if "\\\n" in author:
    130147                        author = author.replace("\\\n", " & ")
    131                 log("[{:3d}%] Marking `{}` by `{}` as read".format(spinner, meta["doc_props"]["title"], author))
     148                log("Marking `{}` by `{}` as read".format(meta["doc_props"]["title"], author))
    132149        else:
    133                 log("[{:3d}%] Marking `{}` as read".format(spinner, meta["doc_props"]["title"]))
     150                log("Marking `{}` as read".format(meta["doc_props"]["title"]))
    134151
    135152        # Convert the last open date into a mostly-accurate representation of the SQL format...
     
    166183                print("SQL update failed!")
    167184
    168 log("[100%] Done!")
     185log("Done!")
    169186FBInk.fbink_close(fbfd)
Note: See TracChangeset for help on using the changeset viewer.