Skip to content

Commit

Permalink
Merge branch 'feature/remember-explorer-path'
Browse files Browse the repository at this point in the history
Allow app to remember last explorer path
  • Loading branch information
blueaxis authored Jan 2, 2023
2 parents 2d558cd + eb7e513 commit 8044b5d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 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
16 changes: 11 additions & 5 deletions code/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def closeEvent(self, event):
rmtree("./poricom_cache")
except FileNotFoundError:
pass
self.config["NAV_ROOT"] = self.tracker.filepath
saveOnClose(self.config)
return QMainWindow.closeEvent(self, event)

Expand All @@ -111,19 +112,24 @@ def openDir(self):
filepath = QFileDialog.getExistingDirectory(
self,
"Open Directory",
"." # , QFileDialog.DontUseNativeDialog
self.tracker.filepath # , QFileDialog.DontUseNativeDialog
)

if filepath:
# self.tracker.pixImage = filename
self.tracker.filepath = filepath
self.explorer.setDirectory(filepath)
try:
self.tracker.filepath = filepath
self.explorer.setDirectory(filepath)
except FileNotFoundError:
MessagePopup(
f"No images found in the directory",
f"Please select a directory with images."
).exec()

def openManga(self):
filename, _ = QFileDialog.getOpenFileName(
self,
"Open Manga File",
".",
self.tracker.filepath,
"Manga (*.cbz *.cbr *.zip *.rar *.pdf)"
)

Expand Down
24 changes: 17 additions & 7 deletions code/Trackers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,23 @@


class Tracker:

def __init__(self, filename=config["HOME_IMAGE"], filenext=config["ABOUT_IMAGE"]):
def __init__(self):
try:
self.filepath = abspath(config["NAV_ROOT"])
except FileNotFoundError:
self.filepath = abspath(config["DEFAULT_NAV_ROOT"])
try:
filename, filenext, *_ = self._imageList
except ValueError:
filename, *_ = self._imageList
filenext = None
if not config["SPLIT_VIEW_MODE"]:
self._pixImage = PImage(filename)
if config["SPLIT_VIEW_MODE"]:
splitImage = self.twoFileToImage(filename, filenext)
self._pixImage = PImage(splitImage, filename)
self._pixMask = PImage(filename)

self._filepath = abspath(dirname(filename))
self._writeMode = False

self._imageList = []
Expand Down Expand Up @@ -104,11 +111,14 @@ def filepath(self):

@filepath.setter
def filepath(self, filepath):
fileList = filter(lambda f: isfile(join(filepath, f)), listdir(filepath))
imageList = list(map(lambda p: normpath(join(filepath, p)), filter(
(lambda f: ('*'+splitext(f)[1]) in config["IMAGE_EXTENSIONS"]), fileList)))
if len(imageList) <= 0:
raise FileNotFoundError("Empty directory")

self._filepath = filepath
filelist = filter(lambda f: isfile(join(self.filepath,
f)), listdir(self.filepath))
self._imageList = list(map(lambda p: normpath(join(self.filepath, p)), filter(
(lambda f: ('*'+splitext(f)[1]) in config["IMAGE_EXTENSIONS"]), filelist)))
self._imageList = imageList

@property
def language(self):
Expand Down
5 changes: 3 additions & 2 deletions code/utils/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ LANGUAGE = [ " Japanese", " Korean", " Chinese SIM", " Chinese TRA ", " English
ORIENTATION = [ " Vertical", " Horizontal",]
FONT_STYLE = [ " Helvetica", " Poppins", " Arial", " Verdana", " Times New Roman",]
FONT_SIZE = [ " 12", " 14", " 16", " 20", " 24", " 32", " 40", " 56", " 72",]
IMAGE_SCALING= [ " Fit to Width", " Fit to Height", " Fit to Screen",]
MODIFIER = [ " Ctrl", " Shift", " Alt", " Ctrl+Alt", " Shift+Alt", " Shift+Ctrl", " Shift+Alt+Ctrl", " No Modifier"]
IMAGE_SCALING = [ " Fit to Width", " Fit to Height", " Fit to Screen",]
MODIFIER = [ " Ctrl", " Shift", " Alt", " Ctrl+Alt", " Shift+Alt", " Shift+Ctrl", " Shift+Alt+Ctrl", " No Modifier",]

# Filepath
STYLES_PATH = "./assets/"
DEFAULT_NAV_ROOT = "./assets/images/"
NAV_ROOT = "./assets/images/"
TBAR_ICONS = "./assets/images/icons/"
TBAR_ICONS_LIGHT = "./assets/images/icons/"
Expand Down

0 comments on commit 8044b5d

Please sign in to comment.