diff --git a/twander.py b/twander.py index 56f9acf..b52d844 100755 --- a/twander.py +++ b/twander.py @@ -4,7 +4,7 @@ PROGNAME = "twander" -RCSID = "$Id: twander.py,v 1.35 2002/11/09 06:20:15 tundra Exp $" +RCSID = "$Id: twander.py,v 1.36 2002/11/09 19:54:29 tundra Exp $" VERSION = RCSID.split()[2] @@ -25,12 +25,6 @@ # Defaults ##### -# Booleans - -FALSE = 0 == 1 # Booleans -TRUE = not FALSE - - # Configuration file CONF = os.path.join(os.getenv("HOME"), # Name of default config file @@ -78,6 +72,12 @@ ##### +# Booleans +##### + +# Don't need to define TRUE & FALSE - they are defined in the Tkinter module + +##### # Constants ##### @@ -86,8 +86,8 @@ # General Literals ##### -DIR_LDELIM = '[' # Directory left dsply. delimiter -DIR_RDELIM = ']' # Directory left dsply. delimiter +DIR_LDELIM = '<' # Directory left dsply. delimiter +DIR_RDELIM = '>' # Directory left dsply. delimiter PSEP = os.sep # Character separating path components @@ -218,6 +218,9 @@ # Update the window title UIroot.title(PROGNAME + " " + VERSION + " " + ROOTDIR) + # Clear out the old contents + UI.DirList.delete(0,END) + # Load new directory contents into UI for x in BuildDirList(ROOTDIR): UI.DirList.insert(END, x) @@ -332,6 +335,7 @@ def __init__(self, root): + # Setup the visual elements self.hSB = Scrollbar(root, orient=HORIZONTAL) self.vSB = Scrollbar(root, orient=VERTICAL) self.DirList = Listbox(root, @@ -352,6 +356,26 @@ self.vSB.pack(side=RIGHT, fill=Y) self.DirList.pack(side=LEFT, fill=BOTH, expand=1) + # Start polling the listbox for changes + # This is because Tk is braindamaged and + # cannot automatically track selection changes. + # So, we keep track of the index last selected + # constantly comparing it with the new one + # to watch for a change. Yuk! + + self.lastsel = None + self.poll() + + def poll(self): + cursel = self.DirList.curselection() + if cursel != self.lastsel: + self.lastsel = cursel + DirListHandler(cursel) + + # Go back to sleep for a while + self.DirList.after(150, self.poll) + + # End of class definition, 'twanderUI' @@ -359,11 +383,16 @@ # Event Handler For Directory Listing ListBox ##### -def DirList_Handler(**kwargs): +def DirListHandler(index): global ROOTDIR - selected = DirList.items[DirList._get_selection()] + # Ignore cases with no selection + if not index: + return + # Otherwise, get the actual string selected + selected = UI.DirList.get(int(index[0])) + # If selection is a directory, move there and list contents. # We examine this by checking the string for the directory # delimiter characters previously inserted in BuildDirList() @@ -393,12 +422,13 @@ ROOTDIR = selected LoadDirList() - else: # It's a file - handled by the single-click handler - pass + else: + print selected + " Not a dir" -# End of 'DirList_Handler()' +# End of 'DirListHandler()' + #----------------------------------------------------------# # Program Entry Point # #----------------------------------------------------------# @@ -465,6 +495,8 @@ ErrMsg(eNOCONF % CONF) sys.exit(1) +# Parse contents into dictionary + rcfile = {} ParseRC()