mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-29 08:15:18 -04:00
direct: fix various uses of types.MethodType in Python 3 (from #1000)
This commit is contained in:
parent
1cc82f47b6
commit
dae9e31223
@ -4,6 +4,7 @@ __all__ = ['State']
|
|||||||
|
|
||||||
from direct.directnotify.DirectNotifyGlobal import directNotify
|
from direct.directnotify.DirectNotifyGlobal import directNotify
|
||||||
from direct.showbase.DirectObject import DirectObject
|
from direct.showbase.DirectObject import DirectObject
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
class State(DirectObject):
|
class State(DirectObject):
|
||||||
@ -32,16 +33,24 @@ class State(DirectObject):
|
|||||||
if type(enterFunc) == types.MethodType:
|
if type(enterFunc) == types.MethodType:
|
||||||
if enterFunc.__func__ == oldFunction:
|
if enterFunc.__func__ == oldFunction:
|
||||||
# print 'found: ', enterFunc, oldFunction
|
# print 'found: ', enterFunc, oldFunction
|
||||||
state.setEnterFunc(types.MethodType(newFunction,
|
if sys.version_info >= (3, 0):
|
||||||
enterFunc.__self__,
|
state.setEnterFunc(types.MethodType(newFunction,
|
||||||
enterFunc.__self__.__class__))
|
enterFunc.__self__))
|
||||||
|
else:
|
||||||
|
state.setEnterFunc(types.MethodType(newFunction,
|
||||||
|
enterFunc.__self__,
|
||||||
|
enterFunc.__self__.__class__))
|
||||||
count += 1
|
count += 1
|
||||||
if type(exitFunc) == types.MethodType:
|
if type(exitFunc) == types.MethodType:
|
||||||
if exitFunc.__func__ == oldFunction:
|
if exitFunc.__func__ == oldFunction:
|
||||||
# print 'found: ', exitFunc, oldFunction
|
# print 'found: ', exitFunc, oldFunction
|
||||||
state.setExitFunc(types.MethodType(newFunction,
|
if sys.version_info >= (3, 0):
|
||||||
exitFunc.__self__,
|
state.setExitFunc(types.MethodType(newFunction,
|
||||||
exitFunc.__self__.__class__))
|
exitFunc.__self__))
|
||||||
|
else:
|
||||||
|
state.setExitFunc(types.MethodType(newFunction,
|
||||||
|
exitFunc.__self__,
|
||||||
|
exitFunc.__self__.__class__))
|
||||||
count += 1
|
count += 1
|
||||||
return count
|
return count
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ from panda3d.direct import *
|
|||||||
from direct.showbase.MessengerGlobal import *
|
from direct.showbase.MessengerGlobal import *
|
||||||
from direct.directnotify.DirectNotifyGlobal import directNotify
|
from direct.directnotify.DirectNotifyGlobal import directNotify
|
||||||
from . import Interval
|
from . import Interval
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
#############################################################
|
#############################################################
|
||||||
@ -36,9 +37,13 @@ class FunctionInterval(Interval.Interval):
|
|||||||
if type(ival.function) == types.MethodType:
|
if type(ival.function) == types.MethodType:
|
||||||
if ival.function.__func__ == oldFunction:
|
if ival.function.__func__ == oldFunction:
|
||||||
# print 'found: ', ival.function, oldFunction
|
# print 'found: ', ival.function, oldFunction
|
||||||
ival.function = types.MethodType(newFunction,
|
if sys.version_info >= (3, 0):
|
||||||
ival.function.__self__,
|
ival.function = types.MethodType(newFunction,
|
||||||
ival.function.__self__.__class__)
|
ival.function.__self__)
|
||||||
|
else:
|
||||||
|
ival.function = types.MethodType(newFunction,
|
||||||
|
ival.function.__self__,
|
||||||
|
ival.function.__self__.__class__)
|
||||||
count += 1
|
count += 1
|
||||||
return count
|
return count
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ __all__ = ['Messenger']
|
|||||||
from .PythonUtil import *
|
from .PythonUtil import *
|
||||||
from direct.directnotify import DirectNotifyGlobal
|
from direct.directnotify import DirectNotifyGlobal
|
||||||
import types
|
import types
|
||||||
|
import sys
|
||||||
|
|
||||||
from direct.stdpy.threading import Lock
|
from direct.stdpy.threading import Lock
|
||||||
|
|
||||||
@ -464,8 +465,11 @@ class Messenger:
|
|||||||
# 'oldMethod: ' + repr(oldMethod) + '\n' +
|
# 'oldMethod: ' + repr(oldMethod) + '\n' +
|
||||||
# 'newFunction: ' + repr(newFunction) + '\n')
|
# 'newFunction: ' + repr(newFunction) + '\n')
|
||||||
if (function == oldMethod):
|
if (function == oldMethod):
|
||||||
newMethod = types.MethodType(
|
if sys.version_info >= (3, 0):
|
||||||
newFunction, method.__self__, method.__self__.__class__)
|
newMethod = types.MethodType(newFunction, method.__self__)
|
||||||
|
else:
|
||||||
|
newMethod = types.MethodType(
|
||||||
|
newFunction, method.__self__, method.__self__.__class__)
|
||||||
params[0] = newMethod
|
params[0] = newMethod
|
||||||
# Found it retrun true
|
# Found it retrun true
|
||||||
retFlag += 1
|
retFlag += 1
|
||||||
|
@ -1600,7 +1600,10 @@ def appendStr(obj, st):
|
|||||||
return s
|
return s
|
||||||
oldStr = Functor(stringer, str(obj))
|
oldStr = Functor(stringer, str(obj))
|
||||||
stringer = None
|
stringer = None
|
||||||
obj.__str__ = types.MethodType(Functor(appendedStr, oldStr, st), obj, obj.__class__)
|
if sys.version_info >= (3, 0):
|
||||||
|
obj.__str__ = types.MethodType(Functor(appendedStr, oldStr, st), obj)
|
||||||
|
else:
|
||||||
|
obj.__str__ = types.MethodType(Functor(appendedStr, oldStr, st), obj, obj.__class__)
|
||||||
appendedStr = None
|
appendedStr = None
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
@ -599,9 +599,13 @@ class TaskManager:
|
|||||||
else:
|
else:
|
||||||
function = method
|
function = method
|
||||||
if (function == oldMethod):
|
if (function == oldMethod):
|
||||||
newMethod = types.MethodType(newFunction,
|
if sys.version_info >= (3, 0):
|
||||||
method.__self__,
|
newMethod = types.MethodType(newFunction,
|
||||||
method.__self__.__class__)
|
method.__self__)
|
||||||
|
else:
|
||||||
|
newMethod = types.MethodType(newFunction,
|
||||||
|
method.__self__,
|
||||||
|
method.__self__.__class__)
|
||||||
task.setFunction(newMethod)
|
task.setFunction(newMethod)
|
||||||
# Found a match
|
# Found a match
|
||||||
return 1
|
return 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user