Skip to content

Commit

Permalink
'V0.03.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
domhnallmorr committed Oct 16, 2021
1 parent 5a94cad commit c8fa426
Show file tree
Hide file tree
Showing 15 changed files with 371 additions and 33 deletions.
4 changes: 4 additions & 0 deletions plan.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
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

V0.01.0
tidy frames
come up with name
Expand All @@ -9,7 +11,9 @@ V0.01.1
V0.02
quick access
add/delete top level node
edit top level node
add/delete links
edit links
scrollbar
V0.03
scrollbar for tree
Expand Down
Binary file added src/__pycache__/autoscrollbar.cpython-39.pyc
Binary file not shown.
Binary file modified src/__pycache__/branch_tab.cpython-39.pyc
Binary file not shown.
Binary file not shown.
Binary file modified src/__pycache__/explorer_backend.cpython-39.pyc
Binary file not shown.
Binary file modified src/__pycache__/root_tab.cpython-39.pyc
Binary file not shown.
Binary file added src/__pycache__/sidebar_tree.cpython-39.pyc
Binary file not shown.
35 changes: 35 additions & 0 deletions src/autoscrollbar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Python program to illustrate the usage of
# autohiding scrollbars using tkinter

# Importing tkinter
from tkinter import *
from tkinter import ttk

# Creating class AutoScrollbar
class AutoScrollbar(ttk.Scrollbar):

# Defining set method with all
# its parameter
def set(self, low, high):

if float(low) <= 0.0 and float(high) >= 1.0:

# Using grid_remove
self.tk.call("grid", "remove", self)
else:
self.grid()
Scrollbar.set(self, low, high)

# Defining pack method
def pack(self, **kw):

# If pack is used it throws an error
raise (TclError,"pack cannot be used with \
this widget")

# Defining place method
def place(self, **kw):

# If place is used it throws an error
raise (TclError, "place cannot be used with \
this widget")
33 changes: 23 additions & 10 deletions src/branch_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
from tkinter import *
from tkinter import ttk
from tkinter.ttk import *
from tkinter import messagebox


import address_bar
import autoscrollbar
import explorer_backend
import treeview_functions

Expand All @@ -30,10 +33,14 @@ def __init__(self, root_tab, mainapp, id, text, width):
self.address_bar_entry.update_bar()
self.update_treeview()

def update_tab(self):
self.address_bar_entry.update_bar()
self.update_treeview()
self.root_tab.notebook.tab(self, text=os.path.basename(self.explorer.current_directory))
def update_tab(self, directory):
directory_data = self.explorer.list_directory(directory)
if isinstance(directory_data, str):
messagebox.showerror('Error', message=directory_data)
else:
self.address_bar_entry.update_bar()
self.update_treeview()
self.root_tab.notebook.tab(self, text=os.path.basename(self.explorer.current_directory))

def setup_buttons(self):
#Up a level
Expand All @@ -55,16 +62,22 @@ def setup_treeview(self):
self.treeview.bind("<Double-1>", self.OnDoubleClick)
self.treeview.bind("<Button-3>", self.OnRightClick)

#vsb = ttk.Scrollbar(self, orient="vertical", command=self.treeview.yview)
vsb = autoscrollbar.AutoScrollbar(self, orient="vertical", command=self.treeview.yview)
vsb.grid(row=1, column=16, sticky='NSEW')
self.treeview.configure(yscrollcommand=vsb.set)


def update_treeview(self):
directory_data = self.explorer.list_directory()
treeview_functions.write_data_to_treeview(self.mainapp, self.treeview, 'replace', directory_data)

def OnDoubleClick(self, event):
current_selection = treeview_functions.get_current_selection(self.treeview)
if current_selection[1][2] == 'Folder':
directory = current_selection[1][0]
self.explorer.double_clicked_on_directory(directory)
self.update_tab()
directory = os.path.join(self.explorer.current_directory, current_selection[1][0])
#self.explorer.double_clicked_on_directory(directory)
self.update_tab(directory)
else:
self.explorer.double_clicked_on_file(current_selection[1][0])

Expand All @@ -84,12 +97,12 @@ def OnRightClick(self, event):


def up_one_level(self):
self.explorer.up_one_level()
self.update_tab()
directory = self.explorer.up_one_level()
self.update_tab(directory)

def open_in_text_editor(self):
current_selection = treeview_functions.get_current_selection(self.treeview)
if current_selection[1][2] != 'Folder':
subprocess.call([r"C:\Program Files (x86)\Notepad++\notepad++.exe", fr"{self.explorer.current_directory}\\{current_selection[1][0]}"])


33 changes: 33 additions & 0 deletions src/config_file_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import copy
import json
import os

def write_config_file(mainapp):
save_dict = {}

# Get the Quick Access Links
save_dict['links'] = copy.deepcopy(mainapp.quick_access_tree.links)
save_dict['node_iids'] = copy.deepcopy(mainapp.quick_access_tree.node_iids)
save_dict['nodes'] = copy.deepcopy(mainapp.quick_access_tree.nodes)

with open('tk_path_finder_config.json', 'w') as outfile:
json.dump(save_dict, outfile, indent=4)

def load_config_file(mainapp):
if not os.path.isfile('tk_path_finder_config.json'):
generate_default_config_file()

with open('tk_path_finder_config.json') as f:
data = json.load(f)
return data

def generate_default_config_file():

save_dict = {}
save_dict['links'] = {"I001": {}}
save_dict["node_iids"] = {"I001": 'Default'}
save_dict["nodes"] = {"Default": 'I001'}

with open('tk_path_finder_config.json', 'w') as outfile:
json.dump(save_dict, outfile, indent=4)

