Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG] Add search #26

Merged
merged 8 commits into from
Feb 6, 2019
25 changes: 0 additions & 25 deletions Biscuit/CustomWidgets/EnhancedTreeview.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,6 @@ def enhance(self, *args, **kwargs):
# entry?
self.bind("<<TreeviewSelect>>", self._close_entry, add='+')

"""
could do check boxes using the unicode characters u"\u2610" and
u"\u2611", but will look bad
self.check_columns = kwargs.get("check_columns", [])
if self.check_columns != []:
self.im_checked = PhotoImage(file='assets/checked.png')
self.im_unchecked = PhotoImage(file='assets/unchecked.png')
self.tag_configure("checked", image=self.im_checked)
self.tag_configure("unchecked", image=self.im_unchecked)
self.bind("<Button-1>>", self._toggle_checkbox, add='+')
"""

def all_children(self, item=''):
"""
This is a generator that will yield the ids of all the children
Expand Down Expand Up @@ -196,19 +184,6 @@ def _close_entry(self, event):
except (AttributeError, TclError):
# In this case I dunno, but just pass
pass
"""
def _toggle_checkbox(self, event):
# find out what row and column was clicked on
rowid = self.identify_row(event.y)
column_num = self.identify_column(event.x)
column = self.column(column_num, option='id')
if column_num == '#0':
column = column_num
# we only want to allow editing if the user has specified the column
# should be editable
if column in self.check_columns or column_num in self.check_columns:
pass
"""

@property
def OnRightClick(self):
Expand Down
47 changes: 35 additions & 12 deletions Biscuit/CustomWidgets/FileTreeview.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os.path as path
import os.path as op
import os

from .EnhancedTreeview import EnhancedTreeview
Expand Down Expand Up @@ -45,20 +45,20 @@ def generate(self, parent, directory=""):
# we want to put folders above files (it looks nicer!!)
try:
for file in os.listdir(dir_):
fullpath = path.join(dir_, file)
fullpath = op.normpath(op.join(dir_, file))

# need to check to see whether or not the file/folder already
# exists in the tree:
exists_id = file_list.get(fullpath, None)
if path.isdir(fullpath):
if op.isdir(fullpath):
if exists_id is None:
exists_id = self.ordered_insert(parent,
values=['', fullpath],
text=file,
open=False)
self.generate(exists_id, directory=fullpath)
else:
fname, ext = path.splitext(file)
fname, ext = op.splitext(file)
if exists_id is None:
self.insert(parent, 'end',
values=[ext, fullpath],
Expand Down Expand Up @@ -103,11 +103,11 @@ def refresh(self):
# (ie. BIDSTree, Project, Subject, Session), and if so then
# instantiate the folder as the child object and add it.
for fullpath in added_files:
base, file = path.split(fullpath)
base, file = op.split(fullpath)
parent = self.sid_from_filepath(base)
fname, ext = path.splitext(file)
fname, ext = op.splitext(file)

if path.isdir(fullpath):
if op.isdir(fullpath):
sid = self.ordered_insert(parent,
values=[ext, fullpath],
text=fname,
Expand Down Expand Up @@ -138,7 +138,30 @@ def sid_from_filepath(self, fpath):
Filepath to match

"""
return self.index_cache[fpath]
# Normalise the path just to ensure there are no issues.
fpath = op.normpath(fpath)
try:
return self.index_cache[fpath]
except KeyError:
# In this case the file isn't in the cache, however it may still
# be in the tree. Recurse up the base paths until an object is
# found then follow it back down.
temp_fpath = op.dirname(fpath)
while True:
print(temp_fpath)
if temp_fpath in self.index_cache:
print('found in cache')
sid = self.index_cache[temp_fpath]
for child in self.all_children(item=sid):
print(self.item(child)['values'][1])
if child['values'][1] == fpath:
return child
_temp_fpath = op.dirname(temp_fpath)
# ensure we cannot get stuck in an infinte loop
if _temp_fpath != temp_fpath:
temp_fpath = _temp_fpath
else:
break

def sid_from_text(self, text, _all=False):
""" Return the sid(s) in the treeview with the given text
Expand Down Expand Up @@ -170,12 +193,12 @@ def _find_added_files(self):
for root, dirs, files in os.walk(self.root_path):
# add all the new files
for file in files:
fpath = path.join(root, file)
fpath = op.normpath(op.join(root, file))
if self.index_cache.get(fpath, None) is None:
new_files.append(fpath)
# add all the new folders
for dir_ in dirs:
fpath = path.join(root, dir_)
fpath = op.join(root, dir_)
if self.index_cache.get(fpath, None) is None:
new_files.append(fpath)
return new_files
Expand All @@ -191,11 +214,11 @@ def _find_folder_diff(self):
for root, dirs, files in os.walk(self.root_path):
# add all the new files
for file in files:
fpath = path.join(root, file)
fpath = op.normpath(op.join(root, file))
contained_files.add(fpath)
# add all the new folders
for dir_ in dirs:
fpath = path.join(root, dir_)
fpath = op.join(root, dir_)
contained_files.add(fpath)
prev_files = set(self.index_cache.keys())
removed_files = (prev_files - contained_files) - set([self.root_path])
Expand Down
Loading