def test_conflicts(self): d3 = Direction(right=5, left=2, up=3, down=6, absolute=True, relative=True) self.assertEqual(d3.right(), -d3.left()) self.assertEqual(d3.left(), -d3.right()) self.assertEqual(d3.up(), -d3.down()) self.assertEqual(d3.down(), -d3.up()) self.assertEqual(d3.absolute(), not d3.relative()) self.assertEqual(d3.relative(), not d3.absolute())
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, 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 execute(self): if not self.fm.ui.pager.visible or not self.fm.thisfile or not self.fm.thisfile.is_file: return try: kw = {self.arg(1): int(self.arg(2))} except ValueError: k, v = self.arg(-1).split('=') kw = {k: int(v)} kw.setdefault('cycle', self.fm.settings['wrap_scroll']) kw.setdefault('one_indexed', self.fm.settings['one_indexed']) direction = Direction(kw) if not direction.vertical(): return cwd = self.fm.thisdir pos_orgin = cwd.pointer while True: old_thisfile = self.fm.thisfile cwd.pointer = direction.move( direction=direction.down(), maximum=len(cwd), current=cwd.pointer, pagesize=self.fm.ui.browser.hei) cwd.correct_pointer() if self.fm.thisfile.is_directory: if old_thisfile == self.fm.thisfile: cwd.pointer = pos_orgin cwd.correct_pointer() break else: break if pos_orgin != cwd.pointer: self.fm.display_file()
def move(self, narg=None, **keywords): direction = Direction(keywords) lst = self.get_list() if not lst: return self.pointer pointer = direction.move(direction=direction.down(), maximum=len(lst), override=narg, pagesize=self.get_height(), current=self.pointer) self.pointer = pointer self.correct_pointer() return pointer
def move(self, narg=None, **keywords): direction = Direction(keywords) lst = self.get_list() if not lst: return self.pointer pointer = direction.move( direction=direction.down(), maximum=len(lst), override=narg, pagesize=self.get_height(), current=self.pointer) self.pointer = pointer self.correct_pointer() return pointer
def move(self, narg=None, **kw): """ A universal movement method. Accepts these parameters: (int) down, (int) up, (int) left, (int) right, (int) to, (bool) absolute, (bool) relative, (bool) pages, (bool) percentage to=X is translated to down=X, absolute=True Example: self.move(down=4, pages=True) # moves down by 4 pages. self.move(to=2, pages=True) # moves to page 2. self.move(to=1, percentage=True) # moves to 80% """ cwd = self.env.cwd direction = Direction(kw) if 'left' in direction or direction.left() > 0: steps = direction.left() if narg is not None: steps *= narg try: directory = os.path.join(*(['..'] * steps)) except: return self.env.enter_dir(directory) if cwd and cwd.accessible and cwd.content_loaded: if 'right' in direction: mode = 0 if narg is not None: mode = narg cf = self.env.cf selection = self.env.get_selection() if not self.env.enter_dir(cf) and selection: if self.execute_file(selection, mode=mode) is False: self.open_console('open_with ') elif direction.vertical() and cwd.files: newpos = direction.move( direction=direction.down(), override=narg, maximum=len(cwd), current=cwd.pointer, pagesize=self.ui.browser.hei) cwd.move(to=newpos)
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): """ A universal movement method. Accepts these parameters: (int) down, (int) up, (int) left, (int) right, (int) to, (bool) absolute, (bool) relative, (bool) pages, (bool) percentage to=X is translated to down=X, absolute=True Example: self.move(down=4, pages=True) # moves down by 4 pages. self.move(to=2, pages=True) # moves to page 2. self.move(to=1, percentage=True) # moves to 80% """ cwd = self.env.cwd direction = Direction(kw) if 'left' in direction or direction.left() > 0: steps = direction.left() if narg is not None: steps *= narg try: directory = os.path.join(*(['..'] * steps)) except: return self.env.enter_dir(directory) if cwd and cwd.accessible and cwd.content_loaded: if 'right' in direction: mode = 0 if narg is not None: mode = narg cf = self.env.cf selection = self.env.get_selection() if not self.env.enter_dir(cf) and selection: if self.execute_file(selection, mode=mode) is False: self.open_console('open_with ') elif direction.vertical(): newpos = direction.move(direction=direction.down(), override=narg, maximum=len(cwd), current=cwd.pointer, pagesize=self.ui.browser.hei) cwd.move(to=newpos)
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): """A universal movement method. Accepts these parameters: (int) down, (int) up, (int) left, (int) right, (int) to, (bool) absolute, (bool) relative, (bool) pages, (bool) percentage to=X is translated to down=X, absolute=True Example: self.move(down=4, pages=True) # moves down by 4 pages. self.move(to=2, pages=True) # moves to page 2. self.move(to=1, percentage=True) # moves to 80% """ cwd = self.thisdir direction = Direction(kw) if 'left' in direction or direction.left() > 0: steps = direction.left() if narg is not None: steps *= narg try: directory = os.path.join(*(['..'] * steps)) except: return self.thistab.enter_dir(directory) self.change_mode('normal') if cwd and cwd.accessible and cwd.content_loaded: if 'right' in direction: mode = 0 if narg is not None: mode = narg cf = self.thisfile selection = self.thistab.get_selection() if not self.thistab.enter_dir(cf) and selection: result = self.execute_file(selection, mode=mode) if result in (False, ASK_COMMAND): self.open_console('open_with ') elif direction.vertical() and cwd.files: newpos = direction.move( direction=direction.down(), override=narg, maximum=len(cwd), current=cwd.pointer, pagesize=self.ui.browser.hei) cwd.move(to=newpos) if self.mode == 'visual': try: startpos = cwd.index(self._visual_start) except: self._visual_start = None startpos = min(self._visual_start_pos, len(cwd)) # The files between here and _visual_start_pos targets = set(cwd.files[min(startpos, newpos):\ max(startpos, newpos) + 1]) # The selection before activating visual mode old = self._previous_selection # The current selection current = set(cwd.marked_items) # Set theory anyone? if not self._visual_reverse: for f in targets - current: cwd.mark_item(f, True) for f in current - old - targets: cwd.mark_item(f, False) else: for f in targets & current: cwd.mark_item(f, False) for f in old - current - targets: cwd.mark_item(f, True) if self.ui.pager.visible: self.display_file()
def move(self, narg=None, **kw): """A universal movement method. Accepts these parameters: (int) down, (int) up, (int) left, (int) right, (int) to, (bool) absolute, (bool) relative, (bool) pages, (bool) percentage to=X is translated to down=X, absolute=True Example: self.move(down=4, pages=True) # moves down by 4 pages. self.move(to=2, pages=True) # moves to page 2. self.move(to=80, percentage=True) # moves to 80% """ cwd = self.thisdir direction = Direction(kw) if 'left' in direction or direction.left() > 0: steps = direction.left() if narg is not None: steps *= narg try: directory = os.path.join(*(['..'] * steps)) except Exception: return self.thistab.enter_dir(directory) self.change_mode('normal') if cwd and cwd.accessible and cwd.content_loaded: if 'right' in direction: mode = 0 if narg is not None: mode = narg cf = self.thisfile selection = self.thistab.get_selection() if not self.thistab.enter_dir(cf) and selection: result = self.execute_file(selection, mode=mode) if result in (False, ASK_COMMAND): self.open_console('open_with ') elif direction.vertical() and cwd.files: newpos = direction.move( direction=direction.down(), override=narg, maximum=len(cwd), current=cwd.pointer, pagesize=self.ui.browser.hei) cwd.move(to=newpos) if self.mode == 'visual': try: startpos = cwd.index(self._visual_start) except Exception: self._visual_start = None startpos = min(self._visual_start_pos, len(cwd)) # The files between here and _visual_start_pos targets = set(cwd.files[min(startpos, newpos): max(startpos, newpos) + 1]) # The selection before activating visual mode old = self._previous_selection # The current selection current = set(cwd.marked_items) # Set theory anyone? if not self._visual_reverse: for f in targets - current: cwd.mark_item(f, True) for f in current - old - targets: cwd.mark_item(f, False) else: for f in targets & current: cwd.mark_item(f, False) for f in old - current - targets: cwd.mark_item(f, True) if self.ui.pager.visible: self.display_file()