mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
Begin to add snake_case/property interfaces to important direct classes
This commit is contained in:
parent
cdc8d7d4d9
commit
dafe48a6bc
@ -158,10 +158,10 @@ class OnscreenText(DirectObject, NodePath):
|
||||
scale = (scale, scale)
|
||||
|
||||
# Save some of the parameters for posterity.
|
||||
self.scale = scale
|
||||
self.pos = pos
|
||||
self.roll = roll
|
||||
self.wordwrap = wordwrap
|
||||
self.__scale = scale
|
||||
self.__pos = pos
|
||||
self.__roll = roll
|
||||
self.__wordwrap = wordwrap
|
||||
|
||||
if decal:
|
||||
textNode.setCardDecal(1)
|
||||
@ -249,12 +249,16 @@ class OnscreenText(DirectObject, NodePath):
|
||||
def getDecal(self):
|
||||
return self.textNode.getCardDecal()
|
||||
|
||||
decal = property(getDecal, setDecal)
|
||||
|
||||
def setFont(self, font):
|
||||
self.textNode.setFont(font)
|
||||
|
||||
def getFont(self):
|
||||
return self.textNode.getFont()
|
||||
|
||||
font = property(getFont, setFont)
|
||||
|
||||
def clearText(self):
|
||||
self.textNode.clearText()
|
||||
|
||||
@ -279,31 +283,37 @@ class OnscreenText(DirectObject, NodePath):
|
||||
else:
|
||||
return self.textNode.getText()
|
||||
|
||||
text = property(getText, setText)
|
||||
|
||||
def setX(self, x):
|
||||
self.setPos(x, self.pos[1])
|
||||
self.setPos(x, self.__pos[1])
|
||||
|
||||
def setY(self, y):
|
||||
self.setPos(self.pos[0], y)
|
||||
self.setPos(self.__pos[0], y)
|
||||
|
||||
def setPos(self, x, y):
|
||||
"""setPos(self, float, float)
|
||||
Position the onscreen text in 2d screen space
|
||||
"""
|
||||
self.pos = (x, y)
|
||||
self.__pos = (x, y)
|
||||
self.updateTransformMat()
|
||||
|
||||
def getPos(self):
|
||||
return self.pos
|
||||
return self.__pos
|
||||
|
||||
pos = property(getPos, setPos)
|
||||
|
||||
def setRoll(self, roll):
|
||||
"""setRoll(self, float)
|
||||
Rotate the onscreen text around the screen's normal
|
||||
"""
|
||||
self.roll = roll
|
||||
self.__roll = roll
|
||||
self.updateTransformMat()
|
||||
|
||||
def getRoll(self):
|
||||
return self.roll
|
||||
return self.__roll
|
||||
|
||||
roll = property(getRoll, setRoll)
|
||||
|
||||
def setScale(self, sx, sy = None):
|
||||
"""setScale(self, float, float)
|
||||
@ -313,27 +323,29 @@ class OnscreenText(DirectObject, NodePath):
|
||||
|
||||
if sy == None:
|
||||
if isinstance(sx, types.TupleType):
|
||||
self.scale = sx
|
||||
self.__scale = sx
|
||||
else:
|
||||
self.scale = (sx, sx)
|
||||
self.__scale = (sx, sx)
|
||||
else:
|
||||
self.scale = (sx, sy)
|
||||
self.__scale = (sx, sy)
|
||||
self.updateTransformMat()
|
||||
|
||||
def updateTransformMat(self):
|
||||
assert(isinstance(self.textNode, TextNode))
|
||||
mat = (
|
||||
Mat4.scaleMat(Vec3.rfu(self.scale[0], 1, self.scale[1])) *
|
||||
Mat4.rotateMat(self.roll, Vec3.back()) *
|
||||
Mat4.translateMat(Point3.rfu(self.pos[0], 0, self.pos[1]))
|
||||
Mat4.scaleMat(Vec3.rfu(self.__scale[0], 1, self.__scale[1])) *
|
||||
Mat4.rotateMat(self.__roll, Vec3.back()) *
|
||||
Mat4.translateMat(Point3.rfu(self.__pos[0], 0, self.__pos[1]))
|
||||
)
|
||||
self.textNode.setTransform(mat)
|
||||
|
||||
def getScale(self):
|
||||
return self.scale
|
||||
return self.__scale
|
||||
|
||||
scale = property(getScale, setScale)
|
||||
|
||||
def setWordwrap(self, wordwrap):
|
||||
self.wordwrap = wordwrap
|
||||
self.__wordwrap = wordwrap
|
||||
|
||||
if wordwrap:
|
||||
self.textNode.setWordwrap(wordwrap)
|
||||
@ -341,11 +353,24 @@ class OnscreenText(DirectObject, NodePath):
|
||||
self.textNode.clearWordwrap()
|
||||
|
||||
def getWordwrap(self):
|
||||
return self.wordwrap
|
||||
return self.__wordwrap
|
||||
|
||||
wordwrap = property(getWordwrap, setWordwrap)
|
||||
|
||||
def __getFg(self):
|
||||
return self.textNode.getTextColor()
|
||||
|
||||
def setFg(self, fg):
|
||||
self.textNode.setTextColor(fg[0], fg[1], fg[2], fg[3])
|
||||
|
||||
fg = property(__getFg, setFg)
|
||||
|
||||
def __getBg(self):
|
||||
if self.textNode.hasCard():
|
||||
return self.textNode.getCardColor()
|
||||
else:
|
||||
return LColor(0)
|
||||
|
||||
def setBg(self, bg):
|
||||
if bg[3] != 0:
|
||||
# If we have a background color, create a card.
|
||||
@ -355,6 +380,11 @@ class OnscreenText(DirectObject, NodePath):
|
||||
# Otherwise, remove the card.
|
||||
self.textNode.clearCard()
|
||||
|
||||
bg = property(__getBg, setBg)
|
||||
|
||||
def __getShadow(self):
|
||||
return self.textNode.getShadowColor()
|
||||
|
||||
def setShadow(self, shadow):
|
||||
if shadow[3] != 0:
|
||||
# If we have a shadow color, create a shadow.
|
||||
@ -364,6 +394,11 @@ class OnscreenText(DirectObject, NodePath):
|
||||
# Otherwise, remove the shadow.
|
||||
self.textNode.clearShadow()
|
||||
|
||||
shadow = property(__getShadow, setShadow)
|
||||
|
||||
def __getFrame(self):
|
||||
return self.textNode.getFrameColor()
|
||||
|
||||
def setFrame(self, frame):
|
||||
if frame[3] != 0:
|
||||
# If we have a frame color, create a frame.
|
||||
@ -373,6 +408,8 @@ class OnscreenText(DirectObject, NodePath):
|
||||
# Otherwise, remove the frame.
|
||||
self.textNode.clearFrame()
|
||||
|
||||
frame = property(__getFrame, setFrame)
|
||||
|
||||
def configure(self, option=None, **kw):
|
||||
# These is for compatibility with DirectGui functions
|
||||
if not self.mayChange:
|
||||
@ -399,9 +436,14 @@ class OnscreenText(DirectObject, NodePath):
|
||||
getter = getattr(self, 'get' + option[0].upper() + option[1:])
|
||||
return getter()
|
||||
|
||||
def __getAlign(self):
|
||||
return self.textNode.getAlign()
|
||||
|
||||
def setAlign(self, align):
|
||||
self.textNode.setAlign(align)
|
||||
|
||||
align = property(__getAlign, setAlign)
|
||||
|
||||
# Allow index style refererences
|
||||
__getitem__ = cget
|
||||
|
||||
|
@ -398,6 +398,12 @@ class Interval(DirectObject):
|
||||
space = space + ' '
|
||||
return (space + self.name + ' dur: %.2f' % self.duration)
|
||||
|
||||
open_ended = property(getOpenEnded)
|
||||
loop = property(getLoop, setLoop)
|
||||
stopped = property(isStopped)
|
||||
t = property(getT, setT)
|
||||
play_rate = property(getPlayRate, setPlayRate)
|
||||
done_event = property(getDoneEvent, setDoneEvent)
|
||||
|
||||
# The rest of these methods are duplicates of functions defined
|
||||
# for the CInterval class via the file CInterval-extensions.py.
|
||||
|
@ -124,6 +124,20 @@ PUBLISHED:
|
||||
void setup_resume_until(double end_t);
|
||||
bool step_play();
|
||||
|
||||
PUBLISHED:
|
||||
MAKE_PROPERTY(name, get_name);
|
||||
MAKE_PROPERTY(duration, get_duration);
|
||||
MAKE_PROPERTY(open_ended, get_open_ended);
|
||||
MAKE_PROPERTY(state, get_state);
|
||||
MAKE_PROPERTY(stopped, is_stopped);
|
||||
MAKE_PROPERTY(done_event, get_done_event, set_done_event);
|
||||
MAKE_PROPERTY(t, get_t, set_t);
|
||||
MAKE_PROPERTY(auto_pause, get_auto_pause, set_auto_pause);
|
||||
MAKE_PROPERTY(auto_finish, get_auto_finish, set_auto_finish);
|
||||
MAKE_PROPERTY(manager, get_manager, set_manager);
|
||||
MAKE_PROPERTY(play_rate, get_play_rate, set_play_rate);
|
||||
MAKE_PROPERTY(playing, is_playing);
|
||||
|
||||
public:
|
||||
void mark_dirty();
|
||||
INLINE bool check_t_callback();
|
||||
|
@ -167,7 +167,7 @@ class Loader(DirectObject):
|
||||
|
||||
if not okMissing and None in result:
|
||||
message = 'Could not load model file(s): %s' % (modelList,)
|
||||
raise IOError, message
|
||||
raise IOError(message)
|
||||
|
||||
if gotList:
|
||||
return result
|
||||
@ -503,7 +503,7 @@ class Loader(DirectObject):
|
||||
if font == None:
|
||||
if not okMissing:
|
||||
message = 'Could not load font file: %s' % (modelPath)
|
||||
raise IOError, message
|
||||
raise IOError(message)
|
||||
# If we couldn't load the model, at least return an
|
||||
# empty font.
|
||||
font = StaticTextFont(PandaNode("empty"))
|
||||
@ -620,7 +620,7 @@ class Loader(DirectObject):
|
||||
texture = TexturePool.loadTexture(texturePath, alphaPath, 0, 0, readMipmaps, loaderOptions)
|
||||
if not texture and not okMissing:
|
||||
message = 'Could not load texture: %s' % (texturePath)
|
||||
raise IOError, message
|
||||
raise IOError(message)
|
||||
|
||||
if minfilter is not None:
|
||||
texture.setMinfilter(minfilter)
|
||||
@ -677,7 +677,7 @@ class Loader(DirectObject):
|
||||
texture = TexturePool.load3dTexture(texturePattern, readMipmaps, loaderOptions)
|
||||
if not texture and not okMissing:
|
||||
message = 'Could not load 3-D texture: %s' % (texturePattern)
|
||||
raise IOError, message
|
||||
raise IOError(message)
|
||||
|
||||
if minfilter is not None:
|
||||
texture.setMinfilter(minfilter)
|
||||
@ -730,7 +730,7 @@ class Loader(DirectObject):
|
||||
texture = TexturePool.loadCubeMap(texturePattern, readMipmaps, loaderOptions)
|
||||
if not texture and not okMissing:
|
||||
message = 'Could not load cube map: %s' % (texturePattern)
|
||||
raise IOError, message
|
||||
raise IOError(message)
|
||||
|
||||
if minfilter is not None:
|
||||
texture.setMinfilter(minfilter)
|
||||
@ -838,7 +838,7 @@ class Loader(DirectObject):
|
||||
cb.requests[request] = True
|
||||
return cb
|
||||
|
||||
def unloadSfx (self, sfx):
|
||||
def unloadSfx(self, sfx):
|
||||
if (sfx):
|
||||
if(self.base.sfxManagerList):
|
||||
self.base.sfxManagerList[0].uncacheSound (sfx.getName())
|
||||
@ -852,11 +852,11 @@ class Loader(DirectObject):
|
||||
## nodeCount += 1
|
||||
## self.makeNodeNamesUnique(nodePath.getChild(i), nodeCount)
|
||||
|
||||
def loadShader (self, shaderPath, okMissing = False):
|
||||
def loadShader(self, shaderPath, okMissing = False):
|
||||
shader = ShaderPool.loadShader (shaderPath)
|
||||
if not shader and not okMissing:
|
||||
message = 'Could not load shader file: %s' % (shaderPath)
|
||||
raise IOError, message
|
||||
raise IOError(message)
|
||||
return shader
|
||||
|
||||
def unloadShader(self, shaderPath):
|
||||
@ -948,3 +948,21 @@ class Loader(DirectObject):
|
||||
object = request.getSuccess()
|
||||
|
||||
cb.gotObject(i, object)
|
||||
|
||||
load_model = loadModel
|
||||
cancel_request = cancelRequest
|
||||
is_request_pending = isRequestPending
|
||||
unload_model = unloadModel
|
||||
save_model = saveModel
|
||||
load_font = loadFont
|
||||
load_texture = loadTexture
|
||||
load_3d_texture = load3DTexture
|
||||
load_cube_map = loadCubeMap
|
||||
unload_texture = unloadTexture
|
||||
load_sfx = loadSfx
|
||||
load_music = loadMusic
|
||||
load_sound = loadSound
|
||||
unload_sfx = unloadSfx
|
||||
load_shader = loadShader
|
||||
unload_shader = unloadShader
|
||||
async_flatten_strong = asyncFlattenStrong
|
||||
|
@ -78,11 +78,13 @@ class ShowBase(DirectObject.DirectObject):
|
||||
|
||||
## The directory containing the main Python file of this application.
|
||||
self.mainDir = ExecutionEnvironment.getEnvironmentVariable("MAIN_DIR")
|
||||
self.main_dir = self.mainDir
|
||||
|
||||
## This contains the global appRunner instance, as imported from
|
||||
## AppRunnerGlobal. This will be None if we are not running in the
|
||||
## runtime environment (ie. from a .p3d file).
|
||||
self.appRunner = AppRunnerGlobal.appRunner
|
||||
self.app_runner = self.appRunner
|
||||
|
||||
#debug running multiplier
|
||||
self.debugRunningMultiplier = 4
|
||||
@ -215,6 +217,7 @@ class ShowBase(DirectObject.DirectObject):
|
||||
|
||||
## The global graphics engine, ie. GraphicsEngine.getGlobalPtr()
|
||||
self.graphicsEngine = GraphicsEngine.getGlobalPtr()
|
||||
self.graphics_engine = self.graphicsEngine
|
||||
self.setupRender()
|
||||
self.setupRender2d()
|
||||
self.setupDataGraph()
|
||||
@ -283,6 +286,7 @@ class ShowBase(DirectObject.DirectObject):
|
||||
self.bboard = bulletinBoard
|
||||
## The global task manager, as imported from TaskManagerGlobal.
|
||||
self.taskMgr = taskMgr
|
||||
self.task_mgr = taskMgr
|
||||
## The global job manager, as imported from JobManagerGlobal.
|
||||
self.jobMgr = jobMgr
|
||||
|
||||
@ -992,9 +996,9 @@ class ShowBase(DirectObject.DirectObject):
|
||||
else:
|
||||
# Spawn it after igloop (at the end of each frame)
|
||||
self.taskMgr.remove('clientSleep')
|
||||
self.taskMgr.add(self.sleepCycleTask, 'clientSleep', sort = 55)
|
||||
self.taskMgr.add(self.__sleepCycleTask, 'clientSleep', sort = 55)
|
||||
|
||||
def sleepCycleTask(self, task):
|
||||
def __sleepCycleTask(self, task):
|
||||
Thread.sleep(self.clientSleep)
|
||||
#time.sleep(self.clientSleep)
|
||||
return Task.cont
|
||||
@ -1785,12 +1789,14 @@ class ShowBase(DirectObject.DirectObject):
|
||||
# backwards compatibility. Please do not add code here, add
|
||||
# it to the loader.
|
||||
def loadSfx(self, name):
|
||||
self.notify.warning("base.loadSfx is deprecated, use base.loader.loadSfx instead.")
|
||||
return self.loader.loadSfx(name)
|
||||
|
||||
# This function should only be in the loader but is here for
|
||||
# backwards compatibility. Please do not add code here, add
|
||||
# it to the loader.
|
||||
def loadMusic(self, name):
|
||||
self.notify.warning("base.loadMusic is deprecated, use base.loader.loadMusic instead.")
|
||||
return self.loader.loadMusic(name)
|
||||
|
||||
def playSfx(
|
||||
@ -2985,6 +2991,74 @@ class ShowBase(DirectObject.DirectObject):
|
||||
self.taskMgr.run()
|
||||
|
||||
|
||||
# Snake-case aliases, for people who prefer these. We're in the process
|
||||
# of migrating everyone to use the snake-case alternatives.
|
||||
make_default_pipe = makeDefaultPipe
|
||||
make_module_pipe = makeModulePipe
|
||||
make_all_pipes = makeAllPipes
|
||||
open_window = openWindow
|
||||
close_window = closeWindow
|
||||
open_default_window = openDefaultWindow
|
||||
open_main_window = openMainWindow
|
||||
set_sleep = setSleep
|
||||
set_frame_rate_meter = setFrameRateMeter
|
||||
set_scene_graph_analyzer_meter = setSceneGraphAnalyzerMeter
|
||||
setup_window_controls = setupWindowControls
|
||||
setup_render = setupRender
|
||||
setup_render2d = setupRender2d
|
||||
setup_render2dp = setupRender2dp
|
||||
set_aspect_ratio = setAspectRatio
|
||||
get_aspect_ratio = getAspectRatio
|
||||
get_size = getSize
|
||||
make_camera = makeCamera
|
||||
make_camera2d = makeCamera2d
|
||||
make_camera2dp = makeCamera2dp
|
||||
setup_data_graph = setupDataGraph
|
||||
setup_mouse = setupMouse
|
||||
setup_mouse_cb = setupMouseCB
|
||||
enable_software_mouse_pointer = enableSoftwareMousePointer
|
||||
add_angular_integrator = addAngularIntegrator
|
||||
enable_particles = enableParticles
|
||||
disable_particles = disableParticles
|
||||
toggle_particles = toggleParticles
|
||||
create_stats = createStats
|
||||
add_sfx_manager = addSfxManager
|
||||
enable_music = enableMusic
|
||||
enable_sound_effects = enableSoundEffects
|
||||
disable_all_audio = disableAllAudio
|
||||
enable_all_audio = enableAllAudio
|
||||
init_shadow_trav = initShadowTrav
|
||||
get_background_color = getBackgroundColor
|
||||
set_background_color = setBackgroundColor
|
||||
toggle_backface = toggleBackface
|
||||
backface_culling_on = backfaceCullingOn
|
||||
backface_culling_off = backfaceCullingOff
|
||||
toggle_texture = toggleTexture
|
||||
texture_on = textureOn
|
||||
texture_off = textureOff
|
||||
toggle_wireframe = toggleWireframe
|
||||
wireframe_on = wireframeOn
|
||||
wireframe_off = wireframeOff
|
||||
disable_mouse = disableMouse
|
||||
enable_mouse = enableMouse
|
||||
silence_input = silenceInput
|
||||
revive_input = reviveInput
|
||||
set_mouse_on_node = setMouseOnNode
|
||||
change_mouse_interface = changeMouseInterface
|
||||
use_drive = useDrive
|
||||
use_trackball = useTrackball
|
||||
toggle_tex_mem = toggleTexMem
|
||||
toggle_show_vertices = toggleShowVertices
|
||||
oobe_cull = oobeCull
|
||||
show_camera_frustum = showCameraFrustum
|
||||
remove_camera_frustum = removeCameraFrustum
|
||||
save_cube_map = saveCubeMap
|
||||
save_sphere_map = saveSphereMap
|
||||
start_wx = startWx
|
||||
start_tk = startTk
|
||||
start_direct = startDirect
|
||||
|
||||
|
||||
# A class to encapsulate information necessary for multiwindow support.
|
||||
class WindowControls:
|
||||
def __init__(
|
||||
|
@ -149,6 +149,8 @@ class TaskManager:
|
||||
self.mgr.setClock(clockObject)
|
||||
self.globalClock = clockObject
|
||||
|
||||
clock = property(lambda self: self.mgr.getClock(), setClock)
|
||||
|
||||
def invokeDefaultHandler(self, signalNumber, stackFrame):
|
||||
print '*** allowing mid-frame keyboard interrupt.'
|
||||
# Restore default interrupt handler
|
||||
@ -311,6 +313,8 @@ class TaskManager:
|
||||
self.mgr.add(task)
|
||||
return task
|
||||
|
||||
do_method_later = doMethodLater
|
||||
|
||||
def add(self, funcOrTask, name = None, sort = None, extraArgs = None,
|
||||
priority = None, uponDeath = None, appendTask = False,
|
||||
taskChain = None, owner = None):
|
||||
|
@ -60,6 +60,7 @@ PUBLISHED:
|
||||
|
||||
INLINE void set_clock(ClockObject *clock);
|
||||
INLINE ClockObject *get_clock();
|
||||
MAKE_PROPERTY(clock, get_clock, set_clock);
|
||||
|
||||
int get_num_task_chains() const;
|
||||
AsyncTaskChain *get_task_chain(int n) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user