diff --git a/twander.py b/twander.py index aeb062a..42c16d7 100755 --- a/twander.py +++ b/twander.py @@ -4,7 +4,7 @@ # For Updates See: http://www.tundraware.com/Software/twander PROGNAME = "twander" -RCSID = "$Id: twander.py,v 2.35 2002/12/24 22:16:59 tundra Exp $" +RCSID = "$Id: twander.py,v 2.36 2002/12/31 01:09:12 tundra Exp $" VERSION = RCSID.split()[2] @@ -52,8 +52,11 @@ # Key Assignments ##### +MOUSEBINDING = 'MOUSE' # All mouse binding names start with this string + # General Program Commands +MOUSECTX = '' # Invoke context menu KEYPRESS = '' # Any keypress (for commands) QUITPROG = '' # Quit the program READCONF = '' # Re-read the configuration file @@ -160,7 +163,7 @@ # Constants ##### -# General constants +# General Constants KB = 1024 # 1 KB constant MB = KB * KB # 1 MB constant @@ -169,8 +172,24 @@ POLLINT = 20 # Interval (ms) the poll routine should run REFRESHINT = 3000 # Interval (ms) for automatic refresh +# Key & Button Event Masks -# Stat-related +ShiftMask = (1<<0) +LockMask = (1<<1) +ControlMask = (1<<2) +Mod1Mask = (1<<3) +Mod2Mask = (1<<4) +Mod3Mask = (1<<5) +Mod4Mask = (1<<6) +Mod5Mask = (1<<7) +Button1Mask = (1<<8) +Button2Mask = (1<<9) +Button3Mask = (1<<10) +Button4Mask = (1<<11) +Button5Mask = (1<<12) + + +# Stat-Related Constants # Permissions @@ -204,9 +223,9 @@ # General Literals ##### -COMMANDMENU = 'Commands' # Title for Command Menu button -DIRMENU = 'Directories' # Title for Directory Menu button -PSEP = os.sep # Character separating path components +COMMANDMENU = 'Commands' # Title for Command Menu button +DIRMENU = 'Directories' # Title for Directory Menu button +PSEP = os.sep # Character separating path components ##### @@ -254,18 +273,18 @@ # Errors -eBADCFGLINE = "Bogus Configuration Entry In Line %s: %s" -eBADENVVBL = "Environment Variable %s In Line %s Not Set: %s" +eBADCFGLINE = "Bogus Configuration Entry In Line %s:\n\n%s" +eBADENVVBL = "Environment Variable %s In Line %s Not Set:\n\n%s" eBADROOT = " %s Is Not A Directory" eDIRRD = "Cannot Open Directory : %s --- Check Permissions." -eDUPKEY = "Found Duplicate Command Key '%s' In Line %s: %s" +eDUPKEY = "Found Duplicate Command Key '%s' In Line %s:\n\n%s" eERROR = "ERROR" eINITDIRBAD = "Cannot Open Starting Directory : %s - Check Permissions - ABORTING!." eOPEN = "Cannot Open File: %s" -eREDEFVAR = "Variable %s Redefined In Line %s: %s" +eREDEFVAR = "Variable %s Redefined In Line %s:\n\n%s" eTOOMANY = "You Can Only Specify One Starting Directory." -eUNDEFVBL = "Undefined Variable %s Referenced In Line %s: %s" -eVBLTOODEEP = "Variable Definition Nested Too Deeply At Line %s: %s" +eUNDEFVBL = "Undefined Variable %s Referenced In Line %s:\n\n%s" +eVBLTOODEEP = "Variable Definition Nested Too Deeply At Line %s:\n\n%s" # Information @@ -283,6 +302,7 @@ wCMDKEY = "Configuration File Entry For: \'%s\' Has No Command Key Defined." wCONFOPEN = "Cannot Open Configuration File:\n%s\n\n%s" +wMOUSEBIND = "Cannot Rebind A Mouse Button Combination.\nIgnoring Line %s:\n\n%s" wNOCMDS = "Running With No Commands Defined!" wSYMBACK = " Symbolic Link %s Points Back To Own Directory" wWARN = "WARNING" @@ -376,7 +396,8 @@ # These may be overriden in the configuration file # parsing process. - UI.KeyBindings = {"KEYPRESS":KEYPRESS, + UI.KeyBindings = {"MOUSECTX":MOUSECTX, + "KEYPRESS":KEYPRESS, "QUITPROG":QUITPROG, "READCONF":READCONF, "REFRESH":REFRESH, @@ -568,10 +589,14 @@ sys.exit(1) # Distinguish between internal program variables and - # user-defined variables and act accordingly + # user-defined variables and act accordingly. + # We inhibit the rebinding of mouse button assignments, however. if name in UI.KeyBindings.keys(): - UI.KeyBindings[name] = val + if name.startswith(MOUSEBINDING): + WrnMsg(wMOUSEBIND % (num, line)) + else: + UI.KeyBindings[name] = val else: UI.SymTable[name] = val @@ -686,7 +711,7 @@ def StripPSEP(s): - if s[-1] == PSEP: + if s and s[-1] == PSEP: return s[:-1] else: return s @@ -784,6 +809,9 @@ # General Program Commands + # Bind handler to invoke context menu + self.DirList.bind(self.KeyBindings["MOUSECTX"], ContextMenu) + # Bind handler for individual keystrokes self.DirList.bind(self.KeyBindings["KEYPRESS"], KeystrokeHandler) @@ -995,6 +1023,22 @@ ##### +# Event Handler: Context Menu +##### + +def ContextMenu(event): + + # Make sure we're not triggering on some Ctrl-Button3 combination + if event.state & ControlMask: + return + + # Popup a menu of available commands near the current mouse pointer + UI.CmdBtn.menu.tk_popup(UI.DirList.winfo_pointerx(), UI.DirList.winfo_pointery()) + +# End of 'ContextMenu()' + + +##### # Event Handler: Individual Keystrokes #####