Added more type hints

This commit is contained in:
itdominator 2022-10-27 21:23:12 -05:00
parent 194f616b20
commit 57e5b8f2fc
3 changed files with 50 additions and 50 deletions

View File

@ -16,100 +16,100 @@ def threaded(fn):
class WindowController:
def __init__(self):
USER_HOME = path.expanduser('~')
CONFIG_PATH = f"{USER_HOME}/.config/solarfm"
self._session_file = f"{CONFIG_PATH}/session.json"
USER_HOME: str = path.expanduser('~')
CONFIG_PATH: str = f"{USER_HOME}/.config/solarfm"
self._session_file: srr = f"{CONFIG_PATH}/session.json"
self._event_sleep_time = 1
self._active_window_id = ""
self._active_tab_id = ""
self._windows = []
self._event_sleep_time: int = 1
self._active_window_id: str = ""
self._active_tab_id: str = ""
self._windows: list = []
def set_wid_and_tid(self, wid, tid):
def set_wid_and_tid(self, wid: int, tid: int) -> None:
self._active_window_id = str(wid)
self._active_tab_id = str(tid)
def get_active_wid_and_tid(self):
def get_active_wid_and_tid(self) -> list:
return self._active_window_id, self._active_tab_id
def create_window(self):
def create_window(self) -> Window:
window = Window()
window.set_nickname(f"window_{len(self._windows) + 1}")
window.set_nickname(f"window_{str(len(self._windows) + 1)}")
self._windows.append(window)
return window
def add_tab_for_window(self, win_id):
def add_tab_for_window(self, win_id: str) -> None:
for window in self._windows:
if window.get_id() == win_id:
return window.create_tab()
def add_tab_for_window_by_name(self, name):
def add_tab_for_window_by_name(self, name: str) -> None:
for window in self._windows:
if window.get_name() == name:
return window.create_tab()
def add_tab_for_window_by_nickname(self, nickname):
def add_tab_for_window_by_nickname(self, nickname: str) -> None:
for window in self._windows:
if window.get_nickname() == nickname:
return window.create_tab()
def pop_window(self):
def pop_window(self) -> None:
self._windows.pop()
def delete_window_by_id(self, win_id):
def delete_window_by_id(self, win_id: str) -> None:
for window in self._windows:
if window.get_id() == win_id:
self._windows.remove(window)
break
def delete_window_by_name(self, name):
def delete_window_by_name(self, name: str) -> str:
for window in self._windows:
if window.get_name() == name:
self._windows.remove(window)
break
def delete_window_by_nickname(self, nickname):
def delete_window_by_nickname(self, nickname: str) -> str:
for window in self._windows:
if window.get_nickname() == nickname:
self._windows.remove(window)
break
def get_window_by_id(self, win_id):
def get_window_by_id(self, win_id: str) -> Window:
for window in self._windows:
if window.get_id() == win_id:
return window
raise(f"No Window by ID {win_id} found!")
def get_window_by_name(self, name):
def get_window_by_name(self, name: str) -> Window:
for window in self._windows:
if window.get_name() == name:
return window
raise(f"No Window by Name {name} found!")
def get_window_by_nickname(self, nickname):
def get_window_by_nickname(self, nickname: str) -> Window:
for window in self._windows:
if window.get_nickname() == nickname:
return window
raise(f"No Window by Nickname {nickname} found!")
def get_window_by_index(self, index):
def get_window_by_index(self, index: int) -> Window:
return self._windows[index]
def get_all_windows(self):
def get_all_windows(self) -> list:
return self._windows
def set_window_nickname(self, win_id = None, nickname = ""):
def set_window_nickname(self, win_id: str = None, nickname: str = "") -> None:
for window in self._windows:
if window.get_id() == win_id:
window.set_nickname(nickname)
def list_windows(self):
def list_windows(self) -> None:
print("\n[ ---- Windows ---- ]\n")
for window in self._windows:
print(f"\nID: {window.get_id()}")
@ -121,18 +121,18 @@ class WindowController:
def list_files_from_tabs_of_window(self, win_id):
def list_files_from_tabs_of_window(self, win_id: str) -> None:
for window in self._windows:
if window.get_id() == win_id:
window.list_files_from_tabs()
break
def get_tabs_count(self, win_id):
def get_tabs_count(self, win_id: str) -> int:
for window in self._windows:
if window.get_id() == win_id:
return window.get_tabs_count()
def get_tabs_from_window(self, win_id):
def get_tabs_from_window(self, win_id: str) -> list:
for window in self._windows:
if window.get_id() == win_id:
return window.get_all_tabs()
@ -140,13 +140,13 @@ class WindowController:
def unload_tabs_and_windows(self):
def unload_tabs_and_windows(self) -> None:
for window in self._windows:
window.get_all_tabs().clear()
self._windows.clear()
def save_state(self, session_file = None):
def save_state(self, session_file: str = None) -> None:
if not session_file:
session_file = self._session_file
@ -174,7 +174,7 @@ class WindowController:
else:
raise Exception("Window data corrupted! Can not save session!")
def get_state_from_file(self, session_file = None):
def get_state_from_file(self, session_file: str = None) -> dict:
if not session_file:
session_file = self._session_file

View File

@ -20,25 +20,25 @@ from .path import Path
class Tab(Settings, FileHandler, Launcher, Icon, Path):
def __init__(self):
self.logger = None
self._id_length = 10
self.logger = None
self._id_length: int = 10
self._id = ""
self._wid = None
self._dir_watcher = None
self._hide_hidden = self.HIDE_HIDDEN_FILES
self._files = []
self._dirs = []
self._vids = []
self._images = []
self._desktop = []
self._ungrouped = []
self._hidden = []
self._id: str = ""
self._wid: str = None
self._dir_watcher = None
self._hide_hidden: bool = self.HIDE_HIDDEN_FILES
self._files: list = []
self._dirs: list = []
self._vids: list = []
self._images: list = []
self._desktop: list = []
self._ungrouped: list = []
self._hidden: list = []
self._generate_id()
self.set_to_home()
def load_directory(self):
def load_directory(self) -> None:
path = self.get_path()
self._dirs = []
self._vids = []
@ -97,7 +97,7 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
return False
def get_not_hidden_count(self):
def get_not_hidden_count(self) -> int:
return len(self._files) + \
len(self._dirs) + \
len(self._vids) + \
@ -111,7 +111,7 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
def get_files_count(self) -> int:
return len(self._files)
def get_path_part_from_hash(self, hash) -> str:
def get_path_part_from_hash(self, hash: str) -> str:
files = self.get_files()
file = None
@ -154,7 +154,7 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
return data
def get_gtk_icon_str_combo(self):
def get_gtk_icon_str_combo(self) -> list:
data = []
dir = self.get_current_directory()
for file in self._files:
@ -163,7 +163,7 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
return data
def get_current_directory(self):
def get_current_directory(self) -> str:
return self.get_path()
def get_current_sub_path(self) -> str:

View File

@ -11,7 +11,7 @@ from .tabs.tab import Tab
class Window:
def __init__(self):
self._id_length: str = 10
self._id_length: int = 10
self._id: str = ""
self._name: str = ""
self._nickname:str = ""