Added type hints, added set active tab, updated strings to fstrings
This commit is contained in:
parent
622a4f979e
commit
194f616b20
|
@ -158,7 +158,6 @@ class WindowController:
|
||||||
tabs.append(tab.get_current_directory())
|
tabs.append(tab.get_current_directory())
|
||||||
|
|
||||||
windows.append(
|
windows.append(
|
||||||
[
|
|
||||||
{
|
{
|
||||||
'window':{
|
'window':{
|
||||||
"ID": window.get_id(),
|
"ID": window.get_id(),
|
||||||
|
@ -168,7 +167,6 @@ class WindowController:
|
||||||
'tabs': tabs
|
'tabs': tabs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
with open(session_file, 'w') as outfile:
|
with open(session_file, 'w') as outfile:
|
||||||
|
|
|
@ -42,11 +42,14 @@ class Icon(DesktopIconMixin, VideoIconMixin):
|
||||||
thumbnl = self.parse_desktop_files(full_path)
|
thumbnl = self.parse_desktop_files(full_path)
|
||||||
|
|
||||||
return thumbnl
|
return thumbnl
|
||||||
except Exception as e:
|
except Exception:
|
||||||
|
...
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def create_thumbnail(self, dir, file, scrub_percent = "65%"):
|
def create_thumbnail(self, dir, file, scrub_percent = "65%"):
|
||||||
full_path = f"{dir}/{file}"
|
full_path = f"{dir}/{file}"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
file_hash = hashlib.sha256(str.encode(full_path)).hexdigest()
|
file_hash = hashlib.sha256(str.encode(full_path)).hexdigest()
|
||||||
hash_img_pth = f"{self.ABS_THUMBS_PTH}/{file_hash}.jpg"
|
hash_img_pth = f"{self.ABS_THUMBS_PTH}/{file_hash}.jpg"
|
||||||
|
@ -61,6 +64,7 @@ class Icon(DesktopIconMixin, VideoIconMixin):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Thumbnail generation issue:")
|
print("Thumbnail generation issue:")
|
||||||
print( repr(e) )
|
print( repr(e) )
|
||||||
|
|
||||||
return GdkPixbuf.Pixbuf.new_from_file(f"{self.DEFAULT_ICONS}/video.png")
|
return GdkPixbuf.Pixbuf.new_from_file(f"{self.DEFAULT_ICONS}/video.png")
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,19 +72,20 @@ class Icon(DesktopIconMixin, VideoIconMixin):
|
||||||
if not wxh:
|
if not wxh:
|
||||||
wxh = self.video_icon_wh
|
wxh = self.video_icon_wh
|
||||||
|
|
||||||
|
if path:
|
||||||
try:
|
try:
|
||||||
if path.lower().endswith(".gif"):
|
if path.lower().endswith(".gif"):
|
||||||
return GdkPixbuf.PixbufAnimation.new_from_file(path) \
|
return GdkPixbuf.PixbufAnimation.new_from_file(path) \
|
||||||
.get_static_image() \
|
.get_static_image() \
|
||||||
.scale_simple(wxh[0], wxh[1], GdkPixbuf.InterpType.BILINEAR)
|
.scale_simple(wxh[0], wxh[1], GdkPixbuf.InterpType.BILINEAR)
|
||||||
else:
|
elif path.lower().endswith(".webp") and PImage:
|
||||||
if PImage and path.lower().endswith(".webp"):
|
|
||||||
return self.image2pixbuf(path, wxh)
|
return self.image2pixbuf(path, wxh)
|
||||||
else:
|
|
||||||
return GdkPixbuf.Pixbuf.new_from_file_at_scale(path, wxh[0], wxh[1], True)
|
return GdkPixbuf.Pixbuf.new_from_file_at_scale(path, wxh[0], wxh[1], True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Image Scaling Issue:")
|
print("Image Scaling Issue:")
|
||||||
print( repr(e) )
|
print( repr(e) )
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def image2pixbuf(self, path, wxh):
|
def image2pixbuf(self, path, wxh):
|
||||||
|
@ -101,6 +106,7 @@ class Icon(DesktopIconMixin, VideoIconMixin):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Image from file Issue:")
|
print("Image from file Issue:")
|
||||||
print( repr(e) )
|
print( repr(e) )
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def return_generic_icon(self):
|
def return_generic_icon(self):
|
||||||
|
|
|
@ -50,13 +50,8 @@ class DesktopIconMixin:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def traverse_icons_folder(self, path, icon):
|
def traverse_icons_folder(self, path, icon):
|
||||||
alt_icon_path = ""
|
|
||||||
|
|
||||||
for (dirpath, dirnames, filenames) in os.walk(path):
|
for (dirpath, dirnames, filenames) in os.walk(path):
|
||||||
for file in filenames:
|
for file in filenames:
|
||||||
appNM = "application-x-" + icon
|
appNM = "application-x-" + icon
|
||||||
if icon in file or appNM in file:
|
if icon in file or appNM in file:
|
||||||
alt_icon_path = dirpath + "/" + file
|
return f"{dirpath}/{file}"
|
||||||
break
|
|
||||||
|
|
||||||
return alt_icon_path
|
|
||||||
|
|
|
@ -7,20 +7,20 @@ import os
|
||||||
|
|
||||||
|
|
||||||
class Path:
|
class Path:
|
||||||
def get_home(self):
|
def get_home(self) -> str:
|
||||||
return os.path.expanduser("~") + self.subpath
|
return os.path.expanduser("~") + self.subpath
|
||||||
|
|
||||||
def get_path(self):
|
def get_path(self) -> str:
|
||||||
return f"/{'/'.join(self.path)}" if self.path else f"/{''.join(self.path)}"
|
return f"/{'/'.join(self.path)}" if self.path else f"/{''.join(self.path)}"
|
||||||
|
|
||||||
def get_path_list(self):
|
def get_path_list(self) -> list:
|
||||||
return self.path
|
return self.path
|
||||||
|
|
||||||
def push_to_path(self, dir):
|
def push_to_path(self, dir: str):
|
||||||
self.path.append(dir)
|
self.path.append(dir)
|
||||||
self.load_directory()
|
self.load_directory()
|
||||||
|
|
||||||
def pop_from_path(self):
|
def pop_from_path(self) -> None:
|
||||||
try:
|
try:
|
||||||
self.path.pop()
|
self.path.pop()
|
||||||
|
|
||||||
|
@ -32,9 +32,9 @@ class Path:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def set_path(self, path):
|
def set_path(self, path: str) -> bool:
|
||||||
if path == self.get_path():
|
if path == self.get_path():
|
||||||
return
|
return False
|
||||||
|
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
self.path = list( filter(None, path.replace("\\", "/").split('/')) )
|
self.path = list( filter(None, path.replace("\\", "/").split('/')) )
|
||||||
|
@ -43,7 +43,7 @@ class Path:
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def set_path_with_sub_path(self, sub_path):
|
def set_path_with_sub_path(self, sub_path: str) -> bool:
|
||||||
path = os.path.join(self.get_home(), sub_path)
|
path = os.path.join(self.get_home(), sub_path)
|
||||||
if path == self.get_path():
|
if path == self.get_path():
|
||||||
return False
|
return False
|
||||||
|
@ -55,7 +55,7 @@ class Path:
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def set_to_home(self):
|
def set_to_home(self) -> None:
|
||||||
home = os.path.expanduser("~") + self.subpath
|
home = os.path.expanduser("~") + self.subpath
|
||||||
path = list( filter(None, home.replace("\\", "/").split('/')) )
|
path = list( filter(None, home.replace("\\", "/").split('/')) )
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
|
@ -105,13 +105,13 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
|
||||||
len(self._desktop) + \
|
len(self._desktop) + \
|
||||||
len(self._ungrouped)
|
len(self._ungrouped)
|
||||||
|
|
||||||
def get_hidden_count(self):
|
def get_hidden_count(self) -> int:
|
||||||
return len(self._hidden)
|
return len(self._hidden)
|
||||||
|
|
||||||
def get_files_count(self):
|
def get_files_count(self) -> int:
|
||||||
return len(self._files)
|
return len(self._files)
|
||||||
|
|
||||||
def get_path_part_from_hash(self, hash):
|
def get_path_part_from_hash(self, hash) -> str:
|
||||||
files = self.get_files()
|
files = self.get_files()
|
||||||
file = None
|
file = None
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
|
||||||
|
|
||||||
return file
|
return file
|
||||||
|
|
||||||
def get_files_formatted(self):
|
def get_files_formatted(self) -> dict:
|
||||||
files = self._hash_set(self._files),
|
files = self._hash_set(self._files),
|
||||||
dirs = self._hash_set(self._dirs),
|
dirs = self._hash_set(self._dirs),
|
||||||
videos = self.get_videos(),
|
videos = self.get_videos(),
|
||||||
|
@ -166,54 +166,54 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
|
||||||
def get_current_directory(self):
|
def get_current_directory(self):
|
||||||
return self.get_path()
|
return self.get_path()
|
||||||
|
|
||||||
def get_current_sub_path(self):
|
def get_current_sub_path(self) -> str:
|
||||||
path = self.get_path()
|
path = self.get_path()
|
||||||
home = f"{self.get_home()}/"
|
home = f"{self.get_home()}/"
|
||||||
return path.replace(home, "")
|
return path.replace(home, "")
|
||||||
|
|
||||||
def get_end_of_path(self):
|
def get_end_of_path(self) -> str:
|
||||||
parts = self.get_current_directory().split("/")
|
parts = self.get_current_directory().split("/")
|
||||||
size = len(parts)
|
size = len(parts)
|
||||||
return parts[size - 1]
|
return parts[size - 1]
|
||||||
|
|
||||||
|
|
||||||
def set_hiding_hidden(self, state):
|
def set_hiding_hidden(self, state: bool) -> None:
|
||||||
self._hide_hidden = state
|
self._hide_hidden = state
|
||||||
|
|
||||||
def is_hiding_hidden(self):
|
def is_hiding_hidden(self) -> bool:
|
||||||
return self._hide_hidden
|
return self._hide_hidden
|
||||||
|
|
||||||
def get_dot_dots(self):
|
def get_dot_dots(self) -> list:
|
||||||
return self._hash_set(['.', '..'])
|
return self._hash_set(['.', '..'])
|
||||||
|
|
||||||
def get_files(self):
|
def get_files(self) -> list:
|
||||||
return self._hash_set(self._files)
|
return self._hash_set(self._files)
|
||||||
|
|
||||||
def get_dirs(self):
|
def get_dirs(self) -> list:
|
||||||
return self._hash_set(self._dirs)
|
return self._hash_set(self._dirs)
|
||||||
|
|
||||||
def get_videos(self):
|
def get_videos(self) -> list:
|
||||||
return self._hash_set(self._vids)
|
return self._hash_set(self._vids)
|
||||||
|
|
||||||
def get_images(self):
|
def get_images(self) -> list:
|
||||||
return self._hash_set(self._images)
|
return self._hash_set(self._images)
|
||||||
|
|
||||||
def get_desktops(self):
|
def get_desktops(self) -> list:
|
||||||
return self._hash_set(self._desktop)
|
return self._hash_set(self._desktop)
|
||||||
|
|
||||||
def get_ungrouped(self):
|
def get_ungrouped(self) -> list:
|
||||||
return self._hash_set(self._ungrouped)
|
return self._hash_set(self._ungrouped)
|
||||||
|
|
||||||
def get_hidden(self):
|
def get_hidden(self) -> list:
|
||||||
return self._hash_set(self._hidden)
|
return self._hash_set(self._hidden)
|
||||||
|
|
||||||
def get_id(self):
|
def get_id(self) -> str:
|
||||||
return self._id
|
return self._id
|
||||||
|
|
||||||
def set_wid(self, _wid):
|
def set_wid(self, _wid: str) -> None:
|
||||||
self._wid = _wid
|
self._wid = _wid
|
||||||
|
|
||||||
def get_wid(self):
|
def get_wid(self) -> str:
|
||||||
return self._wid
|
return self._wid
|
||||||
|
|
||||||
def set_dir_watcher(self, watcher):
|
def set_dir_watcher(self, watcher):
|
||||||
|
@ -228,19 +228,19 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
|
||||||
def _natural_keys(self, text):
|
def _natural_keys(self, text):
|
||||||
return [ self._atoi(c) for c in re.split('(\d+)',text) ]
|
return [ self._atoi(c) for c in re.split('(\d+)',text) ]
|
||||||
|
|
||||||
def _hash_text(self, text):
|
def _hash_text(self, text) -> str:
|
||||||
return hashlib.sha256(str.encode(text)).hexdigest()[:18]
|
return hashlib.sha256(str.encode(text)).hexdigest()[:18]
|
||||||
|
|
||||||
def _hash_set(self, arry):
|
def _hash_set(self, arry: list) -> list:
|
||||||
data = []
|
data = []
|
||||||
for arr in arry:
|
for arr in arry:
|
||||||
data.append([arr, self._hash_text(arr)])
|
data.append([arr, self._hash_text(arr)])
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def _random_with_N_digits(self, n):
|
def _random_with_N_digits(self, n: int) -> int:
|
||||||
range_start = 10**(n-1)
|
range_start = 10**(n-1)
|
||||||
range_end = (10**n)-1
|
range_end = (10**n)-1
|
||||||
return randint(range_start, range_end)
|
return randint(range_start, range_end)
|
||||||
|
|
||||||
def _generate_id(self):
|
def _generate_id(self) -> str:
|
||||||
self._id = str(self._random_with_N_digits(self._id_length))
|
self._id = str(self._random_with_N_digits(self._id_length))
|
||||||
|
|
|
@ -25,7 +25,7 @@ class Settings:
|
||||||
FFMPG_THUMBNLR = f"{CONFIG_PATH}/ffmpegthumbnailer" # Thumbnail generator binary
|
FFMPG_THUMBNLR = f"{CONFIG_PATH}/ffmpegthumbnailer" # Thumbnail generator binary
|
||||||
REMUX_FOLDER = f"{USER_HOME}/.remuxs" # Remuxed files folder
|
REMUX_FOLDER = f"{USER_HOME}/.remuxs" # Remuxed files folder
|
||||||
|
|
||||||
ICON_DIRS = ["/usr/share/pixmaps", "/usr/share/icons", f"{USER_HOME}/.icons" ,]
|
ICON_DIRS = ["/usr/share/icons", f"{USER_HOME}/.icons" "/usr/share/pixmaps"]
|
||||||
BASE_THUMBS_PTH = f"{USER_HOME}/.thumbnails" # Used for thumbnail generation
|
BASE_THUMBS_PTH = f"{USER_HOME}/.thumbnails" # Used for thumbnail generation
|
||||||
ABS_THUMBS_PTH = f"{BASE_THUMBS_PTH}/normal" # Used for thumbnail generation
|
ABS_THUMBS_PTH = f"{BASE_THUMBS_PTH}/normal" # Used for thumbnail generation
|
||||||
STEAM_ICONS_PTH = f"{BASE_THUMBS_PTH}/steam_icons"
|
STEAM_ICONS_PTH = f"{BASE_THUMBS_PTH}/steam_icons"
|
||||||
|
|
|
@ -11,62 +11,68 @@ from .tabs.tab import Tab
|
||||||
|
|
||||||
class Window:
|
class Window:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._id_length = 10
|
self._id_length: str = 10
|
||||||
self._id = ""
|
self._id: str = ""
|
||||||
self._name = ""
|
self._name: str = ""
|
||||||
self._nickname = ""
|
self._nickname:str = ""
|
||||||
self._isHidden = False
|
self._isHidden: bool = False
|
||||||
self._tabs = []
|
self._active_tab: int = 0
|
||||||
|
self._tabs: list = []
|
||||||
|
|
||||||
self._generate_id()
|
self._generate_id()
|
||||||
self._set_name()
|
self._set_name()
|
||||||
|
|
||||||
|
|
||||||
def create_tab(self):
|
def create_tab(self) -> Tab:
|
||||||
tab = Tab()
|
tab = Tab()
|
||||||
self._tabs.append(tab)
|
self._tabs.append(tab)
|
||||||
return tab
|
return tab
|
||||||
|
|
||||||
def pop_tab(self):
|
def pop_tab(self) -> None:
|
||||||
self._tabs.pop()
|
self._tabs.pop()
|
||||||
|
|
||||||
def delete_tab_by_id(self, tid):
|
def delete_tab_by_id(self, tid: str):
|
||||||
for tab in self._tabs:
|
for tab in self._tabs:
|
||||||
if tab.get_id() == tid:
|
if tab.get_id() == tid:
|
||||||
self._tabs.remove(tab)
|
self._tabs.remove(tab)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
def get_tab_by_id(self, tid):
|
def get_tab_by_id(self, tid: str) -> Tab:
|
||||||
for tab in self._tabs:
|
for tab in self._tabs:
|
||||||
if tab.get_id() == tid:
|
if tab.get_id() == tid:
|
||||||
return tab
|
return tab
|
||||||
|
|
||||||
def get_tab_by_index(self, index):
|
def get_tab_by_index(self, index) -> Tab:
|
||||||
return self._tabs[index]
|
return self._tabs[index]
|
||||||
|
|
||||||
def get_tabs_count(self):
|
def get_tabs_count(self) -> int:
|
||||||
return len(self._tabs)
|
return len(self._tabs)
|
||||||
|
|
||||||
def get_all_tabs(self):
|
def get_all_tabs(self) -> list:
|
||||||
return self._tabs
|
return self._tabs
|
||||||
|
|
||||||
def get_id(self):
|
def get_id(self) -> str:
|
||||||
return self._id
|
return self._id
|
||||||
|
|
||||||
def get_name(self):
|
def get_name(self) -> str:
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
def get_nickname(self):
|
def get_nickname(self) -> str:
|
||||||
return self._nickname
|
return self._nickname
|
||||||
|
|
||||||
def is_hidden(self):
|
def is_hidden(self) -> bool:
|
||||||
return self._isHidden
|
return self._isHidden
|
||||||
|
|
||||||
def list_files_from_tabs(self):
|
def list_files_from_tabs(self) -> None:
|
||||||
for tab in self._tabs:
|
for tab in self._tabs:
|
||||||
print(tab.get_files())
|
print(tab.get_files())
|
||||||
|
|
||||||
|
def set_active_tab(self, index: int):
|
||||||
|
self._active_tab = index
|
||||||
|
|
||||||
|
def get_active_tab(self) -> Tab:
|
||||||
|
return self._tabs[self._active_tab]
|
||||||
|
|
||||||
def set_nickname(self, nickname):
|
def set_nickname(self, nickname):
|
||||||
self._nickname = f"{nickname}"
|
self._nickname = f"{nickname}"
|
||||||
|
|
Loading…
Reference in New Issue