Exemplo n.º 1
0
    def push(self, char):
        ord_char = char if isinstance(char, int) else ord(char)
        char = bytes(bytearray((ord_char,)))
        self.buf.append(ord_char)
        if char in self.k:
            if self.k is self.ck:
                #sanity check, buffer is empty when a special key comes
                assert len(self.buf) == 1
            k = self.k[char]
            trace('found map {k!r}', k=k)
            if isinstance(k, dict):
                self.k = k
            else:
                self.insert(Event('key', k, self.flush_buf()))
                self.k = self.ck

        elif self.buf and self.buf[0] == 27:  # escape
            # escape sequence not recognized by our keymap: propagate it
            # outside so that i can be recognized as an M-... key (see also
            # the docstring in keymap.py, in particular the line \\E.
            trace('unrecognized escape sequence, propagating...')
            self.k = self.ck
            self.insert(Event('key', '\033', bytearray(b'\033')))
            for c in self.flush_buf()[1:]:
                self.push(chr(c))

        else:
            try:
                decoded = bytes(self.buf).decode(self.encoding)
            except UnicodeError:
                return
            else:
                self.insert(Event('key', decoded, self.flush_buf()))
            self.k = self.ck
Exemplo n.º 2
0
 def move_cursor(self, x, y):
     if y < self.__offset or y >= self.__offset + self.height:
         self.event_queue.insert(Event('scroll', None))
     else:
         self.__move(x, y)
         self.__posxy = x, y
         self.flushoutput()
    def get_event(self, block=1):
        """Return an Event instance.  Returns None if |block| is false
        and there is no event pending, otherwise waits for the
        completion of an event."""
        while 1:
            if self.event_queue:
                return self.event_queue.pop(0)
            elif block:
                pyg_event = pygame.event.wait()
            else:
                pyg_event = pygame.event.poll()
                if pyg_event.type == NOEVENT:
                    return

            if pyg_event.key in modcolors:
                continue

            k, c = self.tr_event(pyg_event)
            self.cmd_buf += c.encode('ascii', 'replace')
            self.k = k

            if not isinstance(k, types.DictType):
                e = Event(k, self.cmd_buf, [])
                self.k = self.keymap
                self.cmd_buf = ''
                return e
Exemplo n.º 4
0
 def push(self, char):
     if char in self.k:
         k = self.k[char]
         if isinstance(k, dict):
             self.buf.append(char)
             self.k = k
         else:
             self.events.append(Event('key', k, ''.join(self.buf) + char))
             self.buf = []
             self.k = self.ck
     elif self.buf:
         self.events.extend([Event('key', c, c) for c in self.buf])
         self.buf = []
         self.k = self.ck
         self.push(char)
     else:
         self.events.append(Event('key', char, char))
Exemplo n.º 5
0
 def get_event(self, block=1):
     ev, sc = self.events.pop(0)
     self.next_screen = sc
     if not isinstance(ev, tuple):
         ev = (ev, None)
     self.last_event_name = ev[0]
     if self.verbose:
         print("event", ev)
     return Event(*ev)
Exemplo n.º 6
0
    def push(self, char):
        self.buf.append(ord(char))
        if char in self.k:
            if self.k is self.ck:
                #sanity check, buffer is empty when a special key comes
                assert len(self.buf) == 1
            k = self.k[char]
            trace('found map {k!r}', k=k)
            if isinstance(k, dict):
                self.k = k
            else:
                self.insert(Event('key', k, self.flush_buf()))
                self.k = self.ck

        else:
            try:
                decoded = bytes(self.buf).decode(self.encoding)
            except:
                return

            self.insert(Event('key', decoded, self.flush_buf()))
            self.k = self.ck
Exemplo n.º 7
0
    def getpending(self):
        e = Event('key', '', '')

        while not self.event_queue.empty():
            e2 = self.event_queue.get()
            e.data += e2.data
            e.raw += e2.raw

        amount = 1000
        raw = unicode(self._osread(amount), self.encoding, 'replace')
        e.data += raw
        e.raw += raw
        return e
 def move_cursor(self, x, y):
     cp = self.char_pos(x, y)
     if cp[1] < tmargin or cp[1] + self.fh > 600 - bmargin:
         self.event_queue.append(Event('refresh', '', ''))
     else:
         if self.curs_vis:
             cx, cy = self.cxy
             self.pygame_screen.fill(colors.bg, self.char_rect(cx, cy))
             self.blit_a_char(cy, cx)
             self.pygame_screen.blit(self.cursor, cp)
             self.blit_a_char(y, x)
             pygame.display.update()
         self.cxy = (x, y)
Exemplo n.º 9
0
        def getpending(self):
            e = Event('key', '', '')

            while not self.event_queue.empty():
                e2 = self.event_queue.get()
                e.data += e2.data
                e.raw += e.raw
                
            amount = struct.unpack(
                "i", ioctl(self.input_fd, FIONREAD, "\0\0\0\0"))[0]
            raw = unicode(os.read(self.input_fd, amount), self.encoding, 'replace')
            e.data += raw
            e.raw += raw
            return e
Exemplo n.º 10
0
    def push(self, char):
        #        print "Handling char %r"%char
        #        print >>sys.stderr,"Handling char %r"%char
        if char in self.k:
            k = self.k[char]
            if isinstance(k, dict):
                #                print >>sys.stderr,"In multi-key sequence chr "+char+" dict "+str(k)
                self.buf.append(char)
                self.k = k
            else:
                #                print >>sys.stderr,"Finished multi-key sequence:"+str(self.buf)
                self.events.append(Event('key', k, ''.join(self.buf) + char))
                self.buf = []
                self.k = self.ck
        elif self.buf:
            #            print >>sys.stderr,"Aborted multi-key sequence %r chr %r dict %r"%(self.buf,char,self.k)
            #            print >>sys.stderr,"%r %r %r %r %r %r %r %r %r"%(char,'0',char=='0',self.k.has_key('0'),self.k.has_key(char),len(char),char[0],ord(char),ord('0'))

            self.events.extend([Event('key', c, c) for c in self.buf])
            self.buf = []
            self.k = self.ck
            self.push(char)
        else:
            self.events.append(Event('key', char, char))
Exemplo n.º 11
0
 def __sigwinch(self, signum, frame):
     self.height, self.width = self.getheightwidth()
     self.event_queue.insert(Event('resize', None))
Exemplo n.º 12
0
 def __sigwinch(self, signum, frame):
     self._update_size()
     self.event_queue.insert(Event('resize', None))
Exemplo n.º 13
0
 def getpending(self):
     """Nothing pending, but do not return None here."""
     return Event('key', '', b'')