how to find a function in Panda3D?

i have trouble finding the path for Panda3D functions.
for example, if i want to call getForeground(), how do i know the path: showbase.showbase.win.getProperties().getForeground() ? - if i don’t search the forum or sample programs.

btw: i searched getForeground in Reference, it saids
panda3d::core::WindowProperties.
how should i comprehense this path ?

If I’m not much mistaken, it means that “getForeground” is a method of the “WindowProperties” class, which is in the “panda3d.core” package (if I recall my Python nomenclature correctly).

If I may ask, why are you searching this way around? I would expect rather that you’d usually have an object that you wanted to do something with, and so would look at what methods it has available, rather than having a method that you want to find an object to apply to, which appears to be your case…

In short, your I find your situation and intent confusing – could you please clarify it?

Not sure how to explain, so i’l let
Python do it.
Especially chapter 9 may interest you.

But you kinda answered your question yourself.
panda3d::core::windowProperties in code would be

from panda3d.core import WindowProperties

which in human would be

Get me WindowProperties from core located in panda3d

to quote an old teacher :slight_smile:

And you could then do:

print WindowProperties().getForeground()

to see if window has focus.

In the first code I believe you are trying to do the same but with an instantiated ShowBase object, I’m not that familiar with panda yet so i have to look at the code to be sure.

I’m afraid that I’m still not confident that I understand what you’re asking, but let me attempt to answer anyway…

Hmm… Given that one could potentially have more than one window, I would imagine that you’d want to get hold of a specific instance in order to specify which window it is that you want information on. Based on what experience I have with Panda (and I may very well be incorrect here), this might be fetched from some global singleton instance somewhere.

In general I would expect to be dealing with instances of objects and methods belonging to them, rather than free-floating functions, in case that’s what you were expecting.

So… Given that you can find the class to which a method belongs and the module in which to find that class, both from the reference, is there anything more that is not answered?

after searching the Reference, i did try:
from panda3d.core import WindowProperties
then have in script:
if(WindowProperties().getForeground()==0): …

then python told me : getForeground() needs an argument. but i don’t know what argument should i put in.

later i found in forum:
win.getProperties().getForeground() , it works without any argument.

maybe my question should be:
how do i know there is getProperties in
showbase.showbase.win ?

which documentation should i refer to?

You ask ‘is the window focused?’
Panda/python says: ‘what window?’

The docs on this one do not point out that you need a window to get the window properties of.

WindowProperties::getForeground() does not need an EXPLICIT argument. It is an instance method, and thus needs the “self” argument. But this is added automatically by Python IF (!!!) you have an instance.

Is it possible that you didn’t type exactly what you are posting?

>>> if(WindowProperties().getForeground()==0): pass
...
>>> if(WindowProperties.getForeground()==0): pass
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: descriptor 'getForeground' of 'libpanda.WindowProperties' object needs an argument

To elaborate a little, this:

is incorrect - an argument is actually being provided to it, as it desires: in Python, as enn0x indicated, instance methods – which getForeground is, I believe, and which it should be described as in the reference – are automatically provided as their first argument a reference to the object on which they are being called, often given the parameter name “self”.

That’s perhaps a little trickier – you essentially want to know what class “showbase.win” is. I imagine, however, that it’s mentioned somewhere in the manual, so a search of that might help. Knowing the class you should be able to simply look up its methods in the reference.

Are you trying to instantiate the WindowProperties class there? If so, why? How would it know which window it’s supposed to be describing?

i am not familiar with these objects,nodes,classes,methods,attributes and instances…
i was used to programming with pointers and addresses.

i found another example of how confused i am:

base.cam.node().setLens(lenstype) works,
but
base.camera.node().setLens(lenstype)
base.cam.setLens(lenstype)
base.camera.setLens(lenstype)
don’t work.

where does .node() come from?
why shouldn’t it be
base.cam.setLens(lenstype) or base.camera.setLens(lenstype) ?
why make it so complicated ?
if .cam and .camera are at the same level in base, why do they have different properties, yet they are named so similar?

Aaah, I think that this is the core of the problem. Panda is, I believe, a strongly object-oriented engine, and using it without at least some knowledge of object-orientation is likely to be painful. In short, I strongly recommend at least taking a look at a decent tutorial on object-oriented programming.

As to the base.cam, etc. issue, I hesitate to attempt an explanation before you’ve looked into object-orientation, but in short (and presuming that I have this all correct myself), “setLens” is a method contained by a sub-class of the PandaNode class (which is one of the fundamental classes in Panda), called “LensNode”. On the other hand, “base.cam” is likely a NodePath (one of the other fundamental classes in Panda), which essentially acts as a handle for PandaNodes. The “node()” method in NodePath fetches its associated PandaNode, I believe. As to why there is that separation, I’m afraid that I don’t know, offhand.

As for that I would recommend you read the entire python tutorial i linked earlier, take a look at chapter 6.4 which introduces modules.
IMHO Learning python from O’Reilly is another example of a good python book for people that already know programming.

as for base.win if you do print base.win you get …GraphicsWindow object…
Which tells you that base.win is a GraphicsWindow which i believe is set in ShowBase.py since print base gives you …ShowBase instance… so win is a object(The default window) automatically provided by ShowBase to you
(Which i believe is not productive to learning BTW)

Do this:

import direct.directbase.DirectStart
from panda3d.core import WindowProperties
from panda3d.core import OrthographicLens
 
class MyApp():
 
    def __init__(self):
        lens = OrthographicLens()
        lens.setFilmSize(20, 15)
        
        print "What is base"
        print base
        print "What is base.cam"
        print base.cam
        print "What is base.cam.node"
        print base.cam.node
        print "What is base.cam.node()"
        print base.cam.node()
        print "What is base.cam.node().setLens"
        print base.cam.node().setLens
        print "What is base.cam.node().setLens(lens)"
        print base.cam.node().setLens(lens)
        print "What is base.cam.node() now?"
        print base.cam.node()
        
 
MyApp()
run()

From those results you should be able to figure out what happens and why, il give you the second one: base.cam tells you render is a parent of camera which is the parent of cam (Read scene graph manipulation for more info)

Thank you all.
my understanding will get better day by day as i do reading and trying.
:smiley: