diff --git a/twander.py b/twander.py index 57572f4..c695db5 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.46 2003/01/05 23:27:25 tundra Exp $" +RCSID = "$Id: twander.py,v 2.47 2003/01/07 21:29:14 tundra Exp $" VERSION = RCSID.split()[2] @@ -41,7 +41,6 @@ except: def GetDrives(): return "" - if OSNAME == 'posix': import grp @@ -60,11 +59,10 @@ # Key Assignments ##### -MOUSEBINDING = 'MOUSE' # All mouse binding names start with this string - # General Program Commands MOUSECTX = '' # Invoke context menu +MOUSEDIR = '' # Invoke directory menu KEYPRESS = '' # Any keypress (for commands) QUITPROG = '' # Quit the program READCONF = '' # Re-read the configuration file @@ -105,7 +103,12 @@ RUNCMD = '' # Run arbitrary user command SELKEY = '' # Select item w/keyboard -SELMOUSE = '' # Select item w/mouse +MOUSESEL = '' # Select item w/mouse + + +# Name The Key/Mouse Assignments Which We Do Not Allow To Be Rebound In The Config File + +NOREBIND = ["MOUSECTX", "MOUSEDIR", "MOUSEBACK", "MOUSEUP", "MOUSESEL"] ##### @@ -302,8 +305,8 @@ wCMDKEY = "Configuration File Entry For: \'%s\' Has No Command Key Defined." wCONFOPEN = "Cannot Open Configuration File:\n%s\n\n%s" wLINKBACK = "%s Points Back To Own Directory" -wMOUSEBIND = "Cannot Rebind A Mouse Button Combination.\nIgnoring Line %s:\n\n%s" wNOCMDS = "Running With No Commands Defined!" +wNOREBIND = "Cannot Rebind This Keyboard Or Mouse Button Combination.\nIgnoring Line %s:\n\n%s" wWARN = "WARNING" @@ -443,6 +446,7 @@ # parsing process. UI.KeyBindings = {"MOUSECTX":MOUSECTX, + "MOUSEDIR":MOUSEDIR, "KEYPRESS":KEYPRESS, "QUITPROG":QUITPROG, "READCONF":READCONF, @@ -470,7 +474,7 @@ "PGLFT":PGLFT, "RUNCMD":RUNCMD, "SELKEY":SELKEY, - "SELMOUSE":SELMOUSE + "MOUSESEL":MOUSESEL } # Initialize the command menu @@ -634,12 +638,12 @@ sys.exit(1) # Distinguish between internal program variables and - # user-defined variables and act accordingly. - # We inhibit the rebinding of mouse button assignments, however. + # user-defined variables and act accordingly. We inhibit + # the rebinding of certain, special assignments, however. if name in UI.KeyBindings.keys(): - if name.startswith(MOUSEBINDING): - WrnMsg(wMOUSEBIND % (num, line)) + if name in NOREBIND: + WrnMsg(wNOREBIND % (num, line)) else: UI.KeyBindings[name] = val else: @@ -872,7 +876,10 @@ # General Program Commands # Bind handler to invoke context menu - self.DirList.bind(self.KeyBindings["MOUSECTX"], ContextMenu) + self.DirList.bind(self.KeyBindings["MOUSECTX"], MouseClick) + + # Bind handler to invoke directory menu + self.DirList.bind(self.KeyBindings["MOUSEDIR"], MouseClick) # Bind handler for individual keystrokes self.DirList.bind(self.KeyBindings["KEYPRESS"], KeystrokeHandler) @@ -914,10 +921,10 @@ self.DirList.bind(self.KeyBindings["DRIVELIST"], KeyDriveList) # Bind handler for "Mouse Back Dir" - self.DirList.bind(self.KeyBindings["MOUSEBACK"], KeyBackDir) + self.DirList.bind(self.KeyBindings["MOUSEBACK"], MouseDblClick) # Bind handler for "Mouse Up Dir" - self.DirList.bind(self.KeyBindings["MOUSEUP"], KeyUpDir) + self.DirList.bind(self.KeyBindings["MOUSEUP"], MouseDblClick) # Selection Keys @@ -967,7 +974,7 @@ self.DirList.bind(self.KeyBindings["SELKEY"], DirListHandler) # Bind handler for "Mouse Select" - self.DirList.bind(self.KeyBindings["SELMOUSE"], DirListHandler) + self.DirList.bind(self.KeyBindings["MOUSESEL"], MouseDblClick) # Give the listbox focus so it gets keystrokes @@ -1098,6 +1105,46 @@ # Handler Functions # #----------------------------------------------------------# +#---------------- Mouse Click Dispatchers -----------------# + +# We intercept all mouse clicks (of interest) here so it +# is easy to uniquely handle the Control, Shift, Alt, +# variations of button presses. We use Tkinter itself +# keep track of single- vs. double-clicks and hand-off +# the event to the corresponding Mouse Click Dispatcher. + +##### +# Event Handler: Single Mouse Clicks +##### + +def MouseClick(event): + + if event.state == Button3Mask: # Button-3 / No Modifier + ContextMenu(event) # Display Context Menu + + elif event.state == (Button3Mask | ShiftMask): # ShiftButton-3 + DirMenu(event) # Display Directory Menu + +# End Of 'MouseClick() + + +##### +# Event Handler: Mouse Double-Clicks +##### + +def MouseDblClick(event): + + if event.state == Button1Mask: # Double-Button-2 / No Modifier + DirListHandler(event) # Execute selected item + + elif event.state == (Button1Mask | ControlMask): # Control-DoubleButton-1 + KeyBackDir(event) # Move back one directory + + elif event.state == (Button3Mask | ControlMask): # Control-DoubleButton-3 + KeyUpDir(event) # Move up one directory + +# End Of 'MouseDblClick() + #--------------- General Program Commands -----------------# @@ -1108,10 +1155,6 @@ 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, # but only if there are commands defined. @@ -1123,6 +1166,22 @@ ##### +# Event Handler: Directory Menu +##### + +def DirMenu(event): + + # Popup a menu of available directories near the current mouse pointer, + # but only if there are previously visited directories. + + if UI.DirBtn.menu.index(END): + x, y = UI.DirList.winfo_pointerxy() + UI.DirBtn.menu.tk_popup(x, y) + +# End of 'DirMenu()' + + +##### # Event Handler: Individual Keystrokes #####