HList anomalies
David DeGeorge
dld at degeorge.org
Sun Jan 27 14:39:22 EST 2002
I am trying to use the HList widget and I'm starting with the example in
Demo/samples directory called Tree.py. Out of the can the example doesn't
work as one (I) might expect in that when I close a directory and then
reopen it I get Tcl error because the entries already exist. So I thought I
would test for existence and add the entry only if it doesn't exist. The
obvious code fails to work. The code sample is below --- it is short
because I figure this must a common problem. If I put in prints the wooby
variables are 0 but the if clause is not satisfied. Whassup?
def opendir(tree, dir):
entries = tree.hlist.info_children(dir)
if entries:
# We have already loaded this directory. Let's just
# show all the child entries
#
# Note: since we load the directory only once, it will not be
# refreshed if the you add or remove files from this
# directory.
#
for entry in entries:
tree.hlist.show_entry(entry)
files = os.listdir(dir)
for file in files:
gooby = dir + '/' + file
if os.path.isdir(gooby):
wooby = tree.hlist.info_exists(gooby)
if(not wooby):
adddir(tree, gooby)
else:
wooby = tree.hlist.info_exists(gooby)
if (not wooby) :
tree.hlist.add(gooby, itemtype=Tix.IMAGETEXT, text=file,
image=tree.tk.call('tix', 'getimage',
'file'))
David
More information about the Python-list
mailing list