pyb3.py
def ensurePybulletAPIs(): # {{{0
  "Ensure pybullet has all of the newly-added constants and functions"
  def _ensurePybulletProperty(name, val): # {{{1
    "Ensure pybullet has the given attribute with the given value"
    logger = getLogger()
    if hasattr(pybullet, name):
      v = getattr(pybullet, name)
      if v != val:
        logger.warning("pybullet[{!r}] == {} (not {})".format(name, v, val))
    setattr(pybullet, name, val)
  # 1}}}

  # Ensure pybullet has the added constants
  _ensurePybulletProperty("MOUSE_MOVE_EVENT", 1)
  _ensurePybulletProperty("MOUSE_BUTTON_EVENT", 2)
  _ensurePybulletProperty("MOUSE_PRESS", 3)
  _ensurePybulletProperty("MOUSE_RELEASE", 4)
  _ensurePybulletProperty("MOUSE_BUTTON_NONE", -1)
  _ensurePybulletProperty("MOUSE_BUTTON_LEFT", 0)
  _ensurePybulletProperty("MOUSE_BUTTON_RIGHT", 2)
  _ensurePybulletProperty("MOUSE_LB", pybullet.MOUSE_BUTTON_LEFT)
  _ensurePybulletProperty("MOUSE_WHEEL", 1)
  _ensurePybulletProperty("MOUSE_RB", pybullet.MOUSE_BUTTON_RIGHT)
  _ensurePybulletProperty("B3G_LEFT", pybullet.B3G_LEFT_ARROW)
  _ensurePybulletProperty("B3G_UP", pybullet.B3G_UP_ARROW)
  _ensurePybulletProperty("B3G_RIGHT", pybullet.B3G_RIGHT_ARROW)
  _ensurePybulletProperty("B3G_DOWN", pybullet.B3G_DOWN_ARROW)

  # Add the rest of the keys using the xkeys FFI module, if available
  try:
    import xkeys
    _ensurePybulletProperty("B3G_KP_HOME", xkeys.lib.Key_KP_Home)
    _ensurePybulletProperty("B3G_KP_LEFT", xkeys.lib.Key_KP_Left)
    _ensurePybulletProperty("B3G_KP_UP", xkeys.lib.Key_KP_Up)
    _ensurePybulletProperty("B3G_KP_RIGHT", xkeys.lib.Key_KP_Right)
    _ensurePybulletProperty("B3G_KP_DOWN", xkeys.lib.Key_KP_Down)
    _ensurePybulletProperty("B3G_KP_END", xkeys.lib.Key_KP_End)
    _ensurePybulletProperty("B3G_KP_PGUP", xkeys.lib.Key_KP_Page_Up)
    _ensurePybulletProperty("B3G_KP_PGDN", xkeys.lib.Key_KP_Page_Down)
    _ensurePybulletProperty("B3G_KP_END", xkeys.lib.Key_KP_End)
    _ensurePybulletProperty("B3G_KP_ENTER", xkeys.lib.Key_KP_Enter)
    _ensurePybulletProperty("B3G_KP_INS", xkeys.lib.Key_KP_Insert)
    _ensurePybulletProperty("B3G_KP_DEL", xkeys.lib.Key_KP_Delete)
    _ensurePybulletProperty("B3G_KP_0", pybullet.B3G_KP_0)
    _ensurePybulletProperty("B3G_KP_1", pybullet.B3G_KP_1)
    _ensurePybulletProperty("B3G_KP_2", pybullet.B3G_KP_2)
    _ensurePybulletProperty("B3G_KP_3", pybullet.B3G_KP_3)
    _ensurePybulletProperty("B3G_KP_4", pybullet.B3G_KP_4)
    _ensurePybulletProperty("B3G_KP_5", pybullet.B3G_KP_5)
    _ensurePybulletProperty("B3G_KP_6", pybullet.B3G_KP_6)
    _ensurePybulletProperty("B3G_KP_7", pybullet.B3G_KP_7)
    _ensurePybulletProperty("B3G_KP_8", pybullet.B3G_KP_8)
    _ensurePybulletProperty("B3G_KP_9", pybullet.B3G_KP_9)
  except ImportError as e:
    getLogger().exception(e)
    _ensurePybulletProperty("B3G_KP_HOME", 0xff95)
    _ensurePybulletProperty("B3G_KP_LEFT", 0xff96)
    _ensurePybulletProperty("B3G_KP_UP", 0xff97)
    _ensurePybulletProperty("B3G_KP_RIGHT", 0xff98)
    _ensurePybulletProperty("B3G_KP_DOWN", 0xff99)
    _ensurePybulletProperty("B3G_KP_PGUP", 0xff9a)
    _ensurePybulletProperty("B3G_KP_PGDN", 0xff9b)
    _ensurePybulletProperty("B3G_KP_END", 0xff9c)
    _ensurePybulletProperty("B3G_KP_ENTER", 0xff8d)
    _ensurePybulletProperty("B3G_KP_INS", 0xff9e)
    _ensurePybulletProperty("B3G_KP_DEL", 0xff9f)
    _ensurePybulletProperty("B3G_KP_0", pybullet.B3G_KP_INS)
    _ensurePybulletProperty("B3G_KP_1", pybullet.B3G_KP_END)
    _ensurePybulletProperty("B3G_KP_2", pybullet.B3G_KP_DOWN)
    _ensurePybulletProperty("B3G_KP_3", pybullet.B3G_KP_PGDN)
    _ensurePybulletProperty("B3G_KP_4", pybullet.B3G_KP_LEFT)
    _ensurePybulletProperty("B3G_KP_5", 0xff9d)
    _ensurePybulletProperty("B3G_KP_6", pybullet.B3G_KP_RIGHT)
    _ensurePybulletProperty("B3G_KP_7", pybullet.B3G_KP_HOME)
    _ensurePybulletProperty("B3G_KP_8", pybullet.B3G_KP_UP)
    _ensurePybulletProperty("B3G_KP_9", pybullet.B3G_KP_PGUP)

  # Add the remaining pybullet functions and types

  if not hasattr(pybullet, "b3Print"): # {{{1
    def b3Print(msg):
      "Polyfilled b3Print function implemented in pure Python"
      sys.stdout.write(msg)
      sys.stdout.write("\n")
    pybullet.b3Print = b3Print
  # 1}}}

  if not hasattr(pybullet, "b3Warning"): # {{{1
    def b3Warning(msg):
      sys.stderr.write("Warning:")
      sys.stderr.write(msg)
      sys.stdout.write("\n")
    pybullet.b3Warning = b3Warning
  # 1}}}

  if not hasattr(pybullet, "b3Error"): # {{{1
    def b3Error(msg):
      sys.stderr.write("Error:")
      sys.stderr.write(msg)
      sys.stdout.write("\n")
    pybullet.b3Error = b3Error
  # 1}}}

  if not hasattr(pybullet, "NotConnectedError"): # {{{1
    pybullet.NotConnectedError = pybullet.error
  # 1}}}

  if not hasattr(pybullet, "addUserDebugButton"): # {{{1
    def addUserDebugButton(*args, **kwargs):
      "Stub function for an unimplemented feature"
      raise NotImplementedError()
    pybullet.addUserDebugButton = addUserDebugButton
  # 1}}}

  if not hasattr(pybullet, "readUserDebugButton"): # {{{1
    def readUserDebugButton(*args, **kwargs):
      "Stub function for an unimplemented feature"
      raise NotImplementedError()
    pybullet.readUserDebugButton = readUserDebugButton
  # 1}}}

  if not hasattr(pybullet, "resetUserDebugButton"): # {{{1
    def resetUserDebugButton(*args, **kwargs):
      "Stub function for an unimplemented feature"
      raise NotImplementedError
    pybullet.resetUserDebugButton = resetUserDebugButton
  # 1}}}

  if not hasattr(pybullet, "loadSoftBody"): # {{{1
    def loadSoftBody(*args, **kwargs):
      "Stub function for an unimplemented feature"
      raise NotImplementedError
    pybullet.loadSoftBody = loadSoftBody
  # 1}}}

  if not hasattr(pybullet, "createSoftBody"): # {{{1
    def createSoftBody(*args, **kwargs):
      "Stub function for an unimplemented feature"
      raise NotImplementedError
    pybullet.createSoftBody = createSoftBody
  # 1}}}
