home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyth_os2.zip / python-1.0.2 / Demo / cwilib / vt100win.py < prev   
Text File  |  1993-11-01  |  2KB  |  79 lines

  1. # VT100 terminal emulator in a STDWIN window.
  2.  
  3. import stdwin
  4. from stdwinevents import *
  5. from vt100 import VT100
  6.  
  7. class VT100win(VT100):
  8.  
  9.     def __init__(self):
  10.         VT100.__init__(self)
  11.         self.window = None
  12.         self.last_x = -1
  13.         self.last_y = -1
  14.  
  15.     def __del__(self):
  16.         self.close()
  17.  
  18.     def open(self, title):
  19.         stdwin.setfont('7x14')
  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
  24.         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
  36.         self.window.change(((-10, -10),
  37.               (self.docwidth+10, self.docheight+10)))
  38.  
  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)
  45.         lh = self.lineheight
  46.         cw = self.charwidth
  47.         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.  
  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))
  74.  
  75.     def send(self, str):
  76.         VT100.send(self, str)
  77. ##        self.show()
  78.  
  79.