diff --git a/twander.py b/twander.py index 6809fe8..11a5086 100755 --- a/twander.py +++ b/twander.py @@ -4,7 +4,7 @@ PROGNAME = "twander" -RCSID = "$Id: twander.py,v 1.62 2002/11/19 01:23:15 tundra Exp $" +RCSID = "$Id: twander.py,v 1.63 2002/11/19 09:31:43 tundra Exp $" VERSION = RCSID.split()[2] @@ -13,11 +13,9 @@ #----------------------------------------------------------# import getopt -from mutex import mutex import os from socket import getfqdn import sys -from time import sleep from Tkinter import * from tkMessageBox import showerror, showwarning @@ -57,7 +55,7 @@ SELEND = '' # Select bottom item SELTOP = '' # Select top item SELKEY = '' # Select item w/keyboard -SELMOUSE = '' # Select item w/mouse +SELMOUSE = '' # Select item w/mouse ##### @@ -126,9 +124,9 @@ # Constants ##### -HOSTNAME = getfqdn() # Full name of this host +HOSTNAME = getfqdn() # Full name of this host +REFRESHINT = 2000 # Interval (ms) for automatic refresh -POLLINT = 1000 # Interval (ms) for automatic refresh ##### # General Literals @@ -387,7 +385,7 @@ self.DirList.bind(READCONF, ParseConfFile) # Bind handler of "Refresh Screen" - self.DirList.bind(REFRESH, Refresh) + self.DirList.bind(REFRESH, RefreshDirList) # Directory Navigation @@ -422,10 +420,10 @@ self.DirList.bind(SELEND, KeySelEnd) # Bind handler for "Item Select" - self.DirList.bind(SELKEY, KeySelItem) + self.DirList.bind(SELKEY, DirListHandler) # Bind handler for "Mouse Select" - self.DirList.bind(SELMOUSE, KeySelItem) + self.DirList.bind(SELMOUSE, DirListHandler) # Give the listbox focus so it gets keystrokes self.DirList.focus() @@ -440,8 +438,8 @@ def poll(self): - Refresh() - self.DirList.after(POLLINT, self.poll) + RefreshDirList() + self.DirList.after(REFRESHINT, self.poll) # End of method 'twanderUI.poll()' @@ -648,17 +646,6 @@ # End of 'KeySelTop()' -##### -# Event Handler: Item Selection -# Really just a shim to DirList Handler so we -# can serialize on the selection mutex. -##### - -def KeySelItem(event): - UI.SelMutex.lock(DirListHandler, event) - -# End of 'KeySelItem' - ##### # Process Current Selection @@ -722,9 +709,6 @@ # Have to update the window title because selection changed UI.UpdateTitle(UIroot) - # Release the lock - UI.SelMutex.unlock() - # End of 'DirListHandler()' @@ -833,53 +817,42 @@ ##### -# Shim to RefreshDirList to force serialization on selection mutex -##### - -def Refresh(*args): - UI.SelMutex.lock(RefreshDirList, args) - -# End of 'Refresh()' - - -##### # Refresh contents of directory listing to stay in sync with reality ##### def RefreshDirList(*args): - # Save location of active item - active = UI.DirList.index(ACTIVE) + # Save location & content of active item + + active = UI.DirList.index(ACTIVE) + selected = UI.DirList.get(active) + + # Get new directory listing + newlist = BuildDirList(UI.CurrentDir) # Clean out old listbox contents UI.DirList.delete(0,END) # Save the new directory information - UI.DirList.insert(0, *BuildDirList(UI.CurrentDir)) + UI.DirList.insert(0, *newlist) + + # If possible, maintain selection of same *item*. + # If not, maintain same *position* in widget (set above). + + if selected in newlist: + active = newlist.index(selected) # Restore active item - SetSel(active) + SetSelection(active) # End of 'RefreshDirList() ##### -# Set a particular selection, w/bounds checking. -# This is a shim to the SetSel routine so we -# can serialize selection changes on SelMutex. +# Set a particular selection, w/bounds checking ##### def SetSelection(index): - UI.SelMutex.lock(SetSel, index) - -# End of 'SetSelection()' - - -##### -# Routine that actually set the selection -##### - -def SetSel(index): # Clear all current selection(s) UI.DirList.selection_clear(0, END) @@ -910,9 +883,7 @@ UI.UpdateTitle(UIroot) - UI.SelMutex.unlock() - -# End of 'SetSel()' +# End of 'SetSelection()' #----------------------------------------------------------# @@ -1002,9 +973,6 @@ # And current location UI.CurrentDir = "" -# Set up a semaphore for selection control -UI.SelMutex = mutex() - # Initialize the UI directory listing LoadDirList(STARTDIR)