Skip to content

Commit

Permalink
Set file dialog to remember last path
Browse files Browse the repository at this point in the history
  • Loading branch information
blueaxis committed Dec 22, 2022
1 parent 5a9b6d3 commit 237f83c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
16 changes: 11 additions & 5 deletions code/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,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 @@ -105,19 +106,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 237f83c

Please sign in to comment.