7.0.0 Mocha Pro 2020 Python Guide - Example don't work

  1. I Trying to use the “Example Tool: Spot Cleaner” code, from “Mocha 5.6.0 Python Scripting Guide”
    Unfortunately it isn’t work at all.

  2. Also the implements a handler on the mouse move event , like “AbstractTool.on_mouse_move (event)”

In the "7.0.0 Mocha Pro 2020 Python Guide " said that i can use this function:

def on_mouse_move(self, event):
      #grab the mouse position on the canvas
      cur_pos = event.pos_on_canvas
      print cur_pos.x(), cur_pos.y() 

To detect mouse events inside the Abstract tool class.
But it isn’t work too.
I have no idea why so.

  1. Is there some way to get information about which control points are currently selected? How can I get this data using the API?

What version of Mocha are you using?

MochaPro 2020.5

Flagging this for @martinb as he maintains the Python guide and will be best placed to answer this.

1 Like

Looking at the code example you’ve shown in the post, it looks like you don’t have a Python 3 print statement in brackets.

It should be like this:

def on_mouse_move(self, event):
	#grab the mouse position on the canvas
    cur_pos = event.pos_on_canvas
    print(cur_pos.x(), cur_pos.y())

In the spot cleaner example shown in the guide, the spot tool appears on the “basic” toolbar, not the advanced toolbar. This may be where the confusion lies.
If you switch to “essentials” layout you should see the tool when you run the code from the script editor.

If you want to get the tool on the Advanced toolbar in the classic layout, you can replace:

tools_bar = find_widget('ToolsBar', QToolBar)

with:

tools_bar = find_widget('AdvancedToolsBar', QToolBar)

It isn`t appear not in this case

tools_bar = find_widget(‘AdvancedToolsBar’, QToolBar)
and not in this
tools_bar = find_widget(‘AdvancedToolsBar’, QToolBar)
Not in any of the toolbars

it appear only if i add the var in the end like :

test = SpotCleaner(None)

or

test = SpotCleaner(get_current_project)

But in this case, when i click it. it not work any way.
Check it please.

about “on_mouse_move” I already check with the brackets.
same result

def on_mouse_move(self, event):
      #grab the mouse position on the canvas
      cur_pos = event.pos_on_canvas
      print(cur_pos.x(), cur_pos.y())

And what about control points selection data. How can I get it ?

Once registered, the tools need to be initialised. You can do this either via loading the tool via init.py or by running the script to register it, then load a project.
Loading or reloading a project session should refresh the toolbar, but we recommend adding these tools to your init.py file so they initialise on launch.

If you’re in the v7.0.0 guide, there are sections on accessing the control point data. See the section under “Shape Contours” in the guide: Boris FX | Mocha® 2020 Python Scripting Guide

1 Like

I already check “Shape Contours” in the guide.
But the BezierControlPointData have no attribute or property about is it selected or not. Is there any other options to get selected points?

For selected points, that’s different. As far as I am aware, you can only get the point currently under the mouse cursor, via InputEvent: 4.3. InputEvent — mocha 7.5.1 documentation

We should look at expanding the API to ask for selected points, as currently we can only ask for selected layers:
https://borisfx.com/support/documentation/mocha/7.5.1/python-reference/mocha/project/layer?highlight=selected#mocha.project.Layer.selected

1 Like