blob: 122e5f9dfaee582f3237fe38ed186dfdd2228235 [file] [log] [blame]
Guido van Rossum74b3f8a1993-10-28 09:53:13 +00001# VT100 terminal emulator in a STDWIN window.
2
3import stdwin
4from stdwinevents import *
5from vt100 import VT100
6
7class VT100win(VT100):
8
9 def __init__(self):
10 VT100.__init__(self)
11 self.window = None
Guido van Rossumb71f8791993-11-01 14:48:37 +000012 self.last_x = -1
13 self.last_y = -1
Guido van Rossum74b3f8a1993-10-28 09:53:13 +000014
15 def __del__(self):
16 self.close()
17
18 def open(self, title):
19 stdwin.setfont('7x14')
Guido van Rossumb71f8791993-11-01 14:48:37 +000020 self.charwidth = stdwin.textwidth('m')
21 self.lineheight = stdwin.lineheight()
22 self.docwidth = self.width * self.charwidth
23 self.docheight = self.height * self.lineheight
Guido van Rossum74b3f8a1993-10-28 09:53:13 +000024 stdwin.setdefwinsize(self.docwidth + 2, self.docheight + 2)
25 stdwin.setdefscrollbars(0, 0)
26 self.window = stdwin.open(title)
27 self.window.setdocsize(self.docwidth + 2, self.docheight + 2)
28
29 def close(self):
30 if self.window:
31 self.window.close()
32 self.window = None
33
34 def show(self):
35 if not self.window: return
Guido van Rossumb71f8791993-11-01 14:48:37 +000036 self.window.change(((-10, -10),
37 (self.docwidth+10, self.docheight+10)))
Guido van Rossum74b3f8a1993-10-28 09:53:13 +000038
39 def draw(self, detail):
40 d = self.window.begindrawing()
41 fg = stdwin.getfgcolor()
42 red = stdwin.fetchcolor('red')
43 d.cliprect(detail)
44 d.erase(detail)
Guido van Rossumb71f8791993-11-01 14:48:37 +000045 lh = self.lineheight
46 cw = self.charwidth
Guido van Rossum74b3f8a1993-10-28 09:53:13 +000047 for y in range(self.height):
48 d.text((0, y*lh), self.lines[y].tostring())
49 if self.attrs[y] <> self.blankattr:
50 for x in range(len(self.attrs[y])):
51 if self.attrs[y][x] == 7:
52 p1 = x*cw, y*lh
53 p2 = (x+1)*cw, (y+1)*lh
54 d.invert((p1, p2))
55 x = self.x * cw
56 y = self.y * lh
57 d.setfgcolor(red)
58 d.invert((x, y), (x+cw, y+lh))
59 d.setfgcolor(fg)
60 d.close()
61
Guido van Rossumb71f8791993-11-01 14:48:37 +000062 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))
Guido van Rossum74b3f8a1993-10-28 09:53:13 +000074
75 def send(self, str):
76 VT100.send(self, str)
Guido van Rossumb71f8791993-11-01 14:48:37 +000077## self.show()
78