py2max 0.3.4__tar.gz → 0.3.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. {py2max-0.3.4 → py2max-0.3.5}/CHANGELOG.md +6 -0
  2. {py2max-0.3.4 → py2max-0.3.5}/PKG-INFO +1 -1
  3. {py2max-0.3.4 → py2max-0.3.5}/py2max/__init__.py +1 -1
  4. {py2max-0.3.4 → py2max-0.3.5}/py2max/core/patcher.py +11 -2
  5. {py2max-0.3.4 → py2max-0.3.5}/pyproject.toml +1 -1
  6. py2max-0.3.5/tests/test_patcher.py +96 -0
  7. py2max-0.3.4/tests/test_patcher.py +0 -47
  8. {py2max-0.3.4 → py2max-0.3.5}/LICENSE +0 -0
  9. {py2max-0.3.4 → py2max-0.3.5}/README.md +0 -0
  10. {py2max-0.3.4 → py2max-0.3.5}/py2max/__main__.py +0 -0
  11. {py2max-0.3.4 → py2max-0.3.5}/py2max/cli.py +0 -0
  12. {py2max-0.3.4 → py2max-0.3.5}/py2max/core/__init__.py +0 -0
  13. {py2max-0.3.4 → py2max-0.3.5}/py2max/core/abstract.py +0 -0
  14. {py2max-0.3.4 → py2max-0.3.5}/py2max/core/box.py +0 -0
  15. {py2max-0.3.4 → py2max-0.3.5}/py2max/core/colors.py +0 -0
  16. {py2max-0.3.4 → py2max-0.3.5}/py2max/core/common.py +0 -0
  17. {py2max-0.3.4 → py2max-0.3.5}/py2max/core/factory.py +0 -0
  18. {py2max-0.3.4 → py2max-0.3.5}/py2max/core/patchline.py +0 -0
  19. {py2max-0.3.4 → py2max-0.3.5}/py2max/core/serialization.py +0 -0
  20. {py2max-0.3.4 → py2max-0.3.5}/py2max/exceptions.py +0 -0
  21. {py2max-0.3.4 → py2max-0.3.5}/py2max/export/__init__.py +0 -0
  22. {py2max-0.3.4 → py2max-0.3.5}/py2max/export/converters.py +0 -0
  23. {py2max-0.3.4 → py2max-0.3.5}/py2max/export/svg.py +0 -0
  24. {py2max-0.3.4 → py2max-0.3.5}/py2max/layout/__init__.py +0 -0
  25. {py2max-0.3.4 → py2max-0.3.5}/py2max/layout/base.py +0 -0
  26. {py2max-0.3.4 → py2max-0.3.5}/py2max/layout/external.py +0 -0
  27. {py2max-0.3.4 → py2max-0.3.5}/py2max/layout/flow.py +0 -0
  28. {py2max-0.3.4 → py2max-0.3.5}/py2max/layout/graph.py +0 -0
  29. {py2max-0.3.4 → py2max-0.3.5}/py2max/layout/grid.py +0 -0
  30. {py2max-0.3.4 → py2max-0.3.5}/py2max/layout/matrix.py +0 -0
  31. {py2max-0.3.4 → py2max-0.3.5}/py2max/lint.py +0 -0
  32. {py2max-0.3.4 → py2max-0.3.5}/py2max/log.py +0 -0
  33. {py2max-0.3.4 → py2max-0.3.5}/py2max/m4l.py +0 -0
  34. {py2max-0.3.4 → py2max-0.3.5}/py2max/maxref/__init__.py +0 -0
  35. {py2max-0.3.4 → py2max-0.3.5}/py2max/maxref/category.py +0 -0
  36. {py2max-0.3.4 → py2max-0.3.5}/py2max/maxref/data/bundle.json.gz +0 -0
  37. {py2max-0.3.4 → py2max-0.3.5}/py2max/maxref/db.py +0 -0
  38. {py2max-0.3.4 → py2max-0.3.5}/py2max/maxref/legacy.py +0 -0
  39. {py2max-0.3.4 → py2max-0.3.5}/py2max/maxref/parser.py +0 -0
  40. {py2max-0.3.4 → py2max-0.3.5}/py2max/maxref/porttypes.py +0 -0
  41. {py2max-0.3.4 → py2max-0.3.5}/py2max/py.typed +0 -0
  42. {py2max-0.3.4 → py2max-0.3.5}/py2max/transformers.py +0 -0
  43. {py2max-0.3.4 → py2max-0.3.5}/py2max/utils.py +0 -0
  44. {py2max-0.3.4 → py2max-0.3.5}/tests/__init__.py +0 -0
  45. {py2max-0.3.4 → py2max-0.3.5}/tests/conftest.py +0 -0
  46. {py2max-0.3.4 → py2max-0.3.5}/tests/data/complex.maxpat +0 -0
  47. {py2max-0.3.4 → py2max-0.3.5}/tests/data/desc.maxpat +0 -0
  48. {py2max-0.3.4 → py2max-0.3.5}/tests/data/empty.maxpat +0 -0
  49. {py2max-0.3.4 → py2max-0.3.5}/tests/data/mydevice.amxd +0 -0
  50. {py2max-0.3.4 → py2max-0.3.5}/tests/data/mydevice2.amxd +0 -0
  51. {py2max-0.3.4 → py2max-0.3.5}/tests/data/nested.maxpat +0 -0
  52. {py2max-0.3.4 → py2max-0.3.5}/tests/data/simple.maxpat +0 -0
  53. {py2max-0.3.4 → py2max-0.3.5}/tests/data/tabular.maxpat +0 -0
  54. {py2max-0.3.4 → py2max-0.3.5}/tests/data/umenu.maxref.xml +0 -0
  55. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/README.md +0 -0
  56. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/advanced/connection_patterns.py +0 -0
  57. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/advanced/custom_extensions.py +0 -0
  58. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/advanced/data_containers.py +0 -0
  59. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/advanced/error_handling.py +0 -0
  60. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/advanced/performance_optimization.py +0 -0
  61. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/advanced/subpatchers.py +0 -0
  62. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/api/box_api_examples.py +0 -0
  63. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/api/patcher_api_examples.py +0 -0
  64. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/auto_layout_demo.py +0 -0
  65. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/db/category_db_demo.py +0 -0
  66. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/db/maxref_db_demo.py +0 -0
  67. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/layout/columnar_layout_examples.py +0 -0
  68. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/layout/flow_layout_examples.py +0 -0
  69. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/layout/grid_layout_examples.py +0 -0
  70. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/layout/matrix_layout_examples.py +0 -0
  71. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/preview/basic_synth.maxpat +0 -0
  72. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/preview/basic_synth.svg +0 -0
  73. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/preview/complex_synth.maxpat +0 -0
  74. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/preview/complex_synth.svg +0 -0
  75. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/preview/flow_layout.maxpat +0 -0
  76. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/preview/flow_layout.svg +0 -0
  77. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/preview/grid_layout.maxpat +0 -0
  78. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/preview/grid_layout.svg +0 -0
  79. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/preview/horizontal_layout.maxpat +0 -0
  80. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/preview/horizontal_layout.svg +0 -0
  81. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/preview/styled_no_ports.svg +0 -0
  82. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/preview/styled_no_title.svg +0 -0
  83. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/preview/styled_patch.maxpat +0 -0
  84. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/preview/styled_with_ports.svg +0 -0
  85. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/preview/svg_preview_demo.py +0 -0
  86. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/preview/vertical_layout.maxpat +0 -0
  87. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/preview/vertical_layout.svg +0 -0
  88. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/preview/workflow_demo.maxpat +0 -0
  89. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/preview/workflow_demo.svg +0 -0
  90. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/quickstart/basic_patch.py +0 -0
  91. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/quickstart/layout_examples.py +0 -0
  92. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/tutorial/generative_music.py +0 -0
  93. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/tutorial/interactive_controller.py +0 -0
  94. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/tutorial/signal_processing_chain.py +0 -0
  95. {py2max-0.3.4 → py2max-0.3.5}/tests/examples/tutorial/simple_synthesis.py +0 -0
  96. {py2max-0.3.4 → py2max-0.3.5}/tests/graphs/random/v30e33.tglf +0 -0
  97. {py2max-0.3.4 → py2max-0.3.5}/tests/test_abstract_coverage.py +0 -0
  98. {py2max-0.3.4 → py2max-0.3.5}/tests/test_abstraction.py +0 -0
  99. {py2max-0.3.4 → py2max-0.3.5}/tests/test_add.py +0 -0
  100. {py2max-0.3.4 → py2max-0.3.5}/tests/test_amxd.py +0 -0
  101. {py2max-0.3.4 → py2max-0.3.5}/tests/test_attrui.py +0 -0
  102. {py2max-0.3.4 → py2max-0.3.5}/tests/test_basic.py +0 -0
  103. {py2max-0.3.4 → py2max-0.3.5}/tests/test_beap.py +0 -0
  104. {py2max-0.3.4 → py2max-0.3.5}/tests/test_bpatcher.py +0 -0
  105. {py2max-0.3.4 → py2max-0.3.5}/tests/test_cli.py +0 -0
  106. {py2max-0.3.4 → py2max-0.3.5}/tests/test_coll.py +0 -0
  107. {py2max-0.3.4 → py2max-0.3.5}/tests/test_colors.py +0 -0
  108. {py2max-0.3.4 → py2max-0.3.5}/tests/test_colors_theme.py +0 -0
  109. {py2max-0.3.4 → py2max-0.3.5}/tests/test_comment.py +0 -0
  110. {py2max-0.3.4 → py2max-0.3.5}/tests/test_connection_validation.py +0 -0
  111. {py2max-0.3.4 → py2max-0.3.5}/tests/test_converters.py +0 -0
  112. {py2max-0.3.4 → py2max-0.3.5}/tests/test_core_coverage.py +0 -0
  113. {py2max-0.3.4 → py2max-0.3.5}/tests/test_db.py +0 -0
  114. {py2max-0.3.4 → py2max-0.3.5}/tests/test_defaults.py +0 -0
  115. {py2max-0.3.4 → py2max-0.3.5}/tests/test_dict.py +0 -0
  116. {py2max-0.3.4 → py2max-0.3.5}/tests/test_edit_operations.py +0 -0
  117. {py2max-0.3.4 → py2max-0.3.5}/tests/test_encapsulate.py +0 -0
  118. {py2max-0.3.4 → py2max-0.3.5}/tests/test_error_handling.py +0 -0
  119. {py2max-0.3.4 → py2max-0.3.5}/tests/test_examples.py +0 -0
  120. {py2max-0.3.4 → py2max-0.3.5}/tests/test_ezdac.py +0 -0
  121. {py2max-0.3.4 → py2max-0.3.5}/tests/test_gen.py +0 -0
  122. {py2max-0.3.4 → py2max-0.3.5}/tests/test_group.py +0 -0
  123. {py2max-0.3.4 → py2max-0.3.5}/tests/test_itable.py +0 -0
  124. {py2max-0.3.4 → py2max-0.3.5}/tests/test_js.py +0 -0
  125. {py2max-0.3.4 → py2max-0.3.5}/tests/test_kwds_filter.py +0 -0
  126. {py2max-0.3.4 → py2max-0.3.5}/tests/test_layout.py +0 -0
  127. {py2max-0.3.4 → py2max-0.3.5}/tests/test_layout_box_dims.py +0 -0
  128. {py2max-0.3.4 → py2max-0.3.5}/tests/test_layout_builtins.py +0 -0
  129. {py2max-0.3.4 → py2max-0.3.5}/tests/test_layout_coverage.py +0 -0
  130. {py2max-0.3.4 → py2max-0.3.5}/tests/test_layout_flow.py +0 -0
  131. {py2max-0.3.4 → py2max-0.3.5}/tests/test_layout_graph.py +0 -0
  132. {py2max-0.3.4 → py2max-0.3.5}/tests/test_layout_graph_layout.py +0 -0
  133. {py2max-0.3.4 → py2max-0.3.5}/tests/test_layout_graph_manager.py +0 -0
  134. {py2max-0.3.4 → py2max-0.3.5}/tests/test_layout_matrix.py +0 -0
  135. {py2max-0.3.4 → py2max-0.3.5}/tests/test_layout_overlaps.py +0 -0
  136. {py2max-0.3.4 → py2max-0.3.5}/tests/test_layout_vertical.py +0 -0
  137. {py2max-0.3.4 → py2max-0.3.5}/tests/test_linking.py +0 -0
  138. {py2max-0.3.4 → py2max-0.3.5}/tests/test_lint.py +0 -0
  139. {py2max-0.3.4 → py2max-0.3.5}/tests/test_m4l.py +0 -0
  140. {py2max-0.3.4 → py2max-0.3.5}/tests/test_maxref.py +0 -0
  141. {py2max-0.3.4 → py2max-0.3.5}/tests/test_maxref_bundle.py +0 -0
  142. {py2max-0.3.4 → py2max-0.3.5}/tests/test_maxref_lazy.py +0 -0
  143. {py2max-0.3.4 → py2max-0.3.5}/tests/test_maxref_parser.py +0 -0
  144. {py2max-0.3.4 → py2max-0.3.5}/tests/test_maxref_refpages.py +0 -0
  145. {py2max-0.3.4 → py2max-0.3.5}/tests/test_mc_cycle.py +0 -0
  146. {py2max-0.3.4 → py2max-0.3.5}/tests/test_mc_poly.py +0 -0
  147. {py2max-0.3.4 → py2max-0.3.5}/tests/test_message.py +0 -0
  148. {py2max-0.3.4 → py2max-0.3.5}/tests/test_mypatch.py +0 -0
  149. {py2max-0.3.4 → py2max-0.3.5}/tests/test_nested.py +0 -0
  150. {py2max-0.3.4 → py2max-0.3.5}/tests/test_nested_patchers.py +0 -0
  151. {py2max-0.3.4 → py2max-0.3.5}/tests/test_number_tilde.py +0 -0
  152. {py2max-0.3.4 → py2max-0.3.5}/tests/test_numbers.py +0 -0
  153. {py2max-0.3.4 → py2max-0.3.5}/tests/test_param.py +0 -0
  154. {py2max-0.3.4 → py2max-0.3.5}/tests/test_param_placement.py +0 -0
  155. {py2max-0.3.4 → py2max-0.3.5}/tests/test_pitched_osc.py +0 -0
  156. {py2max-0.3.4 → py2max-0.3.5}/tests/test_porttypes.py +0 -0
  157. {py2max-0.3.4 → py2max-0.3.5}/tests/test_presets.py +0 -0
  158. {py2max-0.3.4 → py2max-0.3.5}/tests/test_pydantic.py +0 -0
  159. {py2max-0.3.4 → py2max-0.3.5}/tests/test_rnbo.py +0 -0
  160. {py2max-0.3.4 → py2max-0.3.5}/tests/test_rnbo_subpatcher.py +0 -0
  161. {py2max-0.3.4 → py2max-0.3.5}/tests/test_scripting_name.py +0 -0
  162. {py2max-0.3.4 → py2max-0.3.5}/tests/test_search.py +0 -0
  163. {py2max-0.3.4 → py2max-0.3.5}/tests/test_semantic_ids.py +0 -0
  164. {py2max-0.3.4 → py2max-0.3.5}/tests/test_subpatch.py +0 -0
  165. {py2max-0.3.4 → py2max-0.3.5}/tests/test_svg.py +0 -0
  166. {py2max-0.3.4 → py2max-0.3.5}/tests/test_svg_fidelity.py +0 -0
  167. {py2max-0.3.4 → py2max-0.3.5}/tests/test_table.py +0 -0
  168. {py2max-0.3.4 → py2max-0.3.5}/tests/test_transformers.py +0 -0
  169. {py2max-0.3.4 → py2max-0.3.5}/tests/test_transformers_e4.py +0 -0
  170. {py2max-0.3.4 → py2max-0.3.5}/tests/test_tree.py +0 -0
  171. {py2max-0.3.4 → py2max-0.3.5}/tests/test_tree_builder.py +0 -0
  172. {py2max-0.3.4 → py2max-0.3.5}/tests/test_tutorial_simple_synthesis.py +0 -0
  173. {py2max-0.3.4 → py2max-0.3.5}/tests/test_two_sines.py +0 -0
  174. {py2max-0.3.4 → py2max-0.3.5}/tests/test_umenu.py +0 -0
  175. {py2max-0.3.4 → py2max-0.3.5}/tests/test_utils.py +0 -0
  176. {py2max-0.3.4 → py2max-0.3.5}/tests/test_validate_attrs.py +0 -0
  177. {py2max-0.3.4 → py2max-0.3.5}/tests/test_validation.py +0 -0
  178. {py2max-0.3.4 → py2max-0.3.5}/tests/test_varname.py +0 -0
  179. {py2max-0.3.4 → py2max-0.3.5}/tests/test_wheel_bundle.py +0 -0
  180. {py2max-0.3.4 → py2max-0.3.5}/tests/test_zl_group.py +0 -0
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.3.5]
6
+
7
+ ### Fixed: `Patcher.optimize_layout()` now reaches the incremental layout path
8
+
9
+ - `Patcher.optimize_layout()` gained an optional `changed_objects: Optional[Set[str]]` parameter and forwards it to the layout manager. It previously called the manager with no arguments, silently discarding any change set, so the incremental layout engine (`layout/base.py` `optimize_layout(changed_objects)` / `should_use_incremental` / `_incremental_layout`) was unreachable through the public API -- every call forced a full relayout. Passing a set of object IDs now lets managers that support it (grid, flow) reposition only those objects and their patchline neighbours; `None` (the default) preserves the previous full-relayout behaviour, so the change is backward compatible. Matrix/columnar managers still recompute in full (they ignore the argument by design). This is the core prerequisite for server-side auto-layout, which lives in `py2max-server`.
10
+
5
11
  ## [0.3.4]
6
12
 
7
13
  ### New: Param docking in layouts
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: py2max
3
- Version: 0.3.4
3
+ Version: 0.3.5
4
4
  Summary: A library for offline generation of Max/MSP patcher (.maxpat) files.
5
5
  Keywords: Max,maxpat,offline
6
6
  Author: Shakeeb Alireza
@@ -35,7 +35,7 @@ Example:
35
35
  >>> p.save()
36
36
  """
37
37
 
38
- __version__ = "0.3.4"
38
+ __version__ = "0.3.5"
39
39
 
40
40
  from .core import Box, Patcher, Patchline
41
41
  from .exceptions import (
@@ -23,6 +23,7 @@ from typing import (
23
23
  Iterator,
24
24
  List,
25
25
  Optional,
26
+ Set,
26
27
  Tuple,
27
28
  Union,
28
29
  cast,
@@ -656,7 +657,7 @@ class Patcher(BoxFactoryMixin, SerializationMixin, AbstractPatcher):
656
657
  return self._layout_mgr.get_pos(maxclass)
657
658
  return self._layout_mgr.get_pos()
658
659
 
659
- def optimize_layout(self) -> None:
660
+ def optimize_layout(self, changed_objects: Optional[Set[str]] = None) -> None:
660
661
  """Optimize object positions based on layout manager type.
661
662
 
662
663
  Calls the layout manager's optimization method to improve object
@@ -669,9 +670,17 @@ class Patcher(BoxFactoryMixin, SerializationMixin, AbstractPatcher):
669
670
 
670
671
  This method should be called after all objects and connections
671
672
  have been added to the patch.
673
+
674
+ Args:
675
+ changed_objects: Optional set of object IDs that have changed. When
676
+ provided and small relative to the total, managers that support
677
+ it reposition only those objects and their neighbours
678
+ (incremental layout) instead of recomputing the whole patch;
679
+ when ``None`` a full layout is performed. Managers that do not
680
+ implement incremental layout ignore the argument.
672
681
  """
673
682
  if hasattr(self._layout_mgr, "optimize_layout"):
674
- self._layout_mgr.optimize_layout()
683
+ self._layout_mgr.optimize_layout(changed_objects)
675
684
 
676
685
  # Dock value/UI params next to the object they drive (opt-in).
677
686
  if self._param_placement and hasattr(self._layout_mgr, "place_params"):
@@ -7,7 +7,7 @@ authors = [
7
7
  maintainers = [
8
8
  { name = "Shakeeb Alireza", email = "shakfu@users.noreply.github.com" }
9
9
  ]
10
- version = "0.3.4"
10
+ version = "0.3.5"
11
11
  readme = "README.md"
12
12
  requires-python = ">=3.9"
13
13
  keywords = ["Max", "maxpat", "offline"]
@@ -0,0 +1,96 @@
1
+ from pathlib import Path
2
+
3
+ from py2max import Patcher
4
+ import json
5
+
6
+ DATA_DIR = Path(__file__).parent / "data"
7
+
8
+
9
+ def test_patcher_basics():
10
+ p = Patcher("outputs/test_patcher_basics.maxpat", title="top notch patcher")
11
+ assert repr(p) == "Patcher(path='outputs/test_patcher_basics.maxpat')"
12
+ assert p._layout_mgr.parent.rect == p.rect
13
+ osc1 = p.add_textbox("cycle~")
14
+ osc2 = p.add_textbox("cycle~ 440")
15
+ assert osc1.id and osc2.id
16
+ assert repr(osc1) == f"Box(id='{osc1.id}', maxclass='newobj')"
17
+ assert osc1.oid == 1
18
+ line1 = p.add_patchline_by_index(osc1.id, osc2.id)
19
+ assert line1
20
+ assert repr(line1)
21
+ assert len(line1.to_tuple()) == 5
22
+ p.save()
23
+
24
+
25
+ def test_patcher_from_file():
26
+ p = Patcher.from_file(
27
+ DATA_DIR / "complex.maxpat", save_to="outputs/test_complex.maxpat"
28
+ )
29
+ assert len(p._boxes) == len(p.boxes) == 53
30
+ assert len(list(p)) == 60
31
+ assert p.to_json()
32
+ p.save()
33
+ p.save_as("outputs/test_complex2.maxpat")
34
+
35
+
36
+ def test_optimize_layout_forwards_changed_objects():
37
+ """Patcher.optimize_layout() must forward ``changed_objects`` to the layout
38
+ manager so the incremental path is reachable through the public API.
39
+
40
+ Regression: the facade previously called ``self._layout_mgr.optimize_layout()``
41
+ with no arguments, silently discarding the change set and always forcing a
42
+ full relayout.
43
+ """
44
+ p = Patcher("outputs/test_optimize_forwarding.maxpat", layout="grid")
45
+ a = p.add_textbox("cycle~ 440")
46
+ b = p.add_textbox("gain~")
47
+ p.add_line(a, b)
48
+
49
+ received: list = []
50
+ real = p._layout_mgr.optimize_layout
51
+
52
+ def spy(changed_objects=None):
53
+ received.append(changed_objects)
54
+ return real(changed_objects)
55
+
56
+ p._layout_mgr.optimize_layout = spy # type: ignore[method-assign]
57
+
58
+ p.optimize_layout() # full layout
59
+ p.optimize_layout({a.id}) # incremental request
60
+
61
+ assert received == [None, {a.id}]
62
+
63
+
64
+ def test_optimize_layout_incremental_leaves_untouched_objects_fixed():
65
+ """A small change set routes through incremental layout, which keeps
66
+ unaffected, unconnected objects at their existing positions."""
67
+ p = Patcher("outputs/test_optimize_incremental.maxpat", layout="grid")
68
+ # Two connected objects plus a pool of disconnected ones so the affected
69
+ # fraction (one object + its neighbour) stays under the incremental threshold.
70
+ a = p.add_textbox("cycle~ 440")
71
+ b = p.add_textbox("gain~")
72
+ p.add_line(a, b)
73
+ others = [p.add_textbox(f"print label{i}") for i in range(12)]
74
+
75
+ p.optimize_layout() # settle everything
76
+ before = {o.id: tuple(o.patching_rect) for o in others}
77
+
78
+ assert p._layout_mgr.should_use_incremental({a.id}) is True
79
+ p.optimize_layout({a.id})
80
+
81
+ after = {o.id: tuple(o.patching_rect) for o in others}
82
+ assert after == before
83
+
84
+
85
+ def test_patcher_from_file_comparison_complex():
86
+ pd = Patcher.from_file(DATA_DIR / "complex.maxpat").to_dict()
87
+ with open(DATA_DIR / "complex.maxpat") as f:
88
+ d = json.load(f)
89
+ assert pd == d
90
+
91
+
92
+ def test_patcher_from_file_comparison_simple():
93
+ pd = Patcher.from_file(DATA_DIR / "simple.maxpat").to_dict()
94
+ with open(DATA_DIR / "simple.maxpat") as f:
95
+ d = json.load(f)
96
+ assert pd == d
@@ -1,47 +0,0 @@
1
- from pathlib import Path
2
-
3
- from py2max import Patcher
4
- import json
5
-
6
- DATA_DIR = Path(__file__).parent / "data"
7
-
8
-
9
- def test_patcher_basics():
10
- p = Patcher("outputs/test_patcher_basics.maxpat", title="top notch patcher")
11
- assert repr(p) == "Patcher(path='outputs/test_patcher_basics.maxpat')"
12
- assert p._layout_mgr.parent.rect == p.rect
13
- osc1 = p.add_textbox("cycle~")
14
- osc2 = p.add_textbox("cycle~ 440")
15
- assert osc1.id and osc2.id
16
- assert repr(osc1) == f"Box(id='{osc1.id}', maxclass='newobj')"
17
- assert osc1.oid == 1
18
- line1 = p.add_patchline_by_index(osc1.id, osc2.id)
19
- assert line1
20
- assert repr(line1)
21
- assert len(line1.to_tuple()) == 5
22
- p.save()
23
-
24
-
25
- def test_patcher_from_file():
26
- p = Patcher.from_file(
27
- DATA_DIR / "complex.maxpat", save_to="outputs/test_complex.maxpat"
28
- )
29
- assert len(p._boxes) == len(p.boxes) == 53
30
- assert len(list(p)) == 60
31
- assert p.to_json()
32
- p.save()
33
- p.save_as("outputs/test_complex2.maxpat")
34
-
35
-
36
- def test_patcher_from_file_comparison_complex():
37
- pd = Patcher.from_file(DATA_DIR / "complex.maxpat").to_dict()
38
- with open(DATA_DIR / "complex.maxpat") as f:
39
- d = json.load(f)
40
- assert pd == d
41
-
42
-
43
- def test_patcher_from_file_comparison_simple():
44
- pd = Patcher.from_file(DATA_DIR / "simple.maxpat").to_dict()
45
- with open(DATA_DIR / "simple.maxpat") as f:
46
- d = json.load(f)
47
- assert pd == d
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes