You need to log in to create posts and topics.

Feature request : mouse event in scripted component

Hi,

Mouse event handling would be a valuable feature. It would expand the capabilities of scripted components and make them interactive.

I've attempted a modification with the help of Claude AI.

The files he provided are attached.

I've also included an example. When you click on the component's surface, the events are displayed in the console.

Uploaded files:
arcachofo has reacted to this post.
arcachofo

That is indeed an interesting feature that requires very little code.

Indeed I would remove '''Mcu::toDisplayCoords( QPointF p )''' and just send component coordinates.
Then let the script calculate display coordinates if that is what he wants or use it for any other purpose.

I would also send button value directly as '''(int)event->button()''' keeping the values from Qt.

The only problem I can see is that the component might be not movable during simulation.
Maybe this should work only if '''m_scriptLink''' actually implements some of the mouse event functions.

Actually, I was thinking of this feature for scripted components with a `<display>` element.
Components without a `<display>` element have a box that's just a rectangular surface without any symbols that can be drawn on it (at least, I don't know how). So, the usefulness of mouse event is quite limited unless you want to create a giant button.

If a component has a `<display>` element, it would be nice if the mouse coordinates corresponded to the coordinates of the `<display>` element. This way, you can establish a relationship between what you draw and the returned position.

Moving components during a simulation isn't possible because the script has captured the events. But moving components during a simulation might not be a useful feature if the software is used in an educational context. In any case, I can't see any use cases for it. On the contrary, as someone who uses the software for my electronics courses, I sometimes find that students unintentionally move components and distort the setup I've meticulously prepared.

But yes, if we want to preserve the possibility of moving components during the simulation, we could, for example, check if a `<display>` element is present, or perhaps a function that allows us to lock/unlock the component depending on whether we want to capture mouse events or not.

There are some things you can do, for example use an image as background and create some kind of control panel or whatever.

I was also thinking about using scripts inside subcircuits as mouse interaction areas.
It is not possible right now but very easy to implement.
With that there are a lot of things you can do...

Moving while simulating is not a big deal, but differs from the expected behavior, so better do it only if needed.
In any case I can take care of that. 
Something similar happens with double-click, this is used to open properties widget.

As I understand,  maybe it would be useful to implement a way to "lock" components?

Another interesting feature to add when using mouse events would be the ability to replace an image on the component's casing in real time with a script. This way, you can create an animation with a series of images.

arcachofo has reacted to this post.
arcachofo