Browse Source

Gathered hotkeys to DirectSession for easy remapping

Gyedo Jeon 16 years ago
parent
commit
b9338f9f7f
2 changed files with 97 additions and 25 deletions
  1. 49 23
      direct/src/directtools/DirectCameraControl.py
  2. 48 2
      direct/src/directtools/DirectSession.py

+ 49 - 23
direct/src/directtools/DirectCameraControl.py

@@ -43,30 +43,56 @@ class DirectCameraControl(DirectObject):
             ['DIRECT-mouse3', self.mouseDollyStart],
             ['DIRECT-mouse3Up', self.mouseDollyStop],
             ]
+
+        # [gjeon] moved all of the hotkeys to single place for easy remapping
+##         self.keyEvents = [
+##             ['c', self.centerCamIn, 0.5],
+##             ['f', self.fitOnWidget],                  # Note: This function doesn't work as intended
+##             ['h', self.homeCam],
+##             ['shift-v', self.toggleMarkerVis],          
+##             ['m', self.moveToFit],                      # Note: This function doesn't work as intended; the object dissappears and screen flashes
+##             ['n', self.pickNextCOA],
+##             ['u', self.orbitUprightCam],
+##             ['shift-u', self.uprightCam],
+##             [`1`, self.spawnMoveToView, 1],
+##             [`2`, self.spawnMoveToView, 2],
+##             [`3`, self.spawnMoveToView, 3],
+##             [`4`, self.spawnMoveToView, 4],
+##             [`5`, self.spawnMoveToView, 5],
+##             [`6`, self.spawnMoveToView, 6],
+##             [`7`, self.spawnMoveToView, 7],
+##             [`8`, self.spawnMoveToView, 8],
+##             ['9', self.swingCamAboutWidget, -90.0, t],
+##             ['0', self.swingCamAboutWidget,  90.0, t],
+##             ['`', self.removeManipulateCameraTask],
+##             ['=', self.zoomCam, 0.5, t],
+##             ['+', self.zoomCam, 0.5, t],
+##             ['-', self.zoomCam, -2.0, t],
+##             ['_', self.zoomCam, -2.0, t],
+##             ]
+        
         self.keyEvents = [
-            ['c', self.centerCamIn, 0.5],
-            ['f', self.fitOnWidget],                  # Note: This function doesn't work as intended
-            ['h', self.homeCam],
-            ['shift-v', self.toggleMarkerVis],          
-            ['m', self.moveToFit],                      # Note: This function doesn't work as intended; the object dissappears and screen flashes
-            ['n', self.pickNextCOA],
-            ['u', self.orbitUprightCam],
-            ['shift-u', self.uprightCam],
-            [`1`, self.spawnMoveToView, 1],
-            [`2`, self.spawnMoveToView, 2],
-            [`3`, self.spawnMoveToView, 3],
-            [`4`, self.spawnMoveToView, 4],
-            [`5`, self.spawnMoveToView, 5],
-            [`6`, self.spawnMoveToView, 6],
-            [`7`, self.spawnMoveToView, 7],
-            [`8`, self.spawnMoveToView, 8],
-            ['9', self.swingCamAboutWidget, -90.0, t],
-            ['0', self.swingCamAboutWidget,  90.0, t],
-            ['`', self.removeManipulateCameraTask],
-            ['=', self.zoomCam, 0.5, t],
-            ['+', self.zoomCam, 0.5, t],
-            ['-', self.zoomCam, -2.0, t],
-            ['_', self.zoomCam, -2.0, t],
+            ['DIRECT-centerCamIn', self.centerCamIn, 0.5],
+            ['DIRECT-fitOnWidget', self.fitOnWidget],                  # Note: This function doesn't work as intended
+            ['DIRECT-homeCam', self.homeCam],
+            ['DIRECT-toggleMarkerVis', self.toggleMarkerVis],          
+            ['DIRECT-moveToFit', self.moveToFit],                      # Note: This function doesn't work as intended; the object dissappears and screen flashes
+            ['DIRECT-pickNextCOA', self.pickNextCOA],
+            ['DIRECT-orbitUprightCam', self.orbitUprightCam],
+            ['DIRECT-uprightCam', self.uprightCam],
+            ['DIRECT-spwanMoveToView-1', self.spawnMoveToView, 1],
+            ['DIRECT-spwanMoveToView-2', self.spawnMoveToView, 2],
+            ['DIRECT-spwanMoveToView-3', self.spawnMoveToView, 3],
+            ['DIRECT-spwanMoveToView-4', self.spawnMoveToView, 4],
+            ['DIRECT-spwanMoveToView-5', self.spawnMoveToView, 5],
+            ['DIRECT-spwanMoveToView-6', self.spawnMoveToView, 6],
+            ['DIRECT-spwanMoveToView-7', self.spawnMoveToView, 7],
+            ['DIRECT-spwanMoveToView-8', self.spawnMoveToView, 8],
+            ['DIRECT-swingCamAboutWidget-0', self.swingCamAboutWidget, -90.0, t],
+            ['DIRECT-swingCamAboutWidget-1', self.swingCamAboutWidget,  90.0, t],
+            ['DIRECT-removeManipulateCameraTask', self.removeManipulateCameraTask],
+            ['DIRECT-zoomInCam', self.zoomCam, 0.5, t],
+            ['DIRECT-zoomOutCam', self.zoomCam, -2.0, t],
             ]
         # set this to true to prevent the camera from rolling
         self.lockRoll = False

