Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b71f879

Browse files
committed
Changed redraw policy.
1 parent 615194a commit b71f879

1 file changed

Lines changed: 24 additions & 14 deletions

File tree

Demo/cwilib/vt100win.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ class VT100win(VT100):
99
def __init__(self):
1010
VT100.__init__(self)
1111
self.window = None
12-
## self.last_x = -1
13-
## self.last_y = -1
12+
self.last_x = -1
13+
self.last_y = -1
1414

1515
def __del__(self):
1616
self.close()
1717

1818
def open(self, title):
1919
stdwin.setfont('7x14')
20-
self.docwidth = self.width * stdwin.textwidth('m')
21-
self.docheight = self.height * stdwin.lineheight()
20+
self.charwidth = stdwin.textwidth('m')
21+
self.lineheight = stdwin.lineheight()
22+
self.docwidth = self.width * self.charwidth
23+
self.docheight = self.height * self.lineheight
2224
stdwin.setdefwinsize(self.docwidth + 2, self.docheight + 2)
2325
stdwin.setdefscrollbars(0, 0)
2426
self.window = stdwin.open(title)
@@ -31,16 +33,17 @@ def close(self):
3133

3234
def show(self):
3335
if not self.window: return
34-
self.draw(((-10, -10), (self.docwidth+10, self.docheight+10)))
36+
self.window.change(((-10, -10),
37+
(self.docwidth+10, self.docheight+10)))
3538

3639
def draw(self, detail):
3740
d = self.window.begindrawing()
3841
fg = stdwin.getfgcolor()
3942
red = stdwin.fetchcolor('red')
4043
d.cliprect(detail)
4144
d.erase(detail)
42-
lh = d.lineheight()
43-
cw = d.textwidth('m')
45+
lh = self.lineheight
46+
cw = self.charwidth
4447
for y in range(self.height):
4548
d.text((0, y*lh), self.lines[y].tostring())
4649
if self.attrs[y] <> self.blankattr:
@@ -56,13 +59,20 @@ def draw(self, detail):
5659
d.setfgcolor(fg)
5760
d.close()
5861

59-
## def move_to(self, x, y):
60-
## VT100.move_to(self, x, y)
61-
## if self.y != self.last_y:
62-
## self.show()
63-
## self.last_x = self.x
64-
## self.last_y = y
62+
def move_to(self, x, y):
63+
VT100.move_to(self, x, y)
64+
if not self.window: return
65+
if self.y != self.last_y:
66+
self.window.change((0, self.last_y * self.lineheight),
67+
(self.width*self.charwidth,
68+
(self.last_y+1) * self.lineheight))
69+
self.last_x = self.x
70+
self.last_y = y
71+
self.window.change((0, self.y * self.lineheight),
72+
(self.width*self.charwidth,
73+
(self.y+1) * self.lineheight))
6574

6675
def send(self, str):
6776
VT100.send(self, str)
68-
self.show()
77+
## self.show()
78+

0 commit comments

Comments
 (0)