Updated and cleaned up logic, added logic
This commit is contained in:
parent
171fa85d5d
commit
870f40de3c
@ -5,12 +5,14 @@ def main():
|
||||
window_controller = WindowController()
|
||||
|
||||
# Create "File Window" 1
|
||||
window_controller.add_window()
|
||||
window_controller.add_view_for_window(1)
|
||||
window = window_controller.create_window()
|
||||
window.nickname = "Win1"
|
||||
window_controller.add_view_for_window_by_nickname(window.nickname)
|
||||
|
||||
# Create "File Window" 2
|
||||
window_controller.add_window()
|
||||
window_controller.add_view_for_window(2)
|
||||
window2 = window_controller.create_window()
|
||||
window2.nickname = "Win2"
|
||||
window_controller.add_view_for_window_by_nickname(window2.nickname)
|
||||
|
||||
window_controller.list_windows()
|
||||
|
||||
|
@ -1,12 +1,34 @@
|
||||
# Python imports
|
||||
from random import randint
|
||||
|
||||
|
||||
# Lib imports
|
||||
|
||||
|
||||
# Application imports
|
||||
from .view import View
|
||||
|
||||
|
||||
class Window:
|
||||
def __init__(self):
|
||||
self.name = ""
|
||||
self.nickname = ""
|
||||
self.id = 0
|
||||
self.views = []
|
||||
self.id_length = 10
|
||||
self.id = ""
|
||||
self.name = ""
|
||||
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):
|
||||
view = View()
|
||||
@ -16,12 +38,10 @@ class Window:
|
||||
def pop_view(self):
|
||||
self.views.pop()
|
||||
|
||||
def delete_view(self, vid):
|
||||
i = -1
|
||||
def delete_view_by_id(self, vid):
|
||||
for view in self.views:
|
||||
i += 1
|
||||
if view.id == vid:
|
||||
del self.views[i]
|
||||
self.views.remove(view)
|
||||
break
|
||||
|
||||
|
||||
@ -32,3 +52,13 @@ class Window:
|
||||
|
||||
def get_view_by_index(self, 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)
|
||||
|
@ -11,44 +11,87 @@ from . import Window
|
||||
|
||||
class WindowController:
|
||||
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('~')
|
||||
CONFIG_PATH = USER_HOME + "/.config/pyfm"
|
||||
self.config_file = CONFIG_PATH + "/session.json"
|
||||
self.active_window_id = ""
|
||||
self.windows = []
|
||||
|
||||
|
||||
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):
|
||||
return self.windows
|
||||
def create_window(self):
|
||||
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)
|
||||
return window
|
||||
|
||||
|
||||
def add_view_for_window(self, win_id):
|
||||
for window in self.windows:
|
||||
if window.id == win_id:
|
||||
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):
|
||||
self.windows.pop()
|
||||
|
||||
def delete_window_by_id(self, win_id):
|
||||
i = 0
|
||||
for window in self.windows:
|
||||
if window.id == win_id:
|
||||
self.window.remove(win_id)
|
||||
self.windows.remove(window)
|
||||
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 = ""):
|
||||
for window in self.windows:
|
||||
@ -57,29 +100,32 @@ class WindowController:
|
||||
|
||||
def list_windows(self):
|
||||
for window in self.windows:
|
||||
print("\n[ Window ]")
|
||||
print("ID: " + str(window.id))
|
||||
print("Name: " + window.name)
|
||||
print("Nickname: " + window.nickname)
|
||||
print("View Count: " + str( len(window.views) ))
|
||||
print("\n\n[ Window ]")
|
||||
print(f"ID: {window.id}")
|
||||
print(f"Name: {window.name}")
|
||||
print(f"Nickname: {window.nickname}")
|
||||
print(f"View Count: {window.get_views_count()}")
|
||||
|
||||
|
||||
|
||||
def list_files_from_views_of_window(self, win_id):
|
||||
for window in self.windows:
|
||||
if window.id == win_id:
|
||||
for view in window.views:
|
||||
print(view.files)
|
||||
window.list_files_from_views()
|
||||
break
|
||||
|
||||
def get_views_count(self, win_id):
|
||||
for window in self.windows:
|
||||
if window.id == win_id:
|
||||
return len(window.views)
|
||||
return window.get_views_count()
|
||||
|
||||
def return_views_from_window(self, win_id):
|
||||
for window in self.windows:
|
||||
if window.id == win_id:
|
||||
return window.views
|
||||
return window.get_all_views()
|
||||
|
||||
|
||||
|
||||
|
||||
def save_state(self):
|
||||
windows = []
|
||||
@ -92,7 +138,7 @@ class WindowController:
|
||||
[
|
||||
{
|
||||
'window':{
|
||||
"ID": str(window.id),
|
||||
"ID": window.id,
|
||||
"Name": window.name,
|
||||
"Nickname": window.nickname,
|
||||
'views': views
|
||||
|
@ -15,20 +15,22 @@ from .utils import Settings, Launcher
|
||||
from .icons import Icon
|
||||
from . import Path
|
||||
|
||||
|
||||
class View(Settings, Launcher, Icon, Path):
|
||||
def __init__(self):
|
||||
self.id = ""
|
||||
self. logger = None
|
||||
self.id_length = 10
|
||||
|
||||
self.id = ""
|
||||
self.files = []
|
||||
self.dirs = []
|
||||
self.vids = []
|
||||
self.images = []
|
||||
self.desktop = []
|
||||
self.ungrouped = []
|
||||
self.id_length = 10
|
||||
|
||||
self.set_to_home()
|
||||
self.generate_id()
|
||||
self.set_to_home()
|
||||
|
||||
|
||||
def random_with_N_digits(self, n):
|
||||
@ -39,6 +41,7 @@ class View(Settings, Launcher, Icon, Path):
|
||||
def generate_id(self):
|
||||
self.id = str(self.random_with_N_digits(self.id_length))
|
||||
|
||||
|
||||
def load_directory(self):
|
||||
path = self.get_path()
|
||||
self.dirs = [".", ".."]
|
||||
|
Loading…
Reference in New Issue
Block a user