Dragging not working

Discussion about using Python with libRocket.

Dragging not working

Postby rcdailey on Thu Feb 28, 2008 8:51 pm

I wrote up a quick little python script to move my object with the cursor on the screen. While the object won't move correctly given the code I have so far, it should at least *move*. I stopped where I am right now because I'm not seeing any movement from my element. I print out the cursor coordinates to the screen and I do verify that I'm getting valid coordinates, however when I modify my elements "left" and "top" attributes it does not move. Here's the python code:

Code: Select all
def OnDrag( event ):
   if event.type == "drag":
      target = event.parameters['drag_element']

      mx = event.parameters['mouse_x']
      my = event.parameters['mouse_y']
      print str(mx), str(my)
      target.SetAttribute( "left", str( mx ) )
      target.SetAttribute( "top", str( my ) )

And the RML:

Code: Select all
      <link type="text/rcss" href="default.rcss"/>
            width: 100%;
            height: 100%;

            background-color: #f00;

            position: absolute;
            display: block;

            width: 64px;
            height: 64px;

            button-decorator: image;
            button-image-src: skillbutton_full.png;

            drag: drag-drop;
            z-index: top;

import MainMenuEventHandler as Handler


Any reason why setting the 'top' and 'left' attributes has no effect?
Posts: 113
Joined: Mon Feb 04, 2008 8:04 pm

Re: Dragging not working

Postby lloydw on Thu Feb 28, 2008 10:08 pm

SetAttribute is the same as setting an attribute in a XML tag which doesn't work for style information. What you want to do is alter the style property, which would be done as follows

Code: Select all
target.style.left = str( mx )
target.style.top = str( my )

Hope that helps :)
Rocket Engineer
Rocket Engineer
Posts: 380
Joined: Tue Jan 15, 2008 10:56 pm

Re: Dragging not working

Postby manuel on Wed Mar 07, 2012 4:51 pm


it seems event.parameters['drag_element'] is always None/NoneType. looking at the code there is a cast from element* to void* to make the variant class happy but there's no python converter back. just the fallback to Py_None. What's the best way to fix that?
Posts: 2
Joined: Wed Mar 07, 2012 2:58 pm

Re: Dragging not working

Postby lloydw on Tue Mar 20, 2012 10:39 pm


It probably shouldn't be storing it as a void*, but rather a script interface. That way the normal python conversion out of a variant should work.

Let me know if that fixes it.
Rocket Engineer
Rocket Engineer
Posts: 380
Joined: Tue Jan 15, 2008 10:56 pm

Re: Dragging not working

Postby kaiyara on Sat Jun 15, 2013 7:48 am

Thanks for reporting the incorrect documentation. Indeed, event.parameters['parameter_name'] is the way to access event parameters. The original implementation used direct attributes on the event object, unfortunately the API Reference must have missed when the documentation was updated.

pimsleur http://www.pimsleur.me/
ileatherworld http://www.ileatherworld.com/
test-kings http://www.test-kings.com
braindumps http://braindumps.net
Posts: 1
Joined: Sat Jun 15, 2013 7:44 am

Return to libRocket and Python