Skip to content

Commit 66376fc

Browse files
committed
fix for comment positions / number_tilde
1 parent 0d9042d commit 66376fc

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
## 0.1.1
55

6+
- Added number_tilde test
7+
8+
- Fixed comment positioning
9+
610
- Added pyhola layout.
711

812
- Added graphviz layouts.

docs/auto-layouts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ The default is a very basic grid layout algo that's implemented in the current `
112112
![tsmpy1](assets/imgs/tsmp1.png)
113113

114114

115-
### Layout
115+
### OrthogonalDrawing Layout
116116

117117
![orthogonal](assets/imgs/orthogonal.png)
118118

py2max/core.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,26 @@ class LayoutManager:
4343
i.e. objects flow and wrap to the right.
4444
"""
4545

46+
4647
LAYOUT_DEFAULT_PAD = 1.5*32.0
48+
# LAYOUT_DEFAULT_PAD = 32.0
4749
LAYOUT_DEFAULT_BOX_WIDTH = 66.0
4850
LAYOUT_DEFAULT_BOX_HEIGHT = 22.0
51+
LAYOUT_DEFAULT_COMMENT_PAD = 2
4952

5053
def __init__(
5154
self,
5255
parent: "Patcher",
5356
pad: int = None,
5457
box_width: int = None,
5558
box_height: int = None,
59+
comment_pad: int = None,
5660
):
5761
self.parent = parent
5862
self.pad = pad or self.LAYOUT_DEFAULT_PAD
5963
self.box_width = box_width or self.LAYOUT_DEFAULT_BOX_WIDTH
6064
self.box_height = box_height or self.LAYOUT_DEFAULT_BOX_HEIGHT
65+
self.comment_pad = comment_pad or self.LAYOUT_DEFAULT_COMMENT_PAD
6166
self.x_layout_counter = 0
6267
self.y_layout_counter = 0
6368
self.prior_rect = None
@@ -163,17 +168,20 @@ def above(self, rect):
163168
def below(self, rect):
164169
"""Return a position below the object"""
165170
x, y, w, h = rect
166-
return [x, y + (self.box_height + h), w, h]
171+
# return [x, y + (self.box_height + h + self.comment_pad), w, h]
172+
return [x, y + (self.box_height + self.comment_pad), w, h]
167173

168174
def left(self, rect):
169175
"""Return a position left of the object"""
170176
x, y, w, h = rect
171-
return [x - self.box_width, y, w, h]
177+
return [x - (self.box_width - self.comment_pad), y, w, h]
172178

173179
def right(self, rect):
174180
"""Return a position right of the object"""
175181
x, y, w, h = rect
176-
return [x + (self.box_width + w), y, w, h]
182+
# return [x + (self.box_width + w), y, w, h]
183+
# return [x + (self.box_width - self.pad + w), y, w, h]
184+
return [x + (self.box_width + self.comment_pad), y, w, h]
177185

178186

179187
class VerticalLayoutManager(LayoutManager):
@@ -464,9 +472,9 @@ def add_textbox(
464472
_maxclass, *tail = text.split()
465473
if _maxclass in MAXCLASS_DEFAULTS and not maxclass:
466474
maxclass = _maxclass
467-
_defaults = MAXCLASS_DEFAULTS[_maxclass]
468-
if "patching_rect" in _defaults and not patching_rect:
469-
patching_rect = _defaults["patching_rect"]
475+
# _defaults = MAXCLASS_DEFAULTS[_maxclass]
476+
# if "patching_rect" in _defaults and not patching_rect:
477+
# patching_rect = _defaults["patching_rect"]
470478

471479
if self.classnamespace == "rnbo":
472480
kwds["rnbo_classname"] = _maxclass

py2max/tests/test_number_tilde.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from .. import Patcher
2+
3+
POSITIONS = ["above", "right", "below", "left"]
4+
5+
6+
def test_number_tilde():
7+
p = Patcher('outputs/test_number_tilde.maxpat')
8+
for pos in POSITIONS:
9+
p.add_textbox("number~", mode=1, comment=f"mode1-{pos}", comment_pos=pos)
10+
for pos in POSITIONS:
11+
p.add_textbox("number~", mode=2, comment=f"mode2-{pos}", comment_pos=pos)
12+
p.save()
13+
14+
15+
if __name__ == '__main__':
16+
test_number_tilde()

py2max/tests/test_numbers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_add_floatbox():
1616
p.save()
1717

1818

19-
def test_add_floatbox():
19+
def test_add_intbox():
2020
p = Patcher('outputs/test_intbox.maxpat')
2121

2222
d = {}

0 commit comments

Comments
 (0)