Commit 1bdefa1
authored
Let the user add event handlers to an opmode, for events defined in the robot (#175)
* In common_storage.ts, save the events declared in the module.
In mrc_event_handler.ts:
Refactored hardcoded fields names into constants FIELD_SENDER and FIELD_EVENT_NAME.
Added otherBlockId to EventHandlerExtraState and mrcOtherBlockId to EventHandlerMixin.
Added onLoad method that updates event handler blocks if the event definition has been changed.
Added functions addRobotEventHandlerBlocks and createRobotEventHandlerBlock to create blocks for the toolbox.
In editor.ts, added method getEventsFromRobot.
In hardware_category.ts, added function getRobotEventsBlocks and call it in getHardwareCategory when the current module is an opmode.
* In extended_python_generator.ts:
Added fields hasHardware and hasEventHandler. Set these in mrcWorkspaceToCode before calling super.workspaceToCode.
Renamed method defineClassVariables to generateInitStatements. Renamed local variable variableDefinitions to initStatements.
Removed setHasHardware and addHardwarePort.
In mrc_components.ts, added methods getNewPort and getHardwarePorts. getHardwarePorts collects the hardware ports and is called by extended_python_generator before we start generating python for blocks. (Previous code called addHardwarePort when the mrc_component blocks was generating python, but that is too late.)
In mrc_event_handler.ts, added function getHasEventHandler. This is used to determine whether the generated __init__ method needs to call register_events.
In generator_context.ts, removed hasHardware, clear(), setHasHardware(), and getHasHardware().
In mrc_call_python_function.ts, use forEach loops where possible. Use BLOCK_NAME instead of 'mrc_call_python_function'.
Moved code that iterates through mrc_mechanism_component_holder blocks from editor.ts
to mrc_mechanism_component_holder.ts functions getComponents and getEvents.
In mrc_mechanism_component_holder.ts added function getHardwarePorts to collect ports needed for define_hardware.
Moved code that iterates through mrc_class_method_def blocks from editor.ts
to mrc_class_method_def.ts functions getMethodsForWithin, getMethodsForOutside,
and getMethodNamesAlreadyOverriddenInWorkspace.
In robot_base.py, added register_event and unregister_event methods.
In methods_category.ts, don't show blocks for robot methods register_event and unregister_event.
* Fixed typescript errors.
* In robot_base.py:
Rename register_event and unregister_event to register_event_handler and unregister_event_handler.
Allow multiple handlers to be registered for an event.
Add fire_event function.
Changed python code for firing an event to call fire_event.
When determining whether a workspace has hardware or events, check whether blocks are enabled.1 parent ee53dd8 commit 1bdefa1
File tree
17 files changed
+573
-202
lines changed- server_python_scripts/blocks_base_classes
- src
- blocks
- utils/generated
- editor
- storage
- toolbox
17 files changed
+573
-202
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
6 | 29 | | |
7 | 30 | | |
8 | 31 | | |
| 32 | + | |
9 | 33 | | |
10 | 34 | | |
11 | 35 | | |
| 36 | + | |
12 | 37 | | |
13 | 38 | | |
14 | 39 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
588 | 588 | | |
589 | 589 | | |
590 | 590 | | |
| 591 | + | |
| 592 | + | |
591 | 593 | | |
592 | 594 | | |
593 | 595 | | |
| |||
637 | 639 | | |
638 | 640 | | |
639 | 641 | | |
640 | | - | |
641 | | - | |
642 | | - | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
643 | 645 | | |
644 | 646 | | |
645 | 647 | | |
| |||
671 | 673 | | |
672 | 674 | | |
673 | 675 | | |
674 | | - | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
675 | 684 | | |
676 | 685 | | |
677 | 686 | | |
| |||
699 | 708 | | |
700 | 709 | | |
701 | 710 | | |
702 | | - | |
| 711 | + | |
703 | 712 | | |
704 | 713 | | |
705 | 714 | | |
706 | 715 | | |
707 | 716 | | |
708 | | - | |
| 717 | + | |
709 | 718 | | |
710 | | - | |
| 719 | + | |
711 | 720 | | |
712 | 721 | | |
713 | 722 | | |
714 | 723 | | |
715 | 724 | | |
716 | 725 | | |
717 | | - | |
| 726 | + | |
718 | 727 | | |
719 | 728 | | |
720 | 729 | | |
| |||
738 | 747 | | |
739 | 748 | | |
740 | 749 | | |
741 | | - | |
| 750 | + | |
742 | 751 | | |
743 | 752 | | |
744 | 753 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
347 | 347 | | |
348 | 348 | | |
349 | 349 | | |
350 | | - | |
| 350 | + | |
351 | 351 | | |
352 | 352 | | |
353 | 353 | | |
| |||
409 | 409 | | |
410 | 410 | | |
411 | 411 | | |
412 | | - | |
| 412 | + | |
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
| |||
510 | 510 | | |
511 | 511 | | |
512 | 512 | | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
149 | 166 | | |
150 | 167 | | |
151 | 168 | | |
| |||
171 | 188 | | |
172 | 189 | | |
173 | 190 | | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
| 191 | + | |
181 | 192 | | |
182 | 193 | | |
183 | 194 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
233 | | - | |
234 | | - | |
| 233 | + | |
| 234 | + | |
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
| |||
0 commit comments