Updated save and load logic
This commit is contained in:
parent
141a50a224
commit
171fa85d5d
@ -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)
|
||||
|
@ -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 = []
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user