Page MenuHome

WM Event Simulation Support
AbandonedPublic

Authored by Campbell Barton (campbellbarton) on Jan 30 2019, 11:19 PM.

Details

Summary

This adds the ability for Python to send events into the event queue (using RNA).

This is intended for writing interaction tests, which I've started doing for the undo system.

Basics:

  • --enable-event-simulate enables events to be added via Window.event_simulate
  • When G_DEBUG_EVENTS_SIMULATE is enabled, user keyboard and mouse events are ignored.

    Useful so tests can be run without stray mouse events interfering.

    This also keeps the feature *testing-only*, not something for developers to use for nasty hacks.
  • bpy.app.debug_events_simulate can only be disabled, never enabled.

    Useful for checking the result of running a test.
  • This patch includes some test scripts, they're not for review, just examples of how it can be used.

    They need to be updated to validate the output is correct. Currently I'm just using them for bugs that crash Blender.

Open Topics:

  • We could add events at different levels, eg: generate ghost events instead.

    It would have some advantages since lower level events could be generated but it would be a bigger patch to interface Python w/ ghost, don't think it's worth the extra hassle.
  • Using keyboard/mouse events to test things isn't perfect because they break when shortcuts change. We could consider alternatives. OTOH, the tests end up being short making them quicker to update. There is also an advantage in being able to translate user steps into something that can be automated, w/o having to lookup API docs.
  • We may eventually want to access other UI elements too, but would only consider this later on.

Diff Detail

Repository
rBS Blender Staging
Branch
temp-wm-event-api
Build Status
Buildable 2823
Build 2823: arc lint + arc unit

Event Timeline

Campbell Barton (campbellbarton) retitled this revision from Experimental event playback, use for testing events to WM Event Simulation Support.Jan 30 2019, 11:32 PM
Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)
Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)

Yield more specific types (be less vague)

Fix accessing freed event in Python

Error when event arguments that don't make sense are passed in.

Update texture painting test for T60954

Rename command line arg '--debug-events-simulate' to '--enable-event-simulate'

Seems generally fine, just some minor comments.

source/blender/makesrna/intern/rna_wm_api.c
537

I suggest to initialize wmEvent e = win->eventstate; and then fill in the other fields.

That's what the WM code does as well so it's maybe a bit more future proof in case extra fields get added.

tests/python/event_simulate/modules/easy_keys.py
1

Maybe name this simulator.py instead of easy_keys.py?

88

ty -> event_type would be more clear

Campbell Barton (campbellbarton) marked 2 inline comments as done.
Campbell Barton (campbellbarton) added inline comments.
source/blender/makesrna/intern/rna_wm_api.c
537
tests/python/event_simulate/modules/easy_keys.py
1

It's still called easy_keys, but it's just part of the tests in SVN, dont have strong opinion, it's just helper module, not something more general for the moment.

Could rename event_simulator_helper.py