diff options
author | benadha <benawiadha@gmail.com> | 2021-02-02 19:35:54 +0700 |
---|---|---|
committer | benadha <benawiadha@gmail.com> | 2021-02-02 19:35:54 +0700 |
commit | 2d87cda4b5cbcfe01dfa92addca68a96e1dd0720 (patch) | |
tree | 2e270f107f2a6d4de91d6d5a4575d755d205c64a | |
parent | 3d4ab0f6675be663124b3322582da254953acd6d (diff) | |
parent | aac7813abc0ceaedbbca37a0b898ae161b6e8c0f (diff) | |
download | epy-2d87cda4b5cbcfe01dfa92addca68a96e1dd0720.tar.gz |
Merge doublespread
-rw-r--r-- | README.md | 7 | ||||
-rwxr-xr-x | epy.py | 90 |
2 files changed, 76 insertions, 21 deletions
@@ -16,6 +16,7 @@ This is just a fork of my own [epr](https://github.com/wustho/epr) with these ex - External dictionary integration (`sdcv` or `dict`) - Inline formats: **bold** and _italic_ (depend on terminal and font capability. Italic only supported in python>=3.7) - Text-to-Speech (with additional setup, read [below](#text-to-speech)) +- [Double Spread](#double-spread) # Installation @@ -78,4 +79,8 @@ $ yay -S svox-pico-bin $ pacman -S sox ``` -And then make sure `pico2wave` and `play` is in `$PATH`.
\ No newline at end of file +And then make sure `pico2wave` and `play` is in `$PATH`. + +# Double Spread + +Double spread is intended to mimic the behaviour of real book, so line scrolling navigation will act as scrolling page.
\ No newline at end of file @@ -14,7 +14,7 @@ Options: """ -__version__ = "2021.2.2" +__version__ = "2021.2.3" __license__ = "GPL-3.0" __author__ = "Benawi Adha" __email__ = "benawiadha@gmail.com" @@ -59,6 +59,7 @@ CFG = { "DictionaryClient": "auto", "ShowProgressIndicator": True, "PageScrollAnimation": True, + "StartWithDoubleSpread": False, "TTSSpeed": 1, "DarkColorFG": 252, "DarkColorBG": 235, @@ -92,7 +93,8 @@ CFG = { "Quit": "q", "Help": "?", "SwitchColor": "c", - "TTSToggle": "!" + "TTSToggle": "!", + "DoubleSpreadToggle": "D" } } STATE = { @@ -126,6 +128,7 @@ ALLPREVLETTERS = [] SUMALLLETTERS = 0 PROC_COUNTLETTERS = None ANIMATE = None +SPREAD = 1 class Epub: @@ -1321,7 +1324,15 @@ def define_word(word): def searching(pad, src, width, y, ch, tot): global SEARCHPATTERN rows, cols = SCREEN.getmaxyx() + if SPREAD == 2: + width = (cols-7)//2 + x = (cols - width) // 2 + if SPREAD == 1: + x = (cols - width) // 2 + else: + x = 2 + if SEARCHPATTERN is None: candtext = input_prompt(" Regex:") if candtext is None: @@ -1375,6 +1386,9 @@ def searching(pad, src, width, y, ch, tot): ) SCREEN.refresh() pad.refresh(y, 0, 0, x, rows-2, x+width) + if SPREAD == 2: + if y+rows < len(src): + pad.refresh(y+rows-1, 0, 0, cols-2-width, rows-2, cols-2) s = pad.getch() sidx = len(found) - 1 @@ -1446,11 +1460,11 @@ def searching(pad, src, width, y, ch, tot): if y+rows-1 > pad.chunks[pad.find_chunkidx(y)]: y = pad.chunks[pad.find_chunkidx(y)] + 1 - while found[sidx][0] not in list(range(y, y+rows-1)): + while found[sidx][0] not in list(range(y, y+(rows-1)*SPREAD )): if found[sidx][0] > y: - y += rows - 1 + y += (rows - 1)*SPREAD else: - y -= rows - 1 + y -= (rows - 1)*SPREAD if y < 0: y = 0 @@ -1462,6 +1476,9 @@ def searching(pad, src, width, y, ch, tot): SCREEN.addstr(rows-1, 0, msg, curses.A_REVERSE) SCREEN.refresh() pad.refresh(y, 0, 0, x, rows-2, x+width) + if SPREAD == 2: + if y+rows < len(src): + pad.refresh(y+rows-1, 0, 0, cols-2-width, rows-2, cols-2) s = pad.getch() @@ -1587,11 +1604,22 @@ def speaking(text): def reader(ebook, index, width, y, pctg, sect): - global SHOWPROGRESS, SPEAKING, ANIMATE + global SHOWPROGRESS, SPEAKING, ANIMATE, SPREAD k = 0 if SEARCHPATTERN is None else ord("/") rows, cols = SCREEN.getmaxyx() + + mincols_doublespr = 2 + 22 + 3 + 22 + 2 + if cols < mincols_doublespr: + SPREAD = 1 + if SPREAD == 2: + width = (cols-7)//2 + x = (cols - width) // 2 + if SPREAD == 1: + x = (cols - width) // 2 + else: + x = 2 contents = ebook.contents toc_name = ebook.toc_entries[0] @@ -1612,7 +1640,7 @@ def reader(ebook, index, width, y, pctg, sect): src_lines, imgs, toc_secid, formatting = parser.get_lines(width) totlines = len(src_lines) + 1 # 1 extra line for suffix - if y < 0 and totlines <= rows: + if y < 0 and totlines <= rows*SPREAD: y = 0 elif pctg is not None: y = round(pctg*totlines) @@ -1666,7 +1694,7 @@ def reader(ebook, index, width, y, pctg, sect): elif k in K["TTSToggle"] and TTSSUPPORT: # tospeak = "\n".join(src_lines[y:y+rows-1]) tospeak = "" - for i in src_lines[y:y+rows]: + for i in src_lines[y:y+(rows*SPREAD)]: if re.match(r"^\s*$", i) is not None: tospeak += "\n. \n" else: @@ -1675,7 +1703,19 @@ def reader(ebook, index, width, y, pctg, sect): if totlines-y <= rows and index == len(contents)-1: SPEAKING = False continue + elif k in K["DoubleSpreadToggle"]: + if cols < mincols_doublespr: + k = text_win(lambda: ( + "Screen is too small", + "Min: {} cols x {} rows".format(mincols_doublespr, 12), + {ord("D")} + ))() + SPREAD = (SPREAD % 2) + 1 + return 0, width, 0, y/totlines, "" elif k in K["ScrollUp"]: + if SPREAD == 2: + k = list(K["PageUp"])[0] + continue if count > 1: svline = y - 1 if y >= count: @@ -1691,14 +1731,17 @@ def reader(ebook, index, width, y, pctg, sect): tmp_parser = HTMLtoLines() tmp_parser.feed(ebook.get_raw_text(contents[index-1])) tmp_parser.close() - return -1, width, rows*(len(tmp_parser.get_lines(width)[0])//rows), None, "" + return -1, width, rows*SPREAD*(len(tmp_parser.get_lines(width)[0])//(rows*SPREAD)), None, "" else: - if y >= rows*count: + if y >= rows*SPREAD*count: ANIMATE = "prev" - y -= rows*count + y -= rows*SPREAD*count else: y = 0 elif k in K["ScrollDown"]: + if SPREAD == 2: + k = list(K["PageDown"])[0] + continue if count > 1: svline = y + rows - 1 if y + count <= totlines - rows: @@ -1709,12 +1752,12 @@ def reader(ebook, index, width, y, pctg, sect): else: y = totlines - rows elif k in K["PageDown"]: - if totlines - y > rows: + if totlines - y > rows*SPREAD: ANIMATE = "next" - if y+rows > pad.chunks[pad.find_chunkidx(y)]: + if y+(rows*SPREAD) > pad.chunks[pad.find_chunkidx(y)]: y = pad.chunks[pad.find_chunkidx(y)] + 1 else: - y += rows + y += rows*SPREAD # SCREEN.clear() # SCREEN.refresh() elif index != len(contents)-1: @@ -1785,13 +1828,13 @@ def reader(ebook, index, width, y, pctg, sect): k = help() if k in WINKEYS: continue - elif k in K["Enlarge"] and (width + count) < cols - 4: + elif k in K["Enlarge"] and (width + count) < cols - 4 and SPREAD == 1: width += count return 0, width, 0, y/totlines, "" - elif k in K["Shrink"] and width >= 22: + elif k in K["Shrink"] and width >= 22 and SPREAD == 1: width -= count return 0, width, 0, y/totlines, "" - elif k in K["SetWidth"]: + elif k in K["SetWidth"] and SPREAD == 1: if countstring == "": # if called without a count, toggle between 80 cols and full width if width != 80 and cols - 4 >= 80: @@ -1826,7 +1869,7 @@ def reader(ebook, index, width, y, pctg, sect): y = fs elif k in K["OpenImage"] and VWR is not None: gambar, idx = [], [] - for n, i in enumerate(src_lines[y:y+rows]): + for n, i in enumerate(src_lines[y:y+(rows*SPREAD)]): img = re.search("(?<=\\[IMG:)[0-9]+(?=\\])", i) if img is not None: gambar.append(img.group()) @@ -1838,7 +1881,7 @@ def reader(ebook, index, width, y, pctg, sect): elif len(gambar) > 1: p, i = 0, 0 while p not in K["Quit"] and p not in K["Follow"]: - SCREEN.move(idx[i], x + width//2 + len(gambar[i]) + 1) + SCREEN.move(idx[i] % rows, (x if idx[i]//rows==0 else cols-2-width) + width//2 + len(gambar[i]) + 1) SCREEN.refresh() safe_curs_set(1) p = pad.getch() @@ -1966,10 +2009,16 @@ def reader(ebook, index, width, y, pctg, sect): SCREEN.refresh() if ANIMATE == "next": pad.refresh(y, 0, 0, x+width-i, rows-1, x+width) + if SPREAD == 2 and y+rows < totlines: + pad.refresh(y+rows, 0, 0, cols-2-i, rows-1, cols-2) elif ANIMATE == "prev": pad.refresh(y, width-i-1, 0, x, rows-1, x+i) + if SPREAD == 2 and y+rows < totlines: + pad.refresh(y+rows, width-i-1, 0, cols-2-width, rows-1, cols-2-width+i) else: pad.refresh(y, 0, 0, x, rows-1, x+width) + if SPREAD == 2 and y+rows < totlines: + pad.refresh(y+rows, 0, 0, cols-2-width, rows-1, cols-2) ANIMATE = None LOCALSUMALLL = SUMALLLETTERS.value if MULTIPROC else SUMALLLETTERS @@ -2013,7 +2062,7 @@ def reader(ebook, index, width, y, pctg, sect): def preread(stdscr, file): - global COLORSUPPORT, SHOWPROGRESS, SCREEN + global COLORSUPPORT, SHOWPROGRESS, SCREEN, SPREAD try: curses.use_default_colors() @@ -2061,6 +2110,7 @@ def preread(stdscr, file): find_dict_client() parse_keys() SHOWPROGRESS = CFG["ShowProgressIndicator"] + SPREAD = 2 if CFG["StartWithDoubleSpread"] else 1 count_max_reading_pg(ebook) sec = "" |