Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update QtTesting translator to record python #1081

Open
jcfr opened this issue Apr 12, 2023 · 4 comments
Open

Update QtTesting translator to record python #1081

jcfr opened this issue Apr 12, 2023 · 4 comments

Comments

@jcfr
Copy link
Member

jcfr commented Apr 12, 2023

Once we are done with Qt4 removal, we should evaluate if the overall of maintaining QtTesting player/translator for both CTK & Slicer is worth it.

We are looking into refreshing/improving QtTesting for recording tutorials that can be replayed in different languages (because we cannot use English language screenshots in non-English tutorials). We would like to generate executable Python code instead of XML. Maybe we'll use the recorder (just fix and extend it as needed) and convert the XML to Python; or maybe we'll change it more significantly to create Python code directly.

Originally posted by @lassoan in #1080 (comment)

@jcfr
Copy link
Member Author

jcfr commented Apr 12, 2023

QtTesting and python

All of that said, we could look into generating python code similar to what is done in Paraview (see here ). The code would be similar to the one posted below:

import QtTesting
import QtTestingImage
object1 = 'MainWindow/menubar/menuFile'
QtTesting.playCommand(object1, 'activate', 'actionFileLoadServerState')
object2 = 'MainWindow/ServerStartupBrowser/connect'
QtTesting.playCommand(object2, 'activate', )
object3 = 'MainWindow/FileLoadServerStateDialog'
QtTesting.playCommand(object3, 'filesSelected', '$PARAVIEW_DATA_ROOT/Data/LoadStateMultiView.pvsm')
snapshotWidget = 'MainWindow/1pqRenderWindowManager0/SplitterFrame/MultiViewSplitter/0/Viewport'
QtTestingImage.compareImage(snapshotWidget, 'LoadStateMultiView.png', 200, 200);

Originally posted by @jcfr in https://discourse.slicer.org/t/macro-xml-to-python/15803/2

@jcfr
Copy link
Member Author

jcfr commented Apr 12, 2023

Recording GUI events (button clicks, etc.) has very limited use (only for testing, and even there it is quite fragile). Meaningful workflow automation Python scripts should operate at lower level, by changing properties of MRML nodes and calling module logic functions.

I’ve recently implemented a simple Python script that observes all MRML node changes and generate a list of node property modifications (by comparing MRML node PrintSelf results before and after the node modification). This can be used to generate a runnable, user-editable Python script. This is similar to what Paraview can do. However, this turned out not to be very useful, because it is too low level (for a single user action you get a bunch of node property modification events, but you don’t know why the node ended up being modified like that).

What we would really need is an intermediate level, where a user action is translated to a few high-level method calls. I’m not sure what is the easiest way to achieve this. Maybe we could add a specially formatted log message whenever a logic method is called (and macro recording is enabled), and these could be easily converted to runnable Python code.

Originally posted by @lassoan in https://discourse.slicer.org/t/macro-xml-to-python/15803/3

@jcfr
Copy link
Member Author

jcfr commented Apr 12, 2023

implemented a simple Python script that observes all MRML node changes and generate a list of node property modifications

See https://github.com/PerkLab/SlicerSandbox/blob/master/SceneRecorder/SceneRecorder.py

@lassoan
Copy link
Member

lassoan commented Apr 12, 2023

Recording&replaying GUI events is bad for batch processing (fragile and may require too many low-level steps) but for tutorials it is actually an appropriate level. Ideally, the user could choose the API level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants