diff --git a/twander.py b/twander.py index 21b4aae..6809fe8 100755 --- a/twander.py +++ b/twander.py @@ -4,7 +4,7 @@ PROGNAME = "twander" -RCSID = "$Id: twander.py,v 1.61 2002/11/18 08:00:00 tundra Exp $" +RCSID = "$Id: twander.py,v 1.62 2002/11/19 01:23:15 tundra Exp $" VERSION = RCSID.split()[2] @@ -12,12 +12,16 @@ # Imports # #----------------------------------------------------------# -from Tkinter import * -from tkMessageBox import showerror, showinfo, showwarning -from tkSimpleDialog import askstring 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 +from tkSimpleDialog import askstring #----------------------------------------------------------# # Variables User Might Change # @@ -42,7 +46,7 @@ CHANGEDIR = '' # Enter a new path DIRHOME = '' # Goto $HOME -DIRPREV = '' # Goto previous directory +DIRPREV = '' # Goto previous directory DIRSTART = '' # Goto starting directory DIRUP = '' # Go up one directory level @@ -73,12 +77,11 @@ ##### -# Initial Dimensions +# Program Constants ##### -HEIGHT = 25 -WIDTH = 60 - +HEIGHT = 25 +WIDTH = 60 ##### # Colors @@ -123,6 +126,9 @@ # Constants ##### +HOSTNAME = getfqdn() # Full name of this host + +POLLINT = 1000 # Interval (ms) for automatic refresh ##### # General Literals @@ -164,22 +170,19 @@ eOPEN = "Cannot Open File: %s" eTOOMANY = "You Can Only Specify One Starting Directory." -# Informational - -iINFO = "INFORMATION" -iVERINFO = "Program Version Information: %s" - # Prompts pCHPATH = "Change Path" pENPATH = "Enter New Path Desired:" +# Warnings + wCMDKEY = "Configuration File Entry For: \'%s\' Has No Command Key Defined." wWARN = "WARNING" ##### -# Usage Prompts +# Usage Information ##### uTable = [PROGNAME + " " + VERSION + " - Copyright 2002, TundraWare Inc., All Rights Reserved\n", @@ -325,19 +328,7 @@ ustring ="" for x in uTable: - ustring += x + "\n" - - # Build and display in a window - - root = Tk() - root.title(PROGNAME + " " + VERSION) - label = Label(root, - justify=LEFT, - font=(FNAME, FSZ, FWT), - text=ustring) - label.pack() - root.mainloop() - + print x # End of 'Usage()' @@ -396,7 +387,7 @@ self.DirList.bind(READCONF, ParseConfFile) # Bind handler of "Refresh Screen" - self.DirList.bind(REFRESH, RefreshDirList) + self.DirList.bind(REFRESH, Refresh) # Directory Navigation @@ -431,10 +422,10 @@ self.DirList.bind(SELEND, KeySelEnd) # Bind handler for "Item Select" - self.DirList.bind(SELKEY, DirListHandler) + self.DirList.bind(SELKEY, KeySelItem) # Bind handler for "Mouse Select" - self.DirList.bind(SELMOUSE, DirListHandler) + self.DirList.bind(SELMOUSE, KeySelItem) # Give the listbox focus so it gets keystrokes self.DirList.focus() @@ -449,8 +440,8 @@ def poll(self): - RefreshDirList() - self.DirList.after(5000, self.poll) + Refresh() + self.DirList.after(POLLINT, self.poll) # End of method 'twanderUI.poll()' @@ -486,7 +477,9 @@ selected = "" # Update the titlebar - mainwin.title(PROGNAME + " " + VERSION + " " + UI.CurrentDir + selected) + mainwin.title(PROGNAME + " " + VERSION + + " " + HOSTNAME + ": "+ + UI.CurrentDir + selected) # End of method 'twanderUI.UpdateTitle()' @@ -655,9 +648,20 @@ # 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' + ##### -# Event Hander: Process Current Selection +# Process Current Selection ##### def DirListHandler(event): @@ -709,7 +713,7 @@ # won't try to operate on an item selected in a # previous directory - UI.DirList.selection_set(('0',)) + SetSelection(0) # File selected else: @@ -718,6 +722,9 @@ # Have to update the window title because selection changed UI.UpdateTitle(UIroot) + # Release the lock + UI.SelMutex.unlock() + # End of 'DirListHandler()' @@ -826,50 +833,53 @@ ##### +# 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): - # After we fiddle with things we want to - # restore the currently selected item as such. - # Ordinarily, the active entry and the - # selected entry are the same - We force that - # to be so at the end of this routine. - # - # However, in the case of the PgUp and - # PgDn keys, there may be multiple selections - # with yet another distinct active entry. In this - # case, the semantic we want is to choose - # the active item as the one selected. - # So ... we just need to save the active index. - - active=UI.DirList.index(ACTIVE) - selindex=UI.DirList.curselection() + # Save location of active item + active = UI.DirList.index(ACTIVE) - - # Clear out the old contents + # Clean out old listbox contents UI.DirList.delete(0,END) - # Reload current directory contents into UI - for x in BuildDirList(UI.CurrentDir): - UI.DirList.insert(END, x) + # Save the new directory information + UI.DirList.insert(0, *BuildDirList(UI.CurrentDir)) - # Restore current selection and active entry - # Make sure they are still in range singe we - # may have fewer items after the refresh. - # If out of range, just set to last item in list - - SetSelection(active) + # Restore active item + SetSel(active) # End of 'RefreshDirList() ##### -# Set a particular selection - does bounds checking +# Set a particular selection, w/bounds checking. +# This is a shim to the SetSel routine so we +# can serialize selection changes on SelMutex. ##### 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) @@ -900,18 +910,15 @@ UI.UpdateTitle(UIroot) -# End of 'SetSelection()' + UI.SelMutex.unlock() + +# End of 'SetSel()' #----------------------------------------------------------# # Program Entry Point # #----------------------------------------------------------# -# Newline to make sure cursor of invoking window is -# at LHS in case we get errors or warnings. - -print "" - # Command line processing try: @@ -939,7 +946,7 @@ if opt == "-s": FSZ = val if opt == "-v": - InfoMsg(iVERINFO % RCSID) + print RCSID sys.exit(0) if opt == "-w": FWT = val @@ -995,6 +1002,9 @@ # And current location UI.CurrentDir = "" +# Set up a semaphore for selection control +UI.SelMutex = mutex() + # Initialize the UI directory listing LoadDirList(STARTDIR)