+ 48 - 2
direct/src/directtools/DirectSession.py

@@ -169,7 +169,19 @@ class DirectSession(DirectObject):
         self.modifierEvents = ['control', 'control-up',
                               'shift', 'shift-up',
                               'alt', 'alt-up',
-                              ]
+                               ]
+
+        keyList = map(chr, range(97, 123))
+        keyList.extend(map(chr, range(48, 58)))
+        keyList.extend(["`", "-", "=", "[", "]", ";", "'", ",", ".", "/", "\\"])
+
+        def addShift(a):
+            return "shift-%s"%a
+
+        self.keyList = keyList[:]
+        self.keyList.extend(map(addShift, keyList))
+        self.keyList.extend(['escape', 'delete', 'page_up', 'page_down'])
+
         self.keyEvents = ['escape', 'delete', 'page_up', 'page_down',
                           '[', '{', ']', '}',
                           'shift-a', 'b', 'control-f',
@@ -189,6 +201,32 @@ class DirectSession(DirectObject):
                             'alt-mouse3', 'alt-mouse3-up',
                             ]
 
+        self.hotKeyEvents = {
+            'c': 'DIRECT-centerCamIn',
+            'f': 'DIRECT-fitOnWidget',
+            'h': 'DIRECT-homeCam',
+            'shift-v': 'DIRECT-toggleMarkerVis',
+            'm': 'DIRECT-moveToFit',
+            'n': 'DIRECT-pickNextCOA',
+            'u': 'DIRECT-orbitUprightCam',
+            'shift-u': 'DIRECT-uprightCam',
+            '1': 'DIRECT-spwanMoveToView-1',
+            '2': 'DIRECT-spwanMoveToView-2',
+            '3': 'DIRECT-spwanMoveToView-3',
+            '4': 'DIRECT-spwanMoveToView-4',
+            '5': 'DIRECT-spwanMoveToView-5',
+            '6': 'DIRECT-spwanMoveToView-6',
+            '7': 'DIRECT-spwanMoveToView-7',
+            '8': 'DIRECT-spwanMoveToView-8',
+            '9': 'DIRECT-swingCamAboutWidget-0',
+            '0': 'DIRECT-swingCamAboutWidget-1',
+            '`': 'DIRECT-removeManipulateCameraTask',
+            '=': 'DIRECT-zoomInCam',
+            '+': 'DIRECT-zoomInCam',
+            '_': 'DIRECT-zoomOutCam',
+            '-': 'DIRECT-zoomOutCam',
+            }
+
         self.passThroughKeys = ['v','b','l','p', 'r', 'shift-r', 's', 't','shift-a', 'w'] 
 
         if base.wantTk:
@@ -366,6 +404,9 @@ class DirectSession(DirectObject):
         for event in self.keyEvents:
             self.accept(event, self.inputHandler, [event])
 
+        for event in self.keyList:
+            self.accept(event, self.inputHandler, [event])
+
     def enableMouseEvents(self):
         for event in self.mouseEvents:
             self.accept(event, self.inputHandler, [event])
@@ -403,7 +444,9 @@ class DirectSession(DirectObject):
                     break
 
         # Deal with keyboard and mouse input
-        if input == 'mouse1-up':
+        if input in self.hotKeyEvents.keys():
+            messenger.send(self.hotKeyEvents[input])
+        elif input == 'mouse1-up':
             self.fMouse1 = 0 # [gjeon] to update alt key information while mouse1 is pressed
             messenger.send('DIRECT-mouse1Up')
         elif input.find('mouse1') != -1:
@@ -1046,6 +1089,7 @@ class DisplayRegionList(DirectObject):
         self.accept("DIRECT-mouse1Up", self.mouseUpdate)
         self.accept("DIRECT-mouse2Up", self.mouseUpdate)
         self.accept("DIRECT-mouse3Up", self.mouseUpdate)
+        self.tryToGetCurrentDr = True
 
     def __getitem__(self, index):
         return self.displayRegionList[index]
@@ -1086,6 +1130,8 @@ class DisplayRegionList(DirectObject):
         #base.direct.dr = self.getCurrentDr()
 
     def getCurrentDr(self):
+        if not self.tryToGetCurrentDr:
+            return base.direct.dr
         for dr in self.displayRegionList:
             if (dr.mouseX >= -1.0 and dr.mouseX <= 1.0 and
                 dr.mouseY >= -1.0 and dr.mouseY <= 1.0):