From 171fa85d5df00c1524c63c7e78188eee696d2d57 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Sun, 25 Apr 2021 22:34:12 -0500 Subject: [PATCH] Updated save and load logic --- src/shellfm/windows/WindowController.py | 43 +++++++++++++++++++++- src/shellfm/windows/view/View.py | 2 +- src/shellfm/windows/view/utils/Settings.py | 2 +- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/shellfm/windows/WindowController.py b/src/shellfm/windows/WindowController.py index b3b2ee5..1f825eb 100644 --- a/src/shellfm/windows/WindowController.py +++ b/src/shellfm/windows/WindowController.py @@ -1,9 +1,22 @@ +# Python imports +import json +from os import path + +# Lib imports + + +# Application imports from . import Window class WindowController: def __init__(self): - self.windows = [] + self.windows = [] + + USER_HOME = path.expanduser('~') + CONFIG_PATH = USER_HOME + "/.config/pyfm" + self.config_file = CONFIG_PATH + "/session.json" + def get_window(self, win_id): for window in self.windows: @@ -67,3 +80,31 @@ class WindowController: for window in self.windows: if window.id == win_id: return window.views + + def save_state(self): + windows = [] + for window in self.windows: + views = [] + for view in window.views: + views.append(view.get_current_directory()) + + windows.append( + [ + { + 'window':{ + "ID": str(window.id), + "Name": window.name, + "Nickname": window.nickname, + 'views': views + } + } + ] + ) + + with open(self.config_file, 'w') as outfile: + json.dump(windows, outfile, separators=(',', ':'), indent=4) + + def load_state(self): + if path.isfile(self.config_file): + with open(self.config_file) as infile: + return json.load(infile) diff --git a/src/shellfm/windows/view/View.py b/src/shellfm/windows/view/View.py index fef9543..102752a 100644 --- a/src/shellfm/windows/view/View.py +++ b/src/shellfm/windows/view/View.py @@ -41,7 +41,7 @@ class View(Settings, Launcher, Icon, Path): def load_directory(self): path = self.get_path() - self.dirs = [] + self.dirs = [".", ".."] self.vids = [] self.images = [] self.desktop = [] diff --git a/src/shellfm/windows/view/utils/Settings.py b/src/shellfm/windows/view/utils/Settings.py index cb0cc3d..7f78934 100644 --- a/src/shellfm/windows/view/utils/Settings.py +++ b/src/shellfm/windows/view/utils/Settings.py @@ -33,7 +33,7 @@ class Settings: ABS_THUMBS_PTH = BASE_THUMBS_PTH + "/normal" # Used for thumbnail generation STEAM_ICONS_PTH = BASE_THUMBS_PTH + "/steam_icons" CONTAINER_ICON_WH = [128, 128] - VIDEO_ICON_WH = [256, 128] + VIDEO_ICON_WH = [128, 64] SYS_ICON_WH = [56, 56] subpath = "" # modify 'home' folder path