44 changes: 26 additions & 18 deletions src/explorer_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,37 @@ def __init__(self, mainapp):
def get_default_directory(self):
return os.getcwd()

def list_directory(self):
# Handle Directories
directory_data = []
files_dirs = os.listdir(self.current_directory)
directories = [o for o in files_dirs if os.path.isdir(os.path.join(self.current_directory,o))]
for d in directories:
directory_data.append([d, '-', 'Folder', ''])
def list_directory(self, directory=None):
file_data = ''

if directory == None:
directory = self.current_directory
try:
# Handle Directories
directory_data = []
files_dirs = os.listdir(directory)
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(self.current_directory,o))]
for f in files:
file_data.append([f, '-', 'File', ''])
# 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:
file_data.append([f, '-', 'File', ''])

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

return directory_data + file_data

def get_file_type(self, filename):
filename, file_extension = os.path.splitext(filename)
print(file_extension)
file_type = 'file'

return file_type
Expand All @@ -41,19 +53,15 @@ def double_clicked_on_directory(self, directory):

def double_clicked_on_file(self, file):
os.startfile(os.path.join(self.current_directory, file))
print(os.path.join(self.current_directory, file))
#subprocess.run(['open', os.path.join(self.current_directory, file)], check=True)


def address_bar_updateed(self, directory):
print('bar updated')
print(directory)
if os.path.isdir(directory):
self.current_directory = directory
print('dsd')

def up_one_level(self):
self.current_directory = os.path.dirname(self.current_directory)
return os.path.dirname(self.current_directory)

def update_explorer(self):
pass
27 changes: 22 additions & 5 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
from tkinter import *
from tkinter import ttk
from tkinter.ttk import *
import os

from ttkbootstrap import Style

import about_screen
import autoscrollbar
import config_file_manager
import root_tab
import sidebar_tree
import tkexplorer_icons

class MainApplication(ttk.Frame):
Expand All @@ -26,18 +30,20 @@ def __init__(self, parent, *args, **kwargs):

self.setup_main_frames()
self.setup_notebook()
self.setup_quick_access()
self.setup_tabs()

def setup_variables(self):
self.version = '0.01.0'
self.version = '0.03.0'
self.parent.title(f"Tk Path Finder V{self.version}")
self.config_data = config_file_manager.load_config_file(self)

def setup_menu(self):
menu = tk.Menu(self.master)
self.master.config(menu=menu)

# ________ ABOUT ________
about_menu = tk.Menu(menu, tearoff = 0)
about_menu = tk.Menu(menu, tearoff=0)
menu.add_cascade(label='About',menu=about_menu)
about_menu.add_command(label = 'About Tk Path Finder', command = lambda self=self: about_screen.about(self))

Expand All @@ -46,7 +52,15 @@ def setup_notebook(self):
self.notebook.pack(expand=True, fill=BOTH, side=LEFT)
self.notebook.bind('<Button-3>', root_tab.right_click)
self.notebook.mainapp = self

def setup_quick_access(self):
self.quick_access_tree = sidebar_tree.QuickAccessTreeview(self)
self.quick_access_tree.grid(row=2, column=0, columnspan=8, sticky='NSEW')

vsb = autoscrollbar.AutoScrollbar(self.sidebar_frame, orient="vertical", command=self.quick_access_tree.yview)
vsb.grid(row=2, column=8, sticky='NSEW')
self.quick_access_tree.configure(yscrollcommand=vsb.set)

def setup_tabs(self):
if self.root_tabs == {}:
tab = self.create_root_tab()
Expand Down Expand Up @@ -77,8 +91,8 @@ def setup_main_frames(self):
#self.rootpane.grid(row=1,column=0, columnspan=4,sticky="nsew")

self.sidebar_frame = ttk.Frame()
self.sidebar_frame.grid_rowconfigure(1, weight=1)
self.sidebar_frame.grid_columnconfigure(19, weight=1)
self.sidebar_frame.grid_rowconfigure(2, weight=1)
self.sidebar_frame.grid_columnconfigure(7, weight=1)
self.rootpane.add(self.sidebar_frame)

self.container = tk.Frame(self.rootpane, bg='pink')
Expand All @@ -87,8 +101,11 @@ def setup_main_frames(self):

self.rootpane.add(self.container,)#stretch="always")

ttk.Label(self.sidebar_frame, text='Quick Access').pack()
ttk.Label(self.sidebar_frame, text='Quick Access').grid(row=0, column=0, columnspan=8, sticky='NSEW')
#ttk.Button(self.container, text='Add Root', command=self.create_root_tab).pack()



if __name__ == "__main__":
root = tk.Tk()
root.resizable(width=tk.TRUE, height=tk.TRUE)
Expand Down
2 changes: 2 additions & 0 deletions src/root_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
def right_click(event):
clicked_tab = event.widget.mainapp.notebook.tk.call(event.widget.mainapp.notebook._w, "identify", "tab", event.x, event.y)
#tab_object = event.widget.nametowidget(event.widget.select(clicked_tab))
event.widget.select(clicked_tab)
tab_object = event.widget.nametowidget(event.widget.select())
popup_menu = tk.Menu(event.widget, tearoff=0)
popup_menu.add_command(label="Add Root Tab", command=event.widget.mainapp.create_root_tab)
Expand Down Expand Up @@ -70,3 +71,4 @@ def rename_tab(self):
new_name = simpledialog.askstring(title = "Rename Tab", prompt = "New Name:".ljust(100), initialvalue=self.text)
if new_name != None:
self.mainapp.notebook.tab(self, text=f'{str(new_name).ljust(20)}')
self.text = new_name
Loading

0 comments on commit c8fa426

Please sign in to comment.