Skip to content

Commit

Permalink
Set first file as default selected index
Browse files Browse the repository at this point in the history
  • Loading branch information
blueaxis committed Dec 22, 2022
1 parent 237f83c commit eb7e513
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions code/Explorers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,30 @@ def __init__(self, parent=None, tracker=None):

def currentChanged(self, current, previous):
if not current.isValid():
current = self.model.index(0, 0, self.rootIndex())
current = self.model.index(self.getTopIndex(), 0, self.rootIndex())
filename = self.model.fileInfo(current).absoluteFilePath()
nextIndex = self.indexBelow(current)
filenext = self.model.fileInfo(nextIndex).absoluteFilePath()
self.parent.viewImageFromExplorer(filename, filenext)
QTreeView.currentChanged(self, current, previous)

def getTopIndex(self):
r = self.model.rowCount(self.rootIndex()) // 2
while True:
item = self.model.index(r, 0, self.rootIndex())
if not item.isValid():
break
if self.model.fileInfo(item).isFile():
r //= 2
elif not self.model.fileInfo(item).isFile():
r += 1
item = self.model.index(r, 0, self.rootIndex())
if self.model.fileInfo(item).isFile():
break
return r

def setTopIndex(self):
topIndex = self.model.index(0, 0, self.rootIndex())
topIndex = self.model.index(self.getTopIndex(), 0, self.rootIndex())
if topIndex.isValid():
self.setCurrentIndex(topIndex)
if self.layoutCheck:
Expand Down

0 comments on commit eb7e513

Please sign in to comment.