start from first page if previous container is empty
This commit is contained in:
parent
e6f09eb5f2
commit
ce44436091
|
@ -17,6 +17,13 @@ from ..co import OrderedDict
|
|||
|
||||
__all__=['Containers']
|
||||
|
||||
def _relocate(lst,pos,step):
|
||||
# change from current position with step from pos in lst, return new position
|
||||
assert isinstance(step,int)
|
||||
if not (lst and step):return 0
|
||||
pos+=step
|
||||
return min(max(0,pos),len(lst)-1)
|
||||
|
||||
class Containers(OrderedDict):
|
||||
|
||||
__slots__=(
|
||||
|
@ -42,13 +49,6 @@ class Containers(OrderedDict):
|
|||
filenames.sort(key=self.sortkey,reverse=self.revsort)
|
||||
self._fnpos=self[container].index(filename)
|
||||
|
||||
def _relocate(self,lst,pos,step):
|
||||
# change from current position with step from pos in lst, return new position
|
||||
assert isinstance(step,int)
|
||||
if not step:return
|
||||
pos+=step
|
||||
return min(max(0,pos),len(lst)-1)
|
||||
|
||||
@property
|
||||
def sortkey(self):
|
||||
# 'key' argument that used in sorting filenames
|
||||
|
@ -106,13 +106,12 @@ class Containers(OrderedDict):
|
|||
assert isinstance(step,int)
|
||||
if not step:return
|
||||
oldpos=self._fnpos
|
||||
while True:
|
||||
try:
|
||||
self._fnpos=self._relocate(self.getvalue(self._pos),self._fnpos,step)
|
||||
break
|
||||
except IndexError:
|
||||
if not self.cross(-1):
|
||||
return False
|
||||
try:
|
||||
filenames=self.getvalue(self._pos)
|
||||
except IndexError:
|
||||
return self.cross(-1)
|
||||
else:
|
||||
self._fnpos=_relocate(filenames,self._fnpos,step)
|
||||
return self._fnpos!=oldpos
|
||||
|
||||
def cross(self,step=1,/):
|
||||
|
|
Loading…
Reference in New Issue