From e5980c6a5af9a66e5b7be0ae4c66b03ae3c193db Mon Sep 17 00:00:00 2001 From: Stiliyan Tonev Date: Mon, 2 Jan 2023 11:20:39 +0200 Subject: [PATCH] refactor: Got motivation during holidays. Got some motivation during holidays, and will try to freshen up a little bit my side projects once again. This is mostly refactoring wrong formatting, missing spaces and so on. * Starting to migrate to `logging` * Using `os.sep` insetead of `\\` * Add basic `requirements.txt` will revise soon again. --- .gitignore | 1 + declaration.py | 36 +++-- files/handlers/system_handler.py | 4 +- files/real/filesystem/files_manager.py | 10 +- files/virtual/custom/files_manager.py | 22 +-- files/virtual/onetab.py | 23 +-- index/csv/index_manager.py | 49 +++--- main.py | 199 +++++++++++++------------ requirements.txt | 3 + view_widgets/tree_manager.py | 31 ++-- 10 files changed, 194 insertions(+), 184 deletions(-) create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index a46ff4e..6c34c13 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.txt +!requirements.txt *.js __pycache__ _* diff --git a/declaration.py b/declaration.py index 5d84ece..cd4aed6 100644 --- a/declaration.py +++ b/declaration.py @@ -1,6 +1,7 @@ import re from functools import wraps from core import Factory,ConfigAdvanced +import logging class VNode: def __init__(self): @@ -10,7 +11,7 @@ def __init__(self): self.other={} def build(self,data:object): - dtype=type(data) + dtype = type(data) if dtype is list: return self.__buildList(data) elif dtype is str: @@ -18,36 +19,33 @@ def build(self,data:object): return None def __buildList(self,data:list): - self.value=data[1] - self.path=data[0] - self.name=re.split(r' |/|\\',self.path)[-1:] - self.name=self.name[0] - - self.other=data[2:] - + self.value = data[1] + self.path = data[0] + self.name = re.split(r' |/|\\',self.path)[-1:] + self.name = self.name[0] + self.other = data[2:] return self def __buildString(self,data:str): - self.value=data.split(';')[1] - self.path=data.split(';')[0] - self.name=re.split(r' |/|\\',self.path)[-1:] - self.name=self.name[0] + self.value = data.split(';')[1] + self.path = data.split(';')[0] + self.name = re.split(r' |/|\\',self.path)[-1:] + self.name = self.name[0] return self cache=[ - {'name':'TagManager','method':'load_tags','store':None}, - {'name':'IndexManager','method':'load_files','store':None}, - {'name':'TagManager','method':'load_tags','store':None} + {'name': 'TagManager','method':'load_tags','store': None}, + {'name': 'IndexManager','method':'load_files','store': None}, + {'name': 'TagManager','method':'load_tags','store': None} ] def invalidate(func): @wraps(func) def execute_and_invalidate(*args, **kwargs): func(*args, **kwargs) - print(func.__name__+" has triggered validation !") - print('\n') + logging.info(func.__name__ + " has triggered validation !") return execute_and_invalidate -factory=Factory() -config=ConfigAdvanced() \ No newline at end of file +factory = Factory() +config = ConfigAdvanced() \ No newline at end of file diff --git a/files/handlers/system_handler.py b/files/handlers/system_handler.py index 42577d3..c048218 100644 --- a/files/handlers/system_handler.py +++ b/files/handlers/system_handler.py @@ -6,11 +6,11 @@ class FileHandler(FileHandler): This class is meant to function as an abstraction for actions upon files. This current version allows the execution of a command in the system shell with the file passed as argument. """ - def __init__(self,command="start",arguments=""): + def __init__(self, command="start", arguments=""): self.shell_command=command self.shell_arguments=arguments - def handle(self,path:str): + def handle(self, path:str): """ Upon a given 'path' to a file, either apply logic for different types of files or directly execute operation. """ diff --git a/files/real/filesystem/files_manager.py b/files/real/filesystem/files_manager.py index 76e9573..a15bcb8 100644 --- a/files/real/filesystem/files_manager.py +++ b/files/real/filesystem/files_manager.py @@ -8,7 +8,7 @@ class FileManager(FileManager): def __init__(self): pass - def get_children(self,path:str): + def get_children(self, path:str): """ In case the given 'path' is traversible Returns the 'children' of the given 'path'. @@ -17,15 +17,15 @@ def get_children(self,path:str): return os.listdir(path) return [] - def get_parent(self,path:str): + def get_parent(self, path:str): """ Returns one level lower path. get_parent('/1/2/3/4/5') will return '\\1\\2\\3\\4' """ - pathArray=re.split(r' |/|\\',path)[:-1] - return '\\'.join(pathArray) + pathArray=re.split(r' |/|\\', path)[:-1] + return os.sep.join(pathArray) - def is_traversable(self,path:str): + def is_traversable(self, path:str): """ Returns if the path is traversible. """ diff --git a/files/virtual/custom/files_manager.py b/files/virtual/custom/files_manager.py index 8baad06..70f962b 100644 --- a/files/virtual/custom/files_manager.py +++ b/files/virtual/custom/files_manager.py @@ -4,14 +4,14 @@ class VirtualManager(VirtualManager): def __init__(self): - self.index_manager=factory.getInstanceByName(config.indexManager) - self.tag_manager=factory.getInstanceByName(config.tagsManager) + self.index_manager = factory.getInstanceByName(config.indexManager) + self.tag_manager = factory.getInstanceByName(config.tagsManager) def get_root_items(self): - result=[] + result = [] for i in self.index_manager.get_indexed_files(): - vnode=i - root=re.split(r' |/|\\',vnode.path)[0] + vnode = i + root = re.split(r' |/|\\',vnode.path)[0] if root not in result: result.append(root) @@ -24,16 +24,16 @@ def get_root_items(self): def get_all_items(self): return self.index_manager.get_indexed_files() - def get_item(self,path:str): + def get_item(self, path:str): return [i for i in self.index_manager.get_indexed_files() if i.path==path] - def get_children(self,path:str): + def get_children(self, path:str): return [r for r in self.index_manager.get_indexed_files() if r.path!=path and r.path.startswith(path)] - def get_parent(self,path:str): - files=self.index_manager.get_indexed_files() - files=[i for i in files if path.startswith(i.path)] + def get_parent(self, path:str): + files = self.index_manager.get_indexed_files() + files = [i for i in files if path.startswith(i.path)] return files - def is_traversable(self,path:str): + def is_traversable(self, path:str): return len([i for i in self.index_manager.get_indexed_files() if i.path.startswith(path) and i.path!=path])>0 \ No newline at end of file diff --git a/files/virtual/onetab.py b/files/virtual/onetab.py index ae4b3f4..a3891ad 100644 --- a/files/virtual/onetab.py +++ b/files/virtual/onetab.py @@ -1,13 +1,14 @@ import re +import os from declaration import config,factory,VNode class VirtualManager: def __init__(self): - self.index_manager=factory.getInstanceByName(config.indexManager) - self.tag_manager=factory.getInstanceByName(config.tagsManager) + self.index_manager = factory.getInstanceByName(config.indexManager) + self.tag_manager = factory.getInstanceByName(config.tagsManager) def get_root_items(self): - result=[] + result= [] for i in self.index_manager.get_indexed_files(): vnode=VNode().build(i) root=re.split(r' |/|\\',vnode.path)[0] @@ -28,23 +29,23 @@ def get_item(self,path): return [VNode().build(i) for i in self.index_manager.get_indexed_files() if i.count(path)>0] def get_children(self,path): - result=[VNode().build(i) for i in self.index_manager.get_indexed_files() if i.count(path)>0] + result = [VNode().build(i) for i in self.index_manager.get_indexed_files() if i.count(path)>0] return [r for r in result if result.path!=path and result.path.count(path)>0] def get_parent(self,path): - i=-1 - parts=re.split(r' |/|\\',path) - shorterPath='\\'.join(parts[:i]) - files=self.index_manager.get_indexed_files() + i = -1 + parts = re.split(r' |/|\\',path) + shorterPath = '\\'.join(parts[:i]) + files = self.index_manager.get_indexed_files() while i>-len(parts): for e in files: if e.count(shorterPath)>0 and e.cont(path)==0: return VNode().build(e) - i=i-1 - shorterPath='\\'.join(parts[:i]) + i = i-1 + shorterPath = os.sep.join(parts[:i]) return None - def is_traversable(self,path): + def is_traversable(self, path:str): return len([i for i in self.index_manager.get_indexed_files() if i.count(path)>0 and len(i)>len(path)])>0 \ No newline at end of file diff --git a/index/csv/index_manager.py b/index/csv/index_manager.py index 596813d..d76f588 100644 --- a/index/csv/index_manager.py +++ b/index/csv/index_manager.py @@ -5,29 +5,27 @@ class IndexManager(IndexManager): def __init__(self): - self.index_item_file=config.indexFile - self.indexed_items=[] - - self.delimiter=';' - self.new_line='' + self.index_item_file = config.indexFile + self.indexed_items = [] + self.delimiter = ';' + self.new_line = '' def get_indexed_files(self): """ Returns all currently tagged files. """ - self.indexed_items=[] - path=self.index_item_file + self.indexed_items = [] + path = self.index_item_file - with open(path,newline=self.new_line) as csvfile: - reader=csv.reader(csvfile,delimiter=self.delimiter) + with open(path, newline=self.new_line) as csvfile: + reader = csv.reader(csvfile, delimiter=self.delimiter) for row in reader: - if len(row)>=2: + if len(row) >= 2: self.indexed_items.append(VNode().build(row)) - return self.indexed_items @invalidate - def tag_item(self,tag_number:int,item_path:str): + def tag_item(self, tag_number:int, item_path:str): """ Tag a file identified by 'item_path' with the 'tag_number' that represents the collection of tags. """ @@ -40,47 +38,46 @@ def tag_item(self,tag_number:int,item_path:str): writer.writerow([item_path,tag_number,self.get_type(item_path)]) @invalidate - def edit_tag(self,tag_number:int,item_path:str): + def edit_tag(self, tag_number:int, item_path:str): """ Change tag number of a given item. """ - files_indexes=self.indexed_items + files_indexes = self.indexed_items with open(self.index_item_file, 'w', newline=self.new_line) as f: - writer = csv.writer(f,delimiter=self.delimiter) + writer = csv.writer(f, delimiter=self.delimiter) for index in files_indexes: - if index[0]==item_path: - writer.writerow([item_path,tag_number,self.get_type(item_path)]) + if index[0] == item_path: + writer.writerow([item_path,tag_number, self.get_type(item_path)]) else: writer.writerow(index) - def get_items_with_all_tags(self,number:int): + def get_items_with_all_tags(self, number:int): """ Returns a list of the items containing ALL tags defined by 'number' """ return [i[0] for i in self.indexed_items if i[1].endswith(str(number))] - def get_items_with_any_tag(self,numbers:list): + def get_items_with_any_tag(self, numbers:list): """ Returns a list of items tagged with ANY of the tags in 'numbers' """ - result=[] + result = [] for item in self.indexed_items: - number=int(item[1]) + number = int(item[1]) for index in numbers: - if number%index==0: + if number%index == 0: result.append(item) break - return result - def is_tagged(self,item:str): + def is_tagged(self, item:str): """ Returns 'true' in case the 'item' has been tagged with any tag. """ return len([i for i in self.indexed_items if i.path==item])>0 - def reindex_files(self,removed_tag_number:int): + def reindex_files(self, removed_tag_number:int): """ Reindex in case a tag has been deleted. """ @@ -92,7 +89,7 @@ def reindex_files(self,removed_tag_number:int): else: writer.writerow([index.path,index.value,self.get_type(index.path)]) - def get_type(self,path:str): + def get_type(self, path:str): if path.startswith("http"): return "http" else: diff --git a/main.py b/main.py index 7318acf..82ae10c 100644 --- a/main.py +++ b/main.py @@ -2,51 +2,57 @@ import tkinter.ttk as ttk from tkinter import filedialog as fd from tkinter.messagebox import showinfo -import uuid,os, sys,subprocess -import re from view_widgets import TreeManager,BrowserManager,CheckBoxContainer - from declaration import config, factory from cache import CacheManager +import uuid +import os +import sys +import subprocess +import re +import logging + class Application(tk.Frame): def __init__(self, master=None): super().__init__(master) self.master = master - self.factory=factory - self.cacheManager=factory.create('cache','CacheManager') - self.indexManager=factory.create(*config.index) - self.tagManager=factory.create(*config.tags) - self.fileManager=factory.create(*config.realFiles) - self.virtualManager=factory.create(*config.virtualFiles) - self.fileHandler=factory.create(*config.fileHandler) - - self.notebook=ttk.Notebook(master) - self.checkBoxes=[] - self.path='/' - - self.frame=tk.Frame(master) + logging.debug('Application Init') + self.factory = factory + self.cacheManager = factory.create('cache','CacheManager') + self.indexManager = factory.create(*config.index) + self.tagManager = factory.create(*config.tags) + self.fileManager = factory.create(*config.realFiles) + self.virtualManager = factory.create(*config.virtualFiles) + self.fileHandler = factory.create(*config.fileHandler) + logging.debug('Loaded factory objects from config.') + + self.notebook = ttk.Notebook(master) + self.notebook.pack(expand=1) + self.checkBoxes = [] + self.path = '/' + + self.frame = tk.Frame(master) self.frame.pack(fill=tk.BOTH, expand=True) - self.frameTwo=tk.Frame(master) - self.frameTwo.pack(fill=tk.BOTH, expand=True) + self.indexedFrame = tk.Frame(master) + self.indexedFrame.pack(fill=tk.BOTH, expand=True) - self.frameThree=tk.Frame(master) + self.frameThree = tk.Frame(master) self.frameThree.pack(fill=tk.BOTH, expand=True) - self.tagManagementFrame=tk.Frame(master) + self.tagManagementFrame = tk.Frame(master) self.tagManagementFrame.pack(fill=tk.BOTH, expand=True) - self.checkboxFrame=CheckBoxContainer(self.frame,self.tagManager.get_tags())#tk.Frame(self.frame) - self.checkboxFrame.grid(rowspan=4,column=2,columnspan=6,row=2) + self.checkboxFrame = CheckBoxContainer(self.frame, self.tagManager.get_tags())#tk.Frame(self.frame) + self.checkboxFrame.grid(rowspan=4, column=2, columnspan=6, row=2) #self.addCheckboxes() - abspath = os.path.abspath(self.path) - self.tree = TreeManager(self,self.frame,abspath,"filesystem",self.process_directory) + self.tree = TreeManager(self, self.frame, os.path.abspath(self.path), "filesystem", self.process_directory) - self.browserIndexed = BrowserManager(self,self.frameTwo,['filesystem',"http"],"Indexed Files",self.browser_directory_process) + self.browserIndexed = BrowserManager(self,self.indexedFrame, ['filesystem',"http"], "Indexed Files", self.browser_directory_process) self.browserIndexed.bind("", self.indexedDoubleClick) self.tagName=tk.Entry(self.tagManagementFrame) @@ -58,37 +64,38 @@ def __init__(self, master=None): self.tagList.pack() self.headerAndFooter() - self.loadTabs([{'frame':self.frame,'text':'File Tagger'},{'frame':self.frameTwo,'text':'Indexed Files'},{'frame':self.tagManagementFrame,'text':'Manage Tags'}]) + self.loadTabs([{'frame':self.frame,'text':'File Tagger'},{'frame':self.indexedFrame,'text':'Indexed Files'},{'frame':self.tagManagementFrame,'text':'Manage Tags'}]) self.tree.drawTree() self.browserIndexed.drawTree() + logging.debug("Finished UI Loading") - def loadTabs(self,tabs_data:dict): + def loadTabs(self, tabs_data:dict): for tab in tabs_data: self.notebook.add(tab['frame'],text=tab['text']) - self.notebook.pack() + self.notebook.pack(expand=True) def headerAndFooter(self): - self.header=tk.Frame(self.master) + self.header = tk.Frame(self.master) self.header.pack(side="top") - self.buttonFrame=tk.Frame(self.master) + self.buttonFrame = tk.Frame(self.master) self.buttonFrame.pack(side="bottom") self.addButtons() - def indexedDoubleClick(self,event): - item=self.browserIndexed.selection()[0] - path=self.browserIndexed.get_path(item,True) + def indexedDoubleClick(self, event): + item = self.browserIndexed.selection()[0] + path = self.browserIndexed.get_path(item,True) + logging.debug("Double clicked on " + item + " pointing towards " + path) self.fileHandler.handle(path) def addListBox(self): - box=tk.Listbox(self.tagManagementFrame) - counter=1 - + box = tk.Listbox(self.tagManagementFrame) + counter = 1 box.insert(0, '(Create New Tag)') for tag in self.tagManager.get_tags(): box.insert(counter, tag) - counter+=1 + counter += 1 return box @@ -96,83 +103,86 @@ def addDropBox(self): pass def addButtons(self): - quit = tk.Button(self.buttonFrame, text="QUIT",command=self.master.destroy) - quit.grid(row=6,column=2) - openfile = tk.Button(self.buttonFrame, text="FILE",command=self.select_file) - openfile.grid(row=6,column=4) - opendir = tk.Button(self.buttonFrame, text="DIRECTORY",command=self.select_directory) - opendir.grid(row=6,column=6) - opendir = tk.Button(self.buttonFrame, text="TAG",command=self.tag_item) - opendir.grid(row=6,column=8) + quit = tk.Button(self.buttonFrame, text="QUIT", command=self.master.destroy) + quit.grid(row=6, column=2) + openfile = tk.Button(self.buttonFrame, text="FILE", command=self.select_file) + openfile.grid(row=6, column=4) + opendir = tk.Button(self.buttonFrame, text="DIRECTORY", command=self.select_directory) + opendir.grid(row=6, column=6) + opendir = tk.Button(self.buttonFrame, text="TAG", command=self.tag_item) + opendir.grid(row=6, column=8) def tag_item(self): - self.indexManager.tag_item(self.tagManager.calc_tags_number([i.get() for i in self.checkboxFrame.getValues()]),self.tree.get_path(self.tree.selection(),False)) + logging.debug("Tagging item : " + self.tree.get_path(self.tree.selection(), False)) + self.indexManager.tag_item(self.tagManager.calc_tags_number([i.get() for i in self.checkboxFrame.getValues()]), self.tree.get_path(self.tree.selection(), False)) def addCheckboxes(self): - index=0 - nrow=0 - ncol=0 - checkbox=None - label=None + index = 0 + nrow = 0 + ncol = 0 + checkbox = None + label = None for i in self.tagManager.get_tags(): if index%3==0: - nrow=0 - ncol=ncol+1 + nrow = 0 + ncol = ncol+1 - value=tk.IntVar() - checkbox=tk.Checkbutton(self.checkboxFrame, variable = value) + value = tk.IntVar() + checkbox = tk.Checkbutton(self.checkboxFrame, variable = value) self.checkBoxes.append(value) - label=tk.Label(self.checkboxFrame,text=str(i)) + label = tk.Label(self.checkboxFrame, text=str(i)) - label.grid(row=nrow,column=ncol) - checkbox.grid(row=nrow,column=ncol+2) + label.grid(row=nrow, column=ncol) + checkbox.grid(row=nrow, column=ncol+2) - nrow+=2 - index+=1 + nrow += 2 + index += 1 def addCombobox(self): pass def select_directory(self): - result=fd.askdirectory() - self.path=result + result = fd.askdirectory() + self.path = result def select_file(self): filetypes = ( - ('text files', '*.txt'), + ('Text files', '*.txt'), ('All files', '*') ) filename = fd.askopenfilename( title='Open a file', initialdir='/', - filetypes=filetypes) + filetypes=filetypes + ) - self.path=filename + self.path = filename def browser_directory_process(self, path:str): - vnodes=self.virtualManager.get_all_items() - formated_file=[] - map=[] + vnodes = self.virtualManager.get_all_items() + formated_file = [] + map = [] + logging.debug("Opening " + path) for file in vnodes: - branch=[i for i in self.browserIndexed.get_children() if self.browserIndexed.item(i)['text']==file.other[0]] + branch = [i for i in self.browserIndexed.get_children() if self.browserIndexed.item(i)['text']==file.other[0]] - currentPath=file.path - value=file.value - formated_file=re.split(r' |/|\\',currentPath) + currentPath = file.path + value = file.value + formated_file = re.split(r' |/|\\', currentPath) for part in formated_file: if not file.path.endswith(part): - value=None + value = None else: - value=int(file.value) - index_arr=self.tagManager.calc_number_tags(value) - text_tags=[self.tagManager.get_tag_value_text(i) for i in index_arr] - value=",".join(text_tags) + value = int(file.value) + index_arr = self.tagManager.calc_number_tags(value) + text_tags = [self.tagManager.get_tag_value_text(i) for i in index_arr] + value = ",".join(text_tags) - same_name=[e for e in map if e[1]==part] + same_name = [e for e in map if e[1]==part] if len([child for child in self.browserIndexed.get_children(branch) if self.browserIndexed.item(child)['text']==part])==0: - branch=self.browserIndexed.insert(branch, 'end', text=part,value=(file.name,value), open=False) + branch = self.browserIndexed.insert(branch, 'end', text=part, value=(file.name,value), open=False) map.append((branch,part)) else: branch=[e[0] for e in map if e[1]==part][0] @@ -186,41 +196,42 @@ def process_directory(self, parent, path): self.tree.insert(oid, 'end', text='', open=False) def open_directory_tree(self,event): - if event.widget.heading('#0')['text']!="filesystem": + if event.widget.heading('#0')['text'] != "filesystem": return - selected_id=self.tree.selection() - selected_item=self.tree.item(selected_id) - children=self.tree.get_children(selected_id) + selected_id = self.tree.selection() + selected_item = self.tree.item(selected_id) + children = self.tree.get_children(selected_id) for i in children: self.tree.delete(i) - self.process_directory(selected_id,self.tree.get_path(selected_id,False)) + self.process_directory(selected_id, self.tree.get_path(selected_id, False)) - def close_directory_tree(self,event): + def close_directory_tree(self, event): if event.widget.heading('#0')['text']=="filesystem": return - selected_id=self.tree.focus() - selected_item=self.tree.item(selected_id) + selected_id = self.tree.focus() + selected_item = self.tree.item(selected_id) for i in self.tree.get_children(selected_id): self.tree.delete(i) - self.tree.insert(selected_id,'end',text='',open=False) + self.tree.insert(selected_id, 'end', text='', open=False) def apply_tag_action(self): - selectedIndex=self.tagList.curselection()[0] + selectedIndex = self.tagList.curselection()[0] if selectedIndex==0 : self.tagManager.add_new_tag(self.tagName.get()) elif self.tagName.get() == "": self.tagManager.remove_existing_tag(selectedIndex-1) else: - self.tagManager.edit_existing_tag(selectedIndex-1,self.tagName.get()) + self.tagManager.edit_existing_tag(selectedIndex-1, self.tagName.get()) if __name__=="__main__": - root=tk.Tk() - app=Application(root) + root = tk.Tk() + app = Application(root) - root.bind('<>',app.open_directory_tree) - root.bind('<>',app.close_directory_tree) + app.master.maxsize(1000,900) + root.bind('<>', app.open_directory_tree) + root.bind('<>', app.close_directory_tree) app.mainloop() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..468eea1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +sympy +unittest +unittest.mock \ No newline at end of file diff --git a/view_widgets/tree_manager.py b/view_widgets/tree_manager.py index b469b9b..9c05b3c 100644 --- a/view_widgets/tree_manager.py +++ b/view_widgets/tree_manager.py @@ -1,25 +1,24 @@ from tkinter import ttk from .abstract import Scroller from declaration import config, factory +import os class TreeManager(ttk.Treeview,Scroller): """ Represents a tree which is used to display the silesystem's files and folders. """ - def __init__(self,application,parentContainer,root,header,populate_tree): + def __init__(self, application, parentContainer, root, header, populate_tree): super().__init__(parentContainer) Scroller.__init__(self,parentContainer) - self.indexer=factory.getInstanceByName(config.indexManager) - self.tagger=factory.getInstanceByName(config.tagsManager) - self.application=application - self.rootText=root - + self.indexer = factory.getInstanceByName(config.indexManager) + self.tagger = factory.getInstanceByName(config.tagsManager) + self.application = application + self.rootText = root self.heading('#0', text=header, anchor='w') - - self.root_text=root + self.root_text = root self.root_node = self.insert('', 'end', text=root, open=True) - self.populate_tree=populate_tree + self.populate_tree = populate_tree self.grid(row=0, column=0,rowspan=10) def clear(self): @@ -34,20 +33,20 @@ def drawTree(self): """ self.clear() self.root_node = self.insert('', 'end', text=self.root_text, open=True) - self.populate_tree(self.root_node,self.rootText) + self.populate_tree(self.root_node, self.rootText) def redrawTree(self): pass def get_path(self,item,remove_root): - current_item=self.item(item) - parent_item=self.parent(item) - result=[current_item["text"]] + current_item = self.item(item) + parent_item = self.parent(item) + result = [current_item["text"]] while parent_item: - result.insert(0,self.item(parent_item)['text']) - parent_item=self.parent(parent_item) + result.insert(0, self.item(parent_item)['text']) + parent_item = self.parent(parent_item) if remove_root: result.remove(result[0]) - return '\\'.join(result) \ No newline at end of file + return os.sep.join(result) \ No newline at end of file