Updated and cleaned up logic, added logic

This commit is contained in:
itdominator 2021-04-27 21:51:45 -05:00
parent 171fa85d5d
commit 870f40de3c
4 changed files with 124 additions and 43 deletions

View File

@ -5,12 +5,14 @@ def main():
window_controller = WindowController() window_controller = WindowController()
# Create "File Window" 1 # Create "File Window" 1
window_controller.add_window() window = window_controller.create_window()
window_controller.add_view_for_window(1) window.nickname = "Win1"
window_controller.add_view_for_window_by_nickname(window.nickname)
# Create "File Window" 2 # Create "File Window" 2
window_controller.add_window() window2 = window_controller.create_window()
window_controller.add_view_for_window(2) window2.nickname = "Win2"
window_controller.add_view_for_window_by_nickname(window2.nickname)
window_controller.list_windows() window_controller.list_windows()

View File

@ -1,12 +1,34 @@
# Python imports
from random import randint
# Lib imports
# Application imports
from .view import View from .view import View
class Window: class Window:
def __init__(self): def __init__(self):
self.name = "" self.id_length = 10
self.nickname = "" self.id = ""
self.id = 0 self.name = ""
self.views = [] self.nickname = ""
self.views = []
self.generate_id()
def random_with_N_digits(self, n):
range_start = 10**(n-1)
range_end = (10**n)-1
return randint(range_start, range_end)
def generate_id(self):
self.id = str(self.random_with_N_digits(self.id_length))
def create_view(self): def create_view(self):
view = View() view = View()
@ -16,12 +38,10 @@ class Window:
def pop_view(self): def pop_view(self):
self.views.pop() self.views.pop()
def delete_view(self, vid): def delete_view_by_id(self, vid):
i = -1
for view in self.views: for view in self.views:
i += 1
if view.id == vid: if view.id == vid:
del self.views[i] self.views.remove(view)
break break
@ -32,3 +52,13 @@ class Window:
def get_view_by_index(self, index): def get_view_by_index(self, index):
return self.views[index] return self.views[index]
def get_views_count(self):
return len(self.views)
def get_all_views(self):
return self.views
def list_files_from_views(self):
for view in self.views:
print(view.files)

View File

@ -11,44 +11,87 @@ from . import Window
class WindowController: class WindowController:
def __init__(self): def __init__(self):
self.windows = [] USER_HOME = path.expanduser('~')
CONFIG_PATH = USER_HOME + "/.config/pyfm"
self.config_file = CONFIG_PATH + "/session.json"
USER_HOME = path.expanduser('~') self.active_window_id = ""
CONFIG_PATH = USER_HOME + "/.config/pyfm" self.windows = []
self.config_file = CONFIG_PATH + "/session.json"
def get_window(self, win_id):
for window in self.windows:
if window.id == win_id:
return window
raise("No Window by ID {} found!".format(win_id))
def get_windows(self): def create_window(self):
return self.windows window = Window()
window.name = "window_" + window.id
window.nickname = "window_" + str(len(self.windows) + 1)
def add_window(self):
window = Window()
window.id = len(self.windows) + 1
window.name = "window_" + str(window.id)
self.windows.append(window) self.windows.append(window)
return window
def add_view_for_window(self, win_id): def add_view_for_window(self, win_id):
for window in self.windows: for window in self.windows:
if window.id == win_id: if window.id == win_id:
return window.create_view() return window.create_view()
def add_view_for_window_by_name(self, name):
for window in self.windows:
if window.name == name:
return window.create_view()
def add_view_for_window_by_nickname(self, nickname):
for window in self.windows:
if window.nickname == nickname:
return window.create_view()
def pop_window(self): def pop_window(self):
self.windows.pop() self.windows.pop()
def delete_window_by_id(self, win_id): def delete_window_by_id(self, win_id):
i = 0
for window in self.windows: for window in self.windows:
if window.id == win_id: if window.id == win_id:
self.window.remove(win_id) self.windows.remove(window)
break break
i += 1
def delete_window_by_name(self, name):
for window in self.windows:
if window.name == name:
self.windows.remove(window)
break
def delete_window_by_nickname(self, nickname):
for window in self.windows:
if window.nickname == nickname:
self.windows.remove(window)
break
def get_window_by_id(self, win_id):
for window in self.windows:
if window.id == win_id:
return window
raise(f"No Window by ID {win_id} found!")
def get_window_by_name(self, name):
for window in self.windows:
if window.name == name:
return window
raise(f"No Window by Name {name} found!")
def get_window_by_nickname(self, nickname):
for window in self.windows:
if window.nickname == nickname:
return window
raise(f"No Window by Nickname {nickname} found!")
def get_window_by_index(self, index):
return self.windows[index]
def get_all_windows(self):
return self.windows
def set_window_nickname(self, win_id = None, nickname = ""): def set_window_nickname(self, win_id = None, nickname = ""):
for window in self.windows: for window in self.windows:
@ -57,29 +100,32 @@ class WindowController:
def list_windows(self): def list_windows(self):
for window in self.windows: for window in self.windows:
print("\n[ Window ]") print("\n\n[ Window ]")
print("ID: " + str(window.id)) print(f"ID: {window.id}")
print("Name: " + window.name) print(f"Name: {window.name}")
print("Nickname: " + window.nickname) print(f"Nickname: {window.nickname}")
print("View Count: " + str( len(window.views) )) print(f"View Count: {window.get_views_count()}")
def list_files_from_views_of_window(self, win_id): def list_files_from_views_of_window(self, win_id):
for window in self.windows: for window in self.windows:
if window.id == win_id: if window.id == win_id:
for view in window.views: window.list_files_from_views()
print(view.files)
break break
def get_views_count(self, win_id): def get_views_count(self, win_id):
for window in self.windows: for window in self.windows:
if window.id == win_id: if window.id == win_id:
return len(window.views) return window.get_views_count()
def return_views_from_window(self, win_id): def return_views_from_window(self, win_id):
for window in self.windows: for window in self.windows:
if window.id == win_id: if window.id == win_id:
return window.views return window.get_all_views()
def save_state(self): def save_state(self):
windows = [] windows = []
@ -92,7 +138,7 @@ class WindowController:
[ [
{ {
'window':{ 'window':{
"ID": str(window.id), "ID": window.id,
"Name": window.name, "Name": window.name,
"Nickname": window.nickname, "Nickname": window.nickname,
'views': views 'views': views

View File

@ -15,20 +15,22 @@ from .utils import Settings, Launcher
from .icons import Icon from .icons import Icon
from . import Path from . import Path
class View(Settings, Launcher, Icon, Path): class View(Settings, Launcher, Icon, Path):
def __init__(self): def __init__(self):
self.id = ""
self. logger = None self. logger = None
self.id_length = 10
self.id = ""
self.files = [] self.files = []
self.dirs = [] self.dirs = []
self.vids = [] self.vids = []
self.images = [] self.images = []
self.desktop = [] self.desktop = []
self.ungrouped = [] self.ungrouped = []
self.id_length = 10
self.set_to_home()
self.generate_id() self.generate_id()
self.set_to_home()
def random_with_N_digits(self, n): def random_with_N_digits(self, n):
@ -39,6 +41,7 @@ class View(Settings, Launcher, Icon, Path):
def generate_id(self): def generate_id(self):
self.id = str(self.random_with_N_digits(self.id_length)) self.id = str(self.random_with_N_digits(self.id_length))
def load_directory(self): def load_directory(self):
path = self.get_path() path = self.get_path()
self.dirs = [".", ".."] self.dirs = [".", ".."]