SolarFM/src/solarfm/shellfm/windows/tabs/path.py

65 lines
1.6 KiB
Python
Raw Normal View History

2021-10-10 06:45:55 +00:00
# Python imports
import os
# Lib imports
# Application imports
2021-10-10 06:45:55 +00:00
class Path:
2022-10-28 02:26:58 +00:00
def get_home(self) -> str:
2021-10-10 06:45:55 +00:00
return os.path.expanduser("~") + self.subpath
2022-10-28 02:26:58 +00:00
def get_path(self) -> str:
2022-01-29 21:14:50 +00:00
return f"/{'/'.join(self.path)}" if self.path else f"/{''.join(self.path)}"
2021-10-10 06:45:55 +00:00
2022-10-28 02:26:58 +00:00
def get_path_list(self) -> list:
2021-10-10 06:45:55 +00:00
return self.path
2022-10-28 02:26:58 +00:00
def push_to_path(self, dir: str):
2021-10-10 06:45:55 +00:00
self.path.append(dir)
self.load_directory()
2022-10-28 02:26:58 +00:00
def pop_from_path(self) -> None:
2022-01-29 21:14:50 +00:00
try:
2021-11-30 06:21:50 +00:00
self.path.pop()
2021-10-10 06:45:55 +00:00
2021-11-30 06:21:50 +00:00
if not self.go_past_home:
if self.get_home() not in self.get_path():
self.set_to_home()
2021-10-10 06:45:55 +00:00
2022-01-24 16:24:55 +00:00
self.load_directory()
2022-01-29 21:14:50 +00:00
except Exception as e:
pass
2021-10-10 06:45:55 +00:00
2022-10-28 02:26:58 +00:00
def set_path(self, path: str) -> bool:
if path == self.get_path():
2022-10-28 02:26:58 +00:00
return False
if os.path.isdir(path):
self.path = list( filter(None, path.replace("\\", "/").split('/')) )
self.load_directory()
return True
2021-11-15 03:40:05 +00:00
return False
2021-10-10 06:45:55 +00:00
2022-10-28 02:26:58 +00:00
def set_path_with_sub_path(self, sub_path: str) -> bool:
path = os.path.join(self.get_home(), sub_path)
if path == self.get_path():
2021-11-15 03:40:05 +00:00
return False
if os.path.isdir(path):
self.path = list( filter(None, path.replace("\\", "/").split('/')) )
self.load_directory()
return True
2021-11-15 03:40:05 +00:00
return False
2021-10-10 06:45:55 +00:00
2022-10-28 02:26:58 +00:00
def set_to_home(self) -> None:
2021-10-10 06:45:55 +00:00
home = os.path.expanduser("~") + self.subpath
path = list( filter(None, home.replace("\\", "/").split('/')) )
self.path = path
self.load_directory()