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): """ 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): """ 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): """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()