aboutsummaryrefslogtreecommitdiffstats
path: root/epy.py
diff options
context:
space:
mode:
authorwustho <benawiadha@gmail.com>2020-09-24 12:48:20 +0700
committerwustho <benawiadha@gmail.com>2020-09-24 12:48:20 +0700
commitcfdeec30a9684efaae3849f39f5a8ee7c3a1b47e (patch)
treedd682f4c8c59660dede7339d73fcaff699e71233 /epy.py
parentc5c98397545b2b3dd92055ff3f1334da309da8f5 (diff)
downloadepy-cfdeec30a9684efaae3849f39f5a8ee7c3a1b47e.tar.gz
Reorganize Board class close to other classes.
Diffstat (limited to 'epy.py')
-rwxr-xr-xepy.py122
1 files changed, 61 insertions, 61 deletions
diff --git a/epy.py b/epy.py
index 2ae848d..4937029 100755
--- a/epy.py
+++ b/epy.py
@@ -534,6 +534,67 @@ class HTMLtoLines(HTMLParser):
return text, self.imgs, sect
+class Board:
+ MAXCHUNKS = 32000 # lines
+
+ def __init__(self, totlines, width):
+ self.chunks = [self.MAXCHUNKS*(i+1)-1 for i in range(totlines // self.MAXCHUNKS)]
+ self.chunks += [] if totlines % self.MAXCHUNKS == 0 else [totlines % self.MAXCHUNKS + (0 if self.chunks == [] else self.chunks[-1])] # -1
+ self.pad = curses.newpad(min([self.MAXCHUNKS, totlines]), width)
+ self.pad.keypad(True)
+ # self.current_chunk = 0
+ self.y = 0
+ self.width = width
+
+ def feed(self, textlist):
+ self.text = textlist
+
+ def getch(self):
+ return self.pad.getch()
+
+ def bkgd(self, bg):
+ self.pad.bkgd(SCREEN.getbkgd())
+
+ def find_chunkidx(self, y):
+ for n, i in enumerate(self.chunks):
+ if y <= i:
+ return n
+
+ def paint_text(self, chunkidx=0):
+ self.pad.clear()
+ start_chunk = 0 if chunkidx == 0 else self.chunks[chunkidx-1]+1
+ end_chunk = self.chunks[chunkidx]
+ for n, i in enumerate(self.text[start_chunk:end_chunk+1]):
+ if re.search("\\[IMG:[0-9]+\\]", i):
+ self.pad.addstr(n, self.width//2 - len(i)//2 + 1, i, curses.A_REVERSE)
+ else:
+ self.pad.addstr(n, 0, i)
+ # chapter suffix
+ ch_suffix = "***" # "\u3064\u3065\u304f" つづく
+ try:
+ self.pad.addstr(n+1, (self.width - len(ch_suffix))//2 + 1, ch_suffix)
+ except curses.error:
+ pass
+
+ def chgat(self, y, x, n, attr):
+ chunkidx = self.find_chunkidx(y)
+ start_chunk = 0 if chunkidx == 0 else self.chunks[chunkidx-1]+1
+ end_chunk = self.chunks[chunkidx]
+ if y in range(start_chunk, end_chunk+1):
+ self.pad.chgat(y % self.MAXCHUNKS, x, n, attr)
+
+ def getbkgd(self):
+ return self.pad.getbkgd()
+
+ def refresh(self, y, b, c, d, e, f):
+ chunkidx = self.find_chunkidx(y)
+ if chunkidx != self.find_chunkidx(self.y):
+ self.paint_text(chunkidx)
+ # TODO: not modulo by self.MAXCHUNKS but self.pad.height
+ self.pad.refresh(y % self.MAXCHUNKS, b, c, d, e, f)
+ self.y = y
+
+
def text_win(textfunc):
@wraps(textfunc)
def wrapper(*args, **kwargs):
@@ -1285,67 +1346,6 @@ def count_max_reading_pg(ebook):
ALLPREVLETTERS, SUMALLLETTERS = count_pct(ebook)
-class Board:
- MAXCHUNKS = 32000 # lines
-
- def __init__(self, totlines, width):
- self.chunks = [self.MAXCHUNKS*(i+1)-1 for i in range(totlines // self.MAXCHUNKS)]
- self.chunks += [] if totlines % self.MAXCHUNKS == 0 else [totlines % self.MAXCHUNKS + (0 if self.chunks == [] else self.chunks[-1])] # -1
- self.pad = curses.newpad(min([self.MAXCHUNKS, totlines]), width)
- self.pad.keypad(True)
- # self.current_chunk = 0
- self.y = 0
- self.width = width
-
- def feed(self, textlist):
- self.text = textlist
-
- def getch(self):
- return self.pad.getch()
-
- def bkgd(self, bg):
- self.pad.bkgd(SCREEN.getbkgd())
-
- def find_chunkidx(self, y):
- for n, i in enumerate(self.chunks):
- if y <= i:
- return n
-
- def paint_text(self, chunkidx=0):
- self.pad.clear()
- start_chunk = 0 if chunkidx == 0 else self.chunks[chunkidx-1]+1
- end_chunk = self.chunks[chunkidx]
- for n, i in enumerate(self.text[start_chunk:end_chunk+1]):
- if re.search("\\[IMG:[0-9]+\\]", i):
- self.pad.addstr(n, self.width//2 - len(i)//2 + 1, i, curses.A_REVERSE)
- else:
- self.pad.addstr(n, 0, i)
- # chapter suffix
- ch_suffix = "***" # "\u3064\u3065\u304f" つづく
- try:
- self.pad.addstr(n+1, (self.width - len(ch_suffix))//2 + 1, ch_suffix)
- except curses.error:
- pass
-
- def chgat(self, y, x, n, attr):
- chunkidx = self.find_chunkidx(y)
- start_chunk = 0 if chunkidx == 0 else self.chunks[chunkidx-1]+1
- end_chunk = self.chunks[chunkidx]
- if y in range(start_chunk, end_chunk+1):
- self.pad.chgat(y % self.MAXCHUNKS, x, n, attr)
-
- def getbkgd(self):
- return self.pad.getbkgd()
-
- def refresh(self, y, b, c, d, e, f):
- chunkidx = self.find_chunkidx(y)
- if chunkidx != self.find_chunkidx(self.y):
- self.paint_text(chunkidx)
- # TODO: not modulo by self.MAXCHUNKS but self.pad.height
- self.pad.refresh(y % self.MAXCHUNKS, b, c, d, e, f)
- self.y = y
-
-
def reader(ebook, index, width, y, pctg, sect):
global SHOWPROGRESS