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