Ensure pybullet has all of the newly-added constants and functions
Ensure pybullet has all of the newly-added constants and functions
Ensure pybullet has all of the newly - added constants and functions
def ensurePybulletAPIs(): 
  def _ensurePybulletProperty(name, val): 
    logger = getLogger()
    if hasattr(pybullet, name):
      v = getattr(pybullet, name)
      if v != val:
        logger.warning("pybullet[{!r}] == {} (not {})".format(name, v, val))
    setattr(pybullet, name, val)
  _ensurePybulletProperty("MOUSE_MOVE_EVENT", 1)
  _ensurePybulletProperty("MOUSE_BUTTON_EVENT", 2)
  _ensurePybulletProperty("MOUSE_PRESS", 3)
  _ensurePybulletProperty("MOUSE_RELEASE", 4)
  _ensurePybulletProperty("MOUSE_BUTTON_NONE", -1)
  _ensurePybulletProperty("MOUSE_BUTTON_LEFT", 0)
  _ensurePybulletProperty("MOUSE_BUTTON_RIGHT", 2)
  _ensurePybulletProperty("MOUSE_LB", pybullet.MOUSE_BUTTON_LEFT)
  _ensurePybulletProperty("MOUSE_WHEEL", 1)
  _ensurePybulletProperty("MOUSE_RB", pybullet.MOUSE_BUTTON_RIGHT)
  _ensurePybulletProperty("B3G_LEFT", pybullet.B3G_LEFT_ARROW)
  _ensurePybulletProperty("B3G_UP", pybullet.B3G_UP_ARROW)
  _ensurePybulletProperty("B3G_RIGHT", pybullet.B3G_RIGHT_ARROW)
  _ensurePybulletProperty("B3G_DOWN", pybullet.B3G_DOWN_ARROW)
  try:
    import xkeys
    _ensurePybulletProperty("B3G_KP_HOME", xkeys.lib.Key_KP_Home)
    _ensurePybulletProperty("B3G_KP_LEFT", xkeys.lib.Key_KP_Left)
    _ensurePybulletProperty("B3G_KP_UP", xkeys.lib.Key_KP_Up)
    _ensurePybulletProperty("B3G_KP_RIGHT", xkeys.lib.Key_KP_Right)
    _ensurePybulletProperty("B3G_KP_DOWN", xkeys.lib.Key_KP_Down)
    _ensurePybulletProperty("B3G_KP_END", xkeys.lib.Key_KP_End)
    _ensurePybulletProperty("B3G_KP_PGUP", xkeys.lib.Key_KP_Page_Up)
    _ensurePybulletProperty("B3G_KP_PGDN", xkeys.lib.Key_KP_Page_Down)
    _ensurePybulletProperty("B3G_KP_END", xkeys.lib.Key_KP_End)
    _ensurePybulletProperty("B3G_KP_ENTER", xkeys.lib.Key_KP_Enter)
    _ensurePybulletProperty("B3G_KP_INS", xkeys.lib.Key_KP_Insert)
    _ensurePybulletProperty("B3G_KP_DEL", xkeys.lib.Key_KP_Delete)
    _ensurePybulletProperty("B3G_KP_0", pybullet.B3G_KP_0)
    _ensurePybulletProperty("B3G_KP_1", pybullet.B3G_KP_1)
    _ensurePybulletProperty("B3G_KP_2", pybullet.B3G_KP_2)
    _ensurePybulletProperty("B3G_KP_3", pybullet.B3G_KP_3)
    _ensurePybulletProperty("B3G_KP_4", pybullet.B3G_KP_4)
    _ensurePybulletProperty("B3G_KP_5", pybullet.B3G_KP_5)
    _ensurePybulletProperty("B3G_KP_6", pybullet.B3G_KP_6)
    _ensurePybulletProperty("B3G_KP_7", pybullet.B3G_KP_7)
    _ensurePybulletProperty("B3G_KP_8", pybullet.B3G_KP_8)
    _ensurePybulletProperty("B3G_KP_9", pybullet.B3G_KP_9)
  except ImportError as e:
    getLogger().exception(e)
    _ensurePybulletProperty("B3G_KP_HOME", 0xff95)
    _ensurePybulletProperty("B3G_KP_LEFT", 0xff96)
    _ensurePybulletProperty("B3G_KP_UP", 0xff97)
    _ensurePybulletProperty("B3G_KP_RIGHT", 0xff98)
    _ensurePybulletProperty("B3G_KP_DOWN", 0xff99)
    _ensurePybulletProperty("B3G_KP_PGUP", 0xff9a)
    _ensurePybulletProperty("B3G_KP_PGDN", 0xff9b)
    _ensurePybulletProperty("B3G_KP_END", 0xff9c)
    _ensurePybulletProperty("B3G_KP_ENTER", 0xff8d)
    _ensurePybulletProperty("B3G_KP_INS", 0xff9e)
    _ensurePybulletProperty("B3G_KP_DEL", 0xff9f)
    _ensurePybulletProperty("B3G_KP_0", pybullet.B3G_KP_INS)
    _ensurePybulletProperty("B3G_KP_1", pybullet.B3G_KP_END)
    _ensurePybulletProperty("B3G_KP_2", pybullet.B3G_KP_DOWN)
    _ensurePybulletProperty("B3G_KP_3", pybullet.B3G_KP_PGDN)
    _ensurePybulletProperty("B3G_KP_4", pybullet.B3G_KP_LEFT)
    _ensurePybulletProperty("B3G_KP_5", 0xff9d)
    _ensurePybulletProperty("B3G_KP_6", pybullet.B3G_KP_RIGHT)
    _ensurePybulletProperty("B3G_KP_7", pybullet.B3G_KP_HOME)
    _ensurePybulletProperty("B3G_KP_8", pybullet.B3G_KP_UP)
    _ensurePybulletProperty("B3G_KP_9", pybullet.B3G_KP_PGUP)
  if not hasattr(pybullet, "b3Print"): 
    def b3Print(msg):
      sys.stdout.write(msg)
      sys.stdout.write("\n")
    pybullet.b3Print = b3Print
  if not hasattr(pybullet, "b3Warning"): 
    def b3Warning(msg):
      sys.stderr.write("Warning:")
      sys.stderr.write(msg)
      sys.stdout.write("\n")
    pybullet.b3Warning = b3Warning
  if not hasattr(pybullet, "b3Error"): 
    def b3Error(msg):
      sys.stderr.write("Error:")
      sys.stderr.write(msg)
      sys.stdout.write("\n")
    pybullet.b3Error = b3Error
  if not hasattr(pybullet, "NotConnectedError"): 
    pybullet.NotConnectedError = pybullet.error
  if not hasattr(pybullet, "addUserDebugButton"): 
    def addUserDebugButton(*args, **kwargs):
      raise NotImplementedError()
    pybullet.addUserDebugButton = addUserDebugButton
  if not hasattr(pybullet, "readUserDebugButton"): 
    def readUserDebugButton(*args, **kwargs):
      raise NotImplementedError()
    pybullet.readUserDebugButton = readUserDebugButton
  if not hasattr(pybullet, "resetUserDebugButton"): 
    def resetUserDebugButton(*args, **kwargs):
      raise NotImplementedError
    pybullet.resetUserDebugButton = resetUserDebugButton
  if not hasattr(pybullet, "loadSoftBody"): 
    def loadSoftBody(*args, **kwargs):
      raise NotImplementedError
    pybullet.loadSoftBody = loadSoftBody
  if not hasattr(pybullet, "createSoftBody"): 
    def createSoftBody(*args, **kwargs):
      raise NotImplementedError
    pybullet.createSoftBody = createSoftBody
