mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
cleanup and fixes
fixed event prefix ID handling fixed removing of nodes of disconnected devices removed debug prints added more comments
This commit is contained in:
parent
271997b462
commit
29896a39a4
@ -1713,17 +1713,20 @@ class ShowBase(DirectObject.DirectObject):
|
|||||||
elif device.getDeviceClass() == InputDevice.DC_keyboard:
|
elif device.getDeviceClass() == InputDevice.DC_keyboard:
|
||||||
prefix = "keyboard"
|
prefix = "keyboard"
|
||||||
|
|
||||||
|
currentPrefixes = []
|
||||||
|
for np in self.dataRoot.findAllMatches("**/{}".format(prefix)):
|
||||||
|
bt = np.node()
|
||||||
|
currentPrefixes.append(bt.getPrefix())
|
||||||
|
|
||||||
id = 0
|
id = 0
|
||||||
for dev in self.devices.devices:
|
# Find the next free ID for the newly connected device
|
||||||
if dev == device:
|
while "{}{}-".format(prefix, id) in currentPrefixes:
|
||||||
break
|
id+=1
|
||||||
elif dev.getDeviceClass() == device.getDeviceClass():
|
# Setup the button thrower for that device and register it's event prefix
|
||||||
id += 1
|
|
||||||
print ""
|
|
||||||
print "MAPPED", device, "AS", prefix, "SET CLASS", device.getDeviceClass()
|
|
||||||
print ""
|
|
||||||
bt = idn.attachNewNode(ButtonThrower(prefix))
|
bt = idn.attachNewNode(ButtonThrower(prefix))
|
||||||
|
self.notify.debug("Registred event prefix {}{}-".format(prefix, id))
|
||||||
bt.node().setPrefix("{}{}-".format(prefix, id))
|
bt.node().setPrefix("{}{}-".format(prefix, id))
|
||||||
|
# append the new button thrower to the list of device button throwers
|
||||||
self.deviceButtonThrowers.append(bt)
|
self.deviceButtonThrowers.append(bt)
|
||||||
|
|
||||||
def disconnectDevice(self, device):
|
def disconnectDevice(self, device):
|
||||||
@ -1732,13 +1735,13 @@ class ShowBase(DirectObject.DirectObject):
|
|||||||
connected. It is then used to clean up the given device from the
|
connected. It is then used to clean up the given device from the
|
||||||
data graph.
|
data graph.
|
||||||
"""
|
"""
|
||||||
print device.getName()
|
self.notify.debug("Disconnect device {}".format(device.getName()))
|
||||||
idn = self.dataRoot.find("**/{}".format(device.getName))
|
idn = self.dataRoot.find("**/{}".format(device.getName()))
|
||||||
for bt in self.deviceButtonThrowers.list():
|
for bt in list(self.deviceButtonThrowers):
|
||||||
if bt.getName() == idn.getName():
|
if bt.getName() == idn.getName():
|
||||||
self.deviceButtonThrowers.remove(bt)
|
self.deviceButtonThrowers.remove(bt)
|
||||||
break
|
break
|
||||||
self.dataRoot.removeNode(idn)
|
idn.removeNode()
|
||||||
|
|
||||||
def addAngularIntegrator(self):
|
def addAngularIntegrator(self):
|
||||||
if not self.physicsMgrAngular:
|
if not self.physicsMgrAngular:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user