[solved]Is there any Mouse Moving Event?

Thanks for reading my question!

I put some DirectGui objects on the screen, and I want to lay them in order. There is an option, [color=indigo]direct-gui-edit, allowing user to use middle mouse to manipulate gui objects. I set that item to true, and want to get each gui object’s exact position after each moving operation. So I write something as following(part of my code):

        self._startPage_Background = DirectLabel(image= '111',
                                       image_scale = (1.3, 0.95, 0.95),
                                       image_pos = (0, 0, 0)) 
        
        # Mouse Moving Adjusting DirectGui Position
        # Event Handlers.
        self.accept('mouse2', self.LeftMouseDown )
        self.accept('mouse2-move', self.LeftMouseMoving )
        self.accept('mouse2-up', self.LeftMouseUp )
    
    def LeftMouseDown(self):
        self._leftMouse_Flag = 1  # 1 for down, 0 
        print 'Left Mouse Down'
        
    def LeftMouseMoving(self):
        if self._leftMouse_Flag == 1 :
            print 'Left Mouse Moving'
            
        
    def LeftMouseUp(self):
        self._leftMouse_Flag = 0
        print 'Left Mouse Up'
        print self._startPage_Background.getPos() # Get new position.

But there’s no event like [color=indigo]mouse-moving. What can I do if I want to get the new position of the gui object after I use mouse moving it.
Thanks!

Just run a task and sample the position every frame, whether it moved or not.

David

Hi, thanks drwr.
I add a task which will print the position of the Gui object every frame. But some strange error comes out. My code:

# Load Panda3D libraries
import direct.directbase.DirectStart
from direct.gui.DirectGui import *
from direct.showbase import DirectObject
from direct.task import Task
from pandac.PandaModules import *

class ManipulateDirectGui(DirectObject.DirectObject):
    def __init__(self):
        base.setBackgroundColor(1, 1, 1)
        self._startPage_Background = DirectLabel(image= 'Texture/StartPageImage.jpg', scale = (1.3, 0.95, 0.95), pos = (0, 0, 0)) 
        taskMgr.add(getGuiPos, 'getGuiPos')
        
def getGuiPos(task):
    global myGui
    print myGui._startPage_Background.getPos()
    
myGui = ManipulateDirectGui()

run()

This is the error I get:

I have no idea what’s wrong :open_mouth: . Similar code goes well in another program!
Actually, the reason I want to get the Gui object position is that I’d like to lay all the DirectGuis in a particular order. I don’t know exactly what float point numbers should be in the [color=red]setPos() function. Is there any way I can put those objects as I like?

Thanks a lot!

You messed up your image tag. Here’s a link for the interested:

thumbq.com/store/55807-error_1.gif

The error looks simple, “tex” is not initialized and so None is being sent as the parameter to self.setTexture(). Make sure that the texture is being loaded correctly and the correct variable is being used.

Thanks, Arkaein.
You see my code. I 've not set any texture to any object. So how does this error come out? The code I include above is the whole file.

BTW: [color=darkred]DirectLabel cannot show images which have transparency correctly, right? If I want to show image with transparency, do I have to use [color=darkred]OnscreenImage? What if I have such an image for my [color=darkred]DirectButton object?

Problem is, the image is not found. Because, if the image is not found, it returns None, which is not an image.

Try setTransparencyAttrib (see the manual on OnscreenImage, i think it should work the same for directbutton)

:unamused: Thanks everyone! I already solve the ‘texture’ problem. 8) Unfortunately, a new problem comes out. I run a task to print the position of my DirectGui object every frame. However, what I get is not what I expected. In the prompt, it prints only one value, the original position of that object, and nothing else. That means Panda3D does not call the task every frame. I cannot find the place where I make the mistake. So I’ll copy my code, then someone can help me!
Thanks a lot!

from pandac.PandaModules import ConfigVariableBool 
myGuiEdit = ConfigVariableBool("direct-gui-edit") 
myGuiEdit.setValue(1)

# Load Panda3D libraries
import direct.directbase.DirectStart
from direct.gui.DirectGui import *
from direct.showbase import DirectObject
from direct.task import Task
from pandac.PandaModules import *

class ManipulateDirectGui(DirectObject.DirectObject):
    def __init__(self):
        base.setBackgroundColor(1, 1, 1)
        self._startPage_Background = DirectLabel(image = 'Texture/StartPageImage.jpg',
                                       scale = (1.3, 0.95, 0.95),
                                       pos = (0, 0, 0)) 
        taskMgr.add(getGuiPos, 'getGuiPos')
        
def getGuiPos(task):
    global myGui
    print myGui._startPage_Background.getPos()
    
myGui = ManipulateDirectGui()

run()

I’m not sure because I usually define my functions before they’re called in Python scripts, but I think the problem might be in adding the task function before defining it. Try either moving the function before the class, or making it a member of the ManipulateDirectGui class.

You might try printing the task function object immediately before calling addTask, this will tell you if it’s defined.

Thanks Arkaein! I tried to either move the function before the definition of the class or make it a member of the class. It doesn’t work. In some other programs of mine, this problem also exists. The function which is added to the taskManager is not called every frame. How does that happen? :confused: :question:

You must return Task.cont from the task function to indicate you want the task to continue.

David

David, thank you so much!
I thought the default return value is Task.cont. !!!
After I add the return statement to that function, YES, it works!