Skip to content

Commit

Permalink
V0.23.2 Add Teams Folder Compatability
Browse files Browse the repository at this point in the history
  • Loading branch information
domhnallmorr committed Jun 18, 2022
1 parent 49d061d commit d69591e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 135 deletions.
Binary file modified src/__pycache__/branch_tab.cpython-39.pyc
Binary file not shown.
Binary file modified src/__pycache__/explorer_backend.cpython-39.pyc
Binary file not shown.
8 changes: 7 additions & 1 deletion src/branch_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ def OnDoubleClick(self, event):
if os.path.isdir(directory):
self.update_tab(directory)
else:
msg = 'This directory does not exist, it may have been moved or deleted'
try:
self.update_tab(directory)
except:
pass
msg = 'This directory does not exist, it may have been moved or deleted'

else:
if os.path.isfile(os.path.join(self.explorer.current_directory, current_selection[1][0])):
Expand Down Expand Up @@ -240,6 +244,7 @@ def check_for_plugins(self, name, is_file):
plugins.append(plugin['name'])

return plugins

def on_right_click_heading(self, event):
col = self.treeview.identify_column(event.x)
if col == '#2':
Expand Down Expand Up @@ -295,6 +300,7 @@ def open_in_text_editor(self, app=None):
subprocess.call([fr"{self.mainapp.text_editor}", fr"{self.explorer.current_directory}\\{current_selection[1][0]}"])
else:
messagebox.showerror('Error', message='Default Text Editor has not been Defined')

def open_with_app(self, app, file):
subprocess.call([app, file])

Expand Down
185 changes: 51 additions & 134 deletions src/explorer_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,151 +17,68 @@ def __init__(self, mainapp):
def get_default_directory(self):
return os.getcwd()

# def list_directory(self, directory=None, mode=None, sort=None):
# if directory == None:
# directory = self.current_directory
# try:
# # Handle Directories
# directory_data = []
# files_dirs = os.listdir(directory)

# if len(files_dirs) > 200:
# directories = [o for o in files_dirs if os.path.isdir(os.path.join(directory,o))]
# for d in directories:
# directory_data.append([d, '-', 'Folder', '-'])

# # Handle Files
# file_data = []
# files = [o for o in files_dirs if not os.path.isdir(os.path.join(directory,o))]
# for f in files:
# full_path = os.path.join(directory,f)

# size = os.path.getsize(full_path)*0.001 # in kb

# modified = os.path.getmtime(full_path)
# modified = datetime.datetime.fromtimestamp(modified)

# if sort != 'size':
# file_data.append([f, modified.strftime("%d/%m/%Y, %H:%M:%S"), self.get_file_type(f), f'{int(size):,} KB'])
# else:
# file_data.append([f, modified.strftime("%d/%m/%Y, %H:%M:%S"), self.get_file_type(f), int(size)])

# else:
# # Large Folders
# data = subprocess.run(f'dir "{directory}"', shell=True, stdout=subprocess.PIPE).stdout.splitlines()
# data = data[5:-2]
# directory_data = []
# file_data = []
# for d in data:
# d= d.decode("utf-8")

# if '<DIR>' in d:
# d = d.split('<DIR>')
# if d[-1].strip() != '.' and d[-1].strip() != '..':
# directory_data.append([d[-1].strip(), '-', 'Folder', '-'])
# else:
# d = d.split()
# file_data.append([' '.join(d[3:]), '-', 'File', '-'])

# #file_data.append([f, '-', 'File', '-'])
# if mode == None:
# if self.current_directory != directory:
# self.previous_directories.append(self.current_directory)
# self.forward_directories.clear()
# elif mode == 'back': # when user clicks back arrow button
# self.previous_directories.pop()
# self.forward_directories.appendleft(self.current_directory)
# elif mode == 'fwd':
# self.forward_directories.popleft()
# self.previous_directories.append(self.current_directory)

# if sort == 'date':
# directory_data = list(reversed(sorted(directory_data, key=lambda x: x[1])))
# file_data = list(reversed(sorted(file_data, key=lambda x: x[1])))
# elif sort == 'file_type':
# directory_data = list(reversed(sorted(directory_data, key=lambda x: x[2])))
# file_data = list(reversed(sorted(file_data, key=lambda x: x[2])))
# elif sort == 'size':
# directory_data = list(reversed(sorted(directory_data, key=lambda x: x[3])))
# file_data = list(reversed(sorted(file_data, key=lambda x: x[3])))
# for f in file_data:
# f[-1] = f'{int(f[-1]):,} KB'

# self.current_directory = directory

# except PermissionError:
# directory_data = 'Permission Denied'
# file_data = ''
# except Exception as e:
# print(e)
# directory_data = 'An Error Ocurred'
# file_data = ''
# if not os.path.isdir(directory):
# directory_data = 'Location Does Not Exist'
# file_data = ''

# #for i in file_data:
# # directory_data.append(i)

# return directory_data + file_data

def list_directory(self, directory=None, mode=None, sort=None):
file_data = ''

if os.path.isdir(directory):
data = subprocess.run(f'dir "{directory}"', shell=True, stdout=subprocess.PIPE).stdout.splitlines()

if type(data) is list:
data = data[5:-2]
directory_data = []
file_data = []
for d in data:
d= d.decode("utf-8")

if '<DIR>' in d:
d = d.split('<DIR>')
if d[-1].strip() != '.' and d[-1].strip() != '..':
directory_data.append([d[-1].strip(), '-', 'Folder', '-'])
else:
d = d.split()
filename = ' '.join(d[3:])
#if os.path.isdir(directory):
data = subprocess.run(f'dir "{directory}"', shell=True, stdout=subprocess.PIPE).stdout.splitlines()

if type(data) is list:
data = data[5:-2]
directory_data = []
file_data = []
for d in data:
d= d.decode("utf-8")

if '<DIR>' in d:
d = d.split('<DIR>')
if d[-1].strip() != '.' and d[-1].strip() != '..':
directory_data.append([d[-1].strip(), '-', 'Folder', '-'])
else:
d = d.split()
filename = ' '.join(d[3:])
try:
size = int(int(d[2].replace(',', ''))*0.001)
if sort == 'size':
file_data.append([filename, f'{d[0]} {d[1]}', self.get_file_type(filename), size])
else:
file_data.append([filename, f'{d[0]} {d[1]}', self.get_file_type(filename), f'{size:,} KB'])
except:
size = 'N/A'

if sort == 'size' or size == 'N/A':
file_data.append([filename, f'{d[0]} {d[1]}', self.get_file_type(filename), size])
else:
file_data.append([filename, f'{d[0]} {d[1]}', self.get_file_type(filename), f'{size:,} KB'])

if mode == None:
if self.current_directory != directory:
self.previous_directories.append(self.current_directory)
self.forward_directories.clear()
elif mode == 'back': # when user clicks back arrow button
self.previous_directories.pop()
self.forward_directories.appendleft(self.current_directory)
elif mode == 'fwd':
self.forward_directories.popleft()
if mode == None:
if self.current_directory != directory:
self.previous_directories.append(self.current_directory)
self.forward_directories.clear()
elif mode == 'back': # when user clicks back arrow button
self.previous_directories.pop()
self.forward_directories.appendleft(self.current_directory)
elif mode == 'fwd':
self.forward_directories.popleft()
self.previous_directories.append(self.current_directory)

# Sorting
if sort == 'date':
directory_data = list(reversed(sorted(directory_data, key=lambda x: x[1])))
file_data = list(reversed(sorted(file_data, key=lambda x: x[1])))
elif sort == 'file_type':
directory_data = list(reversed(sorted(directory_data, key=lambda x: x[2])))
file_data = list(reversed(sorted(file_data, key=lambda x: x[2])))
elif sort == 'size':
directory_data = list(reversed(sorted(directory_data, key=lambda x: x[3])))
file_data = list(reversed(sorted(file_data, key=lambda x: x[3])))
for f in file_data:
f[-1] = f'{int(f[-1]):,} KB'
self.current_directory = directory
else:
directory_data = 'Location Does Not Exist'
# Sorting
if sort == 'date':
directory_data = list(reversed(sorted(directory_data, key=lambda x: x[1])))
file_data = list(reversed(sorted(file_data, key=lambda x: x[1])))
elif sort == 'file_type':
directory_data = list(reversed(sorted(directory_data, key=lambda x: x[2])))
file_data = list(reversed(sorted(file_data, key=lambda x: x[2])))
elif sort == 'size':
directory_data = list(reversed(sorted(directory_data, key=lambda x: x[3])))
file_data = list(reversed(sorted(file_data, key=lambda x: x[3])))
for f in file_data:
f[-1] = f'{int(f[-1]):,} KB'

self.current_directory = directory
#else:
# directory_data = 'Location Does Not Exist'

self.directory_data = directory_data
self.file_data = file_data

return directory_data + file_data

def get_file_type(self, filename):
Expand Down

0 comments on commit d69591e

Please sign in to comment.