diff --git a/twander.py b/twander.py index 0cf43c3..e4212fc 100755 --- a/twander.py +++ b/twander.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "twander" -RCSID = "$Id: twander.py,v 3.158 2005/01/08 19:48:45 tundra Exp $" +RCSID = "$Id: twander.py,v 3.159 2005/01/09 01:28:03 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -270,6 +270,7 @@ # Defaults ##### +ADAPTREFRESH = TRUE # Dynamically adjust refresh intervals AFTERCLEAR = TRUE # Clear all selections following REFRESHAFTER AFTERWAIT = 1 # Seconds to wait before REFRESHAFTER AUTOREFRESH = TRUE # Automatically refresh the directory display? @@ -307,7 +308,7 @@ GB = MB * KB # 1 GB constant NUMFUNCKEY = 12 # Number of function keys NUMPROGMEM = 12 # Number of program memories -POLLINT = 20 # Interval (ms) the poll routine should run +POLLINT = 250 # Interval (ms) the poll routine should run PSEP = os.sep # Character separating path components REFRESHINDI = "*" # Titlebar character used to indicate refresh underway REFRESHAFTER = '+' # Indicate we want a refresh after a command runs @@ -2091,24 +2092,19 @@ # Do autorefreshing as required if AUTOREFRESH: - self.ElapsedTime += POLLINT - # Is it time for a referesh? - if self.ElapsedTime >= REFRESHINT: + # Is it time for a refresh? + + elapsed = int((time.time() - self.LastRefresh) * 1000) + if elapsed >= REFRESHINT: # Don't autorefresh on drive list views if UI.CurrentDir != SHOWDRIVES: # Don't autorefresh if there is a lock outstanding - # Try back again in 1/4 the usual time - # This avoids a deadly embrace which can happen - # if you spin on this lock, waiting for it to release if not UI.DirListMutex.test(): RefreshDirList() - self.ElapsedTime = 0 - else: - self.ElapsedTime = (REFRESHINT * 3)/4 # Setup next polling event self.DirList.after(POLLINT, self.poll) @@ -3435,7 +3431,16 @@ ##### def BuildDirList(currentdir): - global UI, SORTBYFIELD + global UI, SORTBYFIELD, REFRESHINT + + # Set time of the refresh + begintime = time.time() + + # We'll need the nominal refresh interval later + nominal = UI.OptionsNumeric["REFRESHINT"] + + + # Check to see if SORTBYFIELD makes sense @@ -3603,7 +3608,18 @@ # OSs like Win32 like to use '$' in file names which # sorts before "." - + # Dynamically adjust refresh interval if option enabled + + if ADAPTREFRESH: + + UI.LastRefresh = time.time() + length = int((time.time() - begintime) * 1000) + + if length > nominal: + REFRESHINT = int((length - nominal) * 1.5) + nominal + else: + REFRESHINT = nominal + if SORTREVERSE: return dotdot + fList + dList else: @@ -3731,6 +3747,18 @@ else: dList.append(entry[0]) + # Dynamically adjust refresh interval if option enabled + + if ADAPTREFRESH: + + UI.LastRefresh = time.time() + length = int((time.time() - begintime) * 1000) + + if length > nominal: + REFRESHINT = int((length - nominal) * 1.5) + nominal + else: + REFRESHINT = nominal + # Return the list return dList @@ -4556,7 +4584,8 @@ # Options (and their default values) which can be set in the configuration file -UI.OptionsBoolean = {"AFTERCLEAR":AFTERCLEAR, +UI.OptionsBoolean = {"ADAPTREFRESH":ADAPTREFRESH, + "AFTERCLEAR":AFTERCLEAR, "AUTOREFRESH":AUTOREFRESH, "FORCEUNIXPATH":FORCEUNIXPATH, "NODETAILS":NODETAILS, "NONAVIGATE":NONAVIGATE, @@ -4607,8 +4636,8 @@ # Intialize the "new dir via mouse" flag UI.MouseNewDir = FALSE -# Initialize the polling counter -UI.ElapsedTime = 0 +# Initialize the refresh timers +UI.LastRefresh = 0 # Start in detailed mode UI.SetDetailedView(TRUE)