def ensurePybulletAPIs ( ) : def _ensurePybulletProperty ( name , val ) : "Ensure pybullet has the given attribute with the given value" logger = getLogger ( ) if hasattr ( pybullet , name ) : v = getattr ( pybullet , name ) if v != val : logger . warning ( "pybullet[{!r}] == {} (not {})" . format ( name , v , val ) ) setattr ( pybullet , name , val ) _ensurePybulletProperty ( "MOUSE_MOVE_EVENT" , 1 ) _ensurePybulletProperty ( "MOUSE_BUTTON_EVENT" , 2 ) _ensurePybulletProperty ( "MOUSE_PRESS" , 3 ) _ensurePybulletProperty ( "MOUSE_RELEASE" , 4 ) _ensurePybulletProperty ( "MOUSE_BUTTON_NONE" , - 1 ) _ensurePybulletProperty ( "MOUSE_BUTTON_LEFT" , 0 ) _ensurePybulletProperty ( "MOUSE_BUTTON_RIGHT" , 2 ) _ensurePybulletProperty ( "MOUSE_LB" , pybullet . MOUSE_BUTTON_LEFT ) _ensurePybulletProperty ( "MOUSE_WHEEL" , 1 ) _ensurePybulletProperty ( "MOUSE_RB" , pybullet . MOUSE_BUTTON_RIGHT ) _ensurePybulletProperty ( "B3G_LEFT" , pybullet . B3G_LEFT_ARROW ) _ensurePybulletProperty ( "B3G_UP" , pybullet . B3G_UP_ARROW ) _ensurePybulletProperty ( "B3G_RIGHT" , pybullet . B3G_RIGHT_ARROW ) _ensurePybulletProperty ( "B3G_DOWN" , pybullet . B3G_DOWN_ARROW ) try : import xkeys _ensurePybulletProperty ( "B3G_KP_HOME" , xkeys . lib . Key_KP_Home ) _ensurePybulletProperty ( "B3G_KP_LEFT" , xkeys . lib . Key_KP_Left ) _ensurePybulletProperty ( "B3G_KP_UP" , xkeys . lib . Key_KP_Up ) _ensurePybulletProperty ( "B3G_KP_RIGHT" , xkeys . lib . Key_KP_Right ) _ensurePybulletProperty ( "B3G_KP_DOWN" , xkeys . lib . Key_KP_Down ) _ensurePybulletProperty ( "B3G_KP_END" , xkeys . lib . Key_KP_End ) _ensurePybulletProperty ( "B3G_KP_PGUP" , xkeys . lib . Key_KP_Page_Up ) _ensurePybulletProperty ( "B3G_KP_PGDN" , xkeys . lib . Key_KP_Page_Down ) _ensurePybulletProperty ( "B3G_KP_END" , xkeys . lib . Key_KP_End ) _ensurePybulletProperty ( "B3G_KP_ENTER" , xkeys . lib . Key_KP_Enter ) _ensurePybulletProperty ( "B3G_KP_INS" , xkeys . lib . Key_KP_Insert ) _ensurePybulletProperty ( "B3G_KP_DEL" , xkeys . lib . Key_KP_Delete ) _ensurePybulletProperty ( "B3G_KP_0" , pybullet . B3G_KP_0 ) _ensurePybulletProperty ( "B3G_KP_1" , pybullet . B3G_KP_1 ) _ensurePybulletProperty ( "B3G_KP_2" , pybullet . B3G_KP_2 ) _ensurePybulletProperty ( "B3G_KP_3" , pybullet . B3G_KP_3 ) _ensurePybulletProperty ( "B3G_KP_4" , pybullet . B3G_KP_4 ) _ensurePybulletProperty ( "B3G_KP_5" , pybullet . B3G_KP_5 ) _ensurePybulletProperty ( "B3G_KP_6" , pybullet . B3G_KP_6 ) _ensurePybulletProperty ( "B3G_KP_7" , pybullet . B3G_KP_7 ) _ensurePybulletProperty ( "B3G_KP_8" , pybullet . B3G_KP_8 ) _ensurePybulletProperty ( "B3G_KP_9" , pybullet . B3G_KP_9 ) except ImportError as e : getLogger ( ) . exception ( e ) _ensurePybulletProperty ( "B3G_KP_HOME" , 0xff95 ) _ensurePybulletProperty ( "B3G_KP_LEFT" , 0xff96 ) _ensurePybulletProperty ( "B3G_KP_UP" , 0xff97 ) _ensurePybulletProperty ( "B3G_KP_RIGHT" , 0xff98 ) _ensurePybulletProperty ( "B3G_KP_DOWN" , 0xff99 ) _ensurePybulletProperty ( "B3G_KP_PGUP" , 0xff9a ) _ensurePybulletProperty ( "B3G_KP_PGDN" , 0xff9b ) _ensurePybulletProperty ( "B3G_KP_END" , 0xff9c ) _ensurePybulletProperty ( "B3G_KP_ENTER" , 0xff8d ) _ensurePybulletProperty ( "B3G_KP_INS" , 0xff9e ) _ensurePybulletProperty ( "B3G_KP_DEL" , 0xff9f ) _ensurePybulletProperty ( "B3G_KP_0" , pybullet . B3G_KP_INS ) _ensurePybulletProperty ( "B3G_KP_1" , pybullet . B3G_KP_END ) _ensurePybulletProperty ( "B3G_KP_2" , pybullet . B3G_KP_DOWN ) _ensurePybulletProperty ( "B3G_KP_3" , pybullet . B3G_KP_PGDN ) _ensurePybulletProperty ( "B3G_KP_4" , pybullet . B3G_KP_LEFT ) _ensurePybulletProperty ( "B3G_KP_5" , 0xff9d ) _ensurePybulletProperty ( "B3G_KP_6" , pybullet . B3G_KP_RIGHT ) _ensurePybulletProperty ( "B3G_KP_7" , pybullet . B3G_KP_HOME ) _ensurePybulletProperty ( "B3G_KP_8" , pybullet . B3G_KP_UP ) _ensurePybulletProperty ( "B3G_KP_9" , pybullet . B3G_KP_PGUP ) if not hasattr ( pybullet , "b3Print" ) : def b3Print ( msg ) : "Polyfilled b3Print function implemented in pure Python" sys . stdout . write ( msg ) sys . stdout . write ( "\n" ) pybullet . b3Print = b3Print if not hasattr ( pybullet , "b3Warning" ) : def b3Warning ( msg ) : sys . stderr . write ( "Warning:" ) sys . stderr . write ( msg ) sys . stdout . write ( "\n" ) pybullet . b3Warning = b3Warning if not hasattr ( pybullet , "b3Error" ) : def b3Error ( msg ) : sys . stderr . write ( "Error:" ) sys . stderr . write ( msg ) sys . stdout . write ( "\n" ) pybullet . b3Error = b3Error if not hasattr ( pybullet , "NotConnectedError" ) : pybullet . NotConnectedError = pybullet . error if not hasattr ( pybullet , "addUserDebugButton" ) : def addUserDebugButton ( * args , ** kwargs ) : "Stub function for an unimplemented feature" raise NotImplementedError ( ) pybullet . addUserDebugButton = addUserDebugButton if not hasattr ( pybullet , "readUserDebugButton" ) : def readUserDebugButton ( * args , ** kwargs ) : "Stub function for an unimplemented feature" raise NotImplementedError ( ) pybullet . readUserDebugButton = readUserDebugButton if not hasattr ( pybullet , "resetUserDebugButton" ) : def resetUserDebugButton ( * args , ** kwargs ) : "Stub function for an unimplemented feature" raise NotImplementedError pybullet . resetUserDebugButton = resetUserDebugButton if not hasattr ( pybullet , "loadSoftBody" ) : def loadSoftBody ( * args , ** kwargs ) : "Stub function for an unimplemented feature" raise NotImplementedError pybullet . loadSoftBody = loadSoftBody if not hasattr ( pybullet , "createSoftBody" ) : def createSoftBody ( * args , ** kwargs ) : "Stub function for an unimplemented feature" raise NotImplementedError pybullet . createSoftBody = createSoftBody
Ensure pybullet has all of the newly-added constants and functions
Ensure pybullet has all of the newly - added constants and functions
# {{{0 "Ensure pybullet has all of the newly-added constants and functions" # {{{1 "Ensure pybullet has the given attribute with the given value" # 1}}} # Ensure pybullet has the added constants # Add the rest of the keys using the xkeys FFI module, if available # Add the remaining pybullet functions and types # {{{1 "Polyfilled b3Print function implemented in pure Python" # 1}}} # {{{1 # 1}}} # {{{1 # 1}}} # {{{1 # 1}}} # {{{1 "Stub function for an unimplemented feature" # 1}}} # {{{1 "Stub function for an unimplemented feature" # 1}}} # {{{1 "Stub function for an unimplemented feature" # 1}}} # {{{1 "Stub function for an unimplemented feature" # 1}}} # {{{1 "Stub function for an unimplemented feature" # 1}}}