def move(self, narg=None, **kw): direction = Direction(kw) if direction.horizontal(): self.startx = direction.move( direction=direction.right(), override=narg, maximum=self.max_width, current=self.startx, pagesize=self.wid, offset=-self.wid + 1) if direction.vertical(): movement = dict( direction=direction.down(), override=narg, current=self.scroll_begin, pagesize=self.hei, offset=-self.hei + 1) if self.source_is_stream: # For streams, we first pretend that the content ends much later, # in case there are still unread lines. desired_position = direction.move( maximum=len(self.lines) + 9999, **movement) # Then, read the new lines as needed to produce a more accurate # maximum for the movement: self._get_line(desired_position + self.hei) self.scroll_begin = direction.move( maximum=len(self.lines), **movement)
def move(self, **keywords): direction = Direction(keywords) if direction.horizontal(): # Ensure that the pointer is moved utf-char-wise if self.fm.py3: if self.question_queue: umax = len(self.question_queue[0][0]) + 1 - self.wid else: umax = len(self.line) + 1 self.pos = direction.move( direction=direction.right(), minimum=0, maximum=umax, current=self.pos) else: if self.question_queue: uchar = list(self.question_queue[0][0].decode('utf-8', 'ignore')) upos = len(self.question_queue[0][0][:self.pos].decode('utf-8', 'ignore')) umax = len(uchar) + 1 - self.wid else: uchar = list(self.line.decode('utf-8', 'ignore')) upos = len(self.line[:self.pos].decode('utf-8', 'ignore')) umax = len(uchar) + 1 newupos = direction.move( direction=direction.right(), minimum=0, maximum=umax, current=upos) self.pos = len(''.join(uchar[:newupos]).encode('utf-8', 'ignore'))
def move(self, narg=None, **kw): direction = Direction(kw) if direction.horizontal(): self.startx = direction.move(direction=direction.right(), override=narg, maximum=self.max_width, current=self.startx, pagesize=self.wid, offset=-self.wid + 1) if direction.vertical(): movement = dict(direction=direction.down(), override=narg, current=self.scroll_begin, pagesize=self.hei, offset=-self.hei + 1) if self.source_is_stream: # For streams, we first pretend that the content ends much later, # in case there are still unread lines. desired_position = direction.move(maximum=len(self.lines) + 9999, **movement) # Then, read the new lines as needed to produce a more accurate # maximum for the movement: self._get_line(desired_position + self.hei) self.scroll_begin = direction.move(maximum=len(self.lines), **movement)
def move(self, **keywords): direction = Direction(keywords) if direction.horizontal(): # Ensure that the pointer is moved utf-char-wise if PY3: if self.question_queue: umax = len(self.question_queue[0][0]) + 1 - self.wid else: umax = len(self.line) + 1 self.pos = direction.move(direction=direction.right(), minimum=0, maximum=umax, current=self.pos) else: if self.question_queue: uchar = list(self.question_queue[0][0].decode( 'utf-8', 'ignore')) upos = len(self.question_queue[0][0][:self.pos].decode( 'utf-8', 'ignore')) umax = len(uchar) + 1 - self.wid else: uchar = list(self.line.decode('utf-8', 'ignore')) upos = len(self.line[:self.pos].decode('utf-8', 'ignore')) umax = len(uchar) + 1 newupos = direction.move(direction=direction.right(), minimum=0, maximum=umax, current=upos) self.pos = len(''.join(uchar[:newupos]).encode( 'utf-8', 'ignore'))
def test_copy(self): d = Direction(right=5) c = d.copy() self.assertEqual(c.right(), d.right()) d['right'] += 3 self.assertNotEqual(c.right(), d.right()) c['right'] += 3 self.assertEqual(c.right(), d.right()) self.assertFalse(d.vertical()) self.assertTrue(d.horizontal())
def move(self, **keywords): direction = Direction(keywords) if direction.horizontal(): # Ensure that the pointer is moved utf-char-wise uc = uchars(self.line) upos = len(uchars(self.line[:self.pos])) newupos = direction.move( direction=direction.right(), minimum=0, maximum=len(uc) + 1, current=upos) self.pos = len(''.join(uc[:newupos]))
def move(self, **keywords): direction = Direction(keywords) if direction.horizontal(): # Ensure that the pointer is moved utf-char-wise if self.fm.py3: self.pos = direction.move(direction=direction.right(), minimum=0, maximum=len(self.line) + 1, current=self.pos) else: uc = uchars(self.line) upos = len(uchars(self.line[:self.pos])) newupos = direction.move(direction=direction.right(), minimum=0, maximum=len(uc) + 1, current=upos) self.pos = len(''.join(uc[:newupos]))
def move(self, **keywords): direction = Direction(keywords) if direction.horizontal(): # Ensure that the pointer is moved utf-char-wise if self.fm.py3: self.pos = direction.move( direction=direction.right(), minimum=0, maximum=len(self.line) + 1, current=self.pos ) else: if self.fm.py3: uc = list(self.line) upos = len(self.line[: self.pos]) else: uc = list(self.line.decode("utf-8", "ignore")) upos = len(self.line[: self.pos].decode("utf-8", "ignore")) newupos = direction.move(direction=direction.right(), minimum=0, maximum=len(uc) + 1, current=upos) self.pos = len("".join(uc[:newupos]).encode("utf-8", "ignore"))
def move(self, narg=None, **kw): direction = Direction(kw) if direction.horizontal(): self.startx = direction.move(direction=direction.right(), override=narg, maximum=self.max_width, current=self.startx, pagesize=self.wid, offset=-self.wid + 1) if direction.vertical(): if self.source_is_stream: self._get_line(self.scroll_begin + self.hei * 2) self.scroll_begin = direction.move(direction=direction.down(), override=narg, maximum=len(self.lines), current=self.scroll_begin, pagesize=self.hei, offset=-self.hei + 1)
def move(self, narg=None, **kw): direction = Direction(kw) if direction.horizontal(): self.startx = direction.move( direction=direction.right(), override=narg, maximum=self.max_width, current=self.startx, pagesize=self.wid, offset=-self.wid + 1) if direction.vertical(): if self.source_is_stream: self._get_line(self.scroll_begin + self.hei * 2) self.scroll_begin = direction.move( direction=direction.down(), override=narg, maximum=len(self.lines), current=self.scroll_begin, pagesize=self.hei, offset=-self.hei + 1)
def move(self, **keywords): direction = Direction(keywords) if direction.horizontal(): # Ensure that the pointer is moved utf-char-wise if self.fm.py3: self.pos = direction.move(direction=direction.right(), minimum=0, maximum=len(self.line) + 1, current=self.pos) else: if self.fm.py3: uchar = list(self.line) upos = len(self.line[:self.pos]) else: uchar = list(self.line.decode('utf-8', 'ignore')) upos = len(self.line[:self.pos].decode('utf-8', 'ignore')) newupos = direction.move(direction=direction.right(), minimum=0, maximum=len(uchar) + 1, current=upos) self.pos = len(''.join(uchar[:newupos]).encode( 'utf-8', 'ignore'))
def move_word(self, **keywords): direction = Direction(keywords) if direction.horizontal(): self.pos = self.move_by_word(self.line, self.pos, direction.right()) self.on_line_change()