Ejemplo n.º 1
0
 def position_coords(self,maxcol,pos):
     """
     Return (x,y) coordinates for an offset into self.edit_text.
     """
     
     p = pos + len(self.caption)
     trans = self.get_line_translation(maxcol)
     x,y = calc_coords(self.get_text()[0], trans,p)
     return x,y
Ejemplo n.º 2
0
    def position_coords(self, maxcol, pos):
        """
        Return (x,y) coordinates for an offset into self.edit_text.
        """

        p = pos + len(self.caption)
        trans = self.get_line_translation(maxcol)
        x, y = calc_coords(self.get_text()[0], trans, p)
        return x, y
Ejemplo n.º 3
0
    def get_cursor_coords(self, size):
        if self._cursor_position > len(self.text):
            return None

        (maxcol, ) = size
        trans = self.get_line_translation(maxcol)
        x, y = calc_coords(self.text, trans, self._cursor_position)
        if maxcol <= x:
            return None
        return x, y
Ejemplo n.º 4
0
Archivo: wimp.py Proyecto: eykd/urwid
 def get_cursor_coords(self, size):
     """
     Return the position of the cursor if visible.  This method
     is required for widgets that display a cursor.
     """
     if self._cursor_position > len(self.text):
         return None
     # find out where the cursor will be displayed based on
     # the text layout
     (maxcol,) = size
     trans = self.get_line_translation(maxcol)
     x, y = calc_coords(self.text, trans, self._cursor_position)
     return x, y
Ejemplo n.º 5
0
 def get_cursor_coords(self, size):
     """
     Return the position of the cursor if visible.  This method
     is required for widgets that display a cursor.
     """
     if self._cursor_position > len(self.text):
         return None
     # find out where the cursor will be displayed based on
     # the text layout
     (maxcol, ) = size
     trans = self.get_line_translation(maxcol)
     x, y = calc_coords(self.text, trans, self._cursor_position)
     return x, y
Ejemplo n.º 6
0
    def get_line_translation(self, maxcol, ta=None):
        trans = Text.get_line_translation(self, maxcol, ta)
        if not self._shift_view_to_cursor:
            return trans

        text, ignore = self.get_text()
        x, y = calc_coords(text, trans, self.edit_pos + len(self.caption))
        if x < 0:
            return (trans[:y] + [shift_line(trans[y], -x)] + trans[y + 1:])
        elif x >= maxcol:
            return (trans[:y] + [shift_line(trans[y], -(x - maxcol + 1))] +
                    trans[y + 1:])
        return trans
Ejemplo n.º 7
0
 def get_line_translation(self, maxcol, ta=None ):
     trans = Text.get_line_translation(self, maxcol, ta)
     if not self._shift_view_to_cursor: 
         return trans
     
     text, ignore = self.get_text()
     x,y = calc_coords( text, trans, 
         self.edit_pos + len(self.caption) )
     if x < 0:
         return ( trans[:y]
             + [shift_line(trans[y],-x)]
             + trans[y+1:] )
     elif x >= maxcol:
         return ( trans[:y] 
             + [shift_line(trans[y],-(x-maxcol+1))]
             + trans[y+1:] )
     return trans
Ejemplo n.º 8
0
    def get_cursor_coords(self, size):
        """
        Return the (*x*, *y*) coordinates of cursor within widget.

        >>> Edit("? ","yes").get_cursor_coords((10,))
        (5, 0)
        """
        from there import syslogprint as LOG

        if not self._focusable:
            return None

        (maxcol, ) = size

        LOG(len(self.get_text()[0]))
        trans = self.get_line_translation(maxcol)

        current_len = 0
        k = 0
        for item in self.markup:
            if isinstance(item, Link):
                if k == self.link_index:
                    break
                else:
                    k += 1
                current_len += len(item.text)
            else:
                if isinstance(item, tuple):
                    assert len(item) == 2
                    item = item[1]
                    if isinstance(item, list):
                        for it in item:
                            assert isinstance(it, str)
                        current_len += sum([len(x) for x in item])
                    elif isinstance(item, str):
                        current_len += len(item)
                    else:
                        assert False, (repr(item), repr(self.markup))

                elif isinstance(item, str):
                    current_len += len(item)

        LOG("FOCUS at pos", current_len)
        x, y = calc_coords(self.get_text()[0], trans, current_len)

        return (x, y)
Ejemplo n.º 9
0
 def test(self):
     for t, answer in self.mytests:
         for pos, a in zip(self.pos_list, answer):
             r = text_layout.calc_coords(self.text, t, pos)
             assert r == a, "%r got: %r expected: %r" % (t, r, a)
Ejemplo n.º 10
0
 def get_cursor_coords(self, size):
     p = self.cbuf.cursor + len(self.leader)
     trans = self._w.get_line_translation(size[0])
     x, y = calc_coords(self._w.get_text()[0], trans, p)
     return x, y
Ejemplo n.º 11
0
 def test(self):
     for t, answer in self.mytests:
         for pos, a in zip(self.pos_list, answer):
             r = text_layout.calc_coords(self.text, t, pos)
             assert r == a, "%r got: %r expected: %r" % (t, r, a)