Tracking GUI activity

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
KAKM
Posts: 112
Joined: Tue May 04, 2021 12:17 am

Tracking GUI activity

Post by KAKM »

I'm working on being able to record/create a tutorial in FreeCAD that you can play back (initial discussion at https://forum.freecad.org/viewtopic.php?t=60635) and it will highlight (or otherwise draw attention to) the part of the GUI relevant for a given step in the tutorial, which means that I need to be able to tell what happens in the GUI–was a button clicked? a face selected? an endpoint created?

It looks like there isn't a singular tool to be able to track things like that-QActions/signals cover things like the toolbar buttons pretty well, but don't appear to cover things that happen in the tree or in the 3D model view. I know I can pick up selections with getSelected(), but I have no idea how to get something like where the user put endpoints with the Sketcher polyline tool. Does Coin have something similar to a QAction/signal? Should I be looking into document observers? Transactions? Something else? Any general suggestions?

If anyone knows a good way to find the GUI elements associated with a Python command (as recorded in macros), I'm open to that as a possibility too. Or something wildly different that I haven't even considered–I'm only just starting on the GUI interaction part of this, so there's no need to worry about compatibility with existing code.

Katy
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Tracking GUI activity

Post by openBrain »

Hi,

You can use DocumentObserver (object creation, deletion, change) + SelectionObserver (object, face selection) + ViewObserver (mouse clicks).
You can get an overview of them running this example code : https://github.com/0penBrain/FreeCAD-ma ... og.FCMacro
wmayer
Founder
Posts: 20298
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Tracking GUI activity

Post by wmayer »

A low-level method is to implement a Qt event filter class and install it to the QApplication. This way you receive all events the applications gets from the OS and the object that should handle it. In the event filter you then should focus on mouse and keyboard events.

Qt also offers a test module that might be helpful for this: https://doc.qt.io/qt-5/qttest-module.html

But I don't know how easy it is to create a macro that can be executed on any other computer. I don't think it will be that simple.
Post Reply