v0.84.1: automatic buttons ending the second toolbar row line up under the buttons ending the first
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
"""LinTunes — iTunes-style music library manager and player for Linux."""
|
"""LinTunes — iTunes-style music library manager and player for Linux."""
|
||||||
|
|
||||||
__version__ = "0.84.0"
|
__version__ = "0.84.1"
|
||||||
|
|||||||
@@ -113,6 +113,48 @@ def shown_ids(rows) -> set[str]:
|
|||||||
return {e["id"] for row in rows for e in row}
|
return {e["id"] for row in rows for e in row}
|
||||||
|
|
||||||
|
|
||||||
|
def _fills(entry) -> bool:
|
||||||
|
size, base = entry.get("size", "auto"), base_id(entry["id"])
|
||||||
|
return size == "fill" or (size == "auto" and (base in AUTO_FILL or base == "seek"))
|
||||||
|
|
||||||
|
|
||||||
|
def column_partners(rows) -> dict[str, str]:
|
||||||
|
"""{row-1 item: row-0 item} it sits exactly under. ``ANCHORED_UNDER``
|
||||||
|
first; then the buttons ending row 1 pair off, right to left, with the
|
||||||
|
buttons ending row 0, so a theme box over a speakers box lines up like
|
||||||
|
DJ over bpm. Only "auto" buttons in row 1 join (an exact width is the
|
||||||
|
user's call); a spacer or anything that fills ends either run."""
|
||||||
|
top, bottom = rows
|
||||||
|
shown = {e["id"] for e in top}
|
||||||
|
partners = {e["id"]: ANCHORED_UNDER[base_id(e["id"])] for e in bottom
|
||||||
|
if base_id(e["id"]) in ANCHORED_UNDER
|
||||||
|
and e.get("size", "auto") == "auto"
|
||||||
|
and ANCHORED_UNDER[base_id(e["id"])] in shown}
|
||||||
|
|
||||||
|
def run(row, ok):
|
||||||
|
out = []
|
||||||
|
for entry in reversed(row):
|
||||||
|
if base_id(entry["id"]) in SPACERS or _fills(entry) or not ok(entry):
|
||||||
|
break
|
||||||
|
out.append(entry["id"])
|
||||||
|
return out
|
||||||
|
|
||||||
|
below = run(bottom, lambda e: e.get("size", "auto") == "auto"
|
||||||
|
and base_id(e["id"]) not in ("library", "view"))
|
||||||
|
above = run(top, lambda e: True)
|
||||||
|
for low, high in zip(below, above):
|
||||||
|
partners[low] = high
|
||||||
|
# The pairs must keep row 0's order, or the anchors would cross.
|
||||||
|
order = {e["id"]: i for i, e in enumerate(top)}
|
||||||
|
last, kept = -1, {}
|
||||||
|
for entry in bottom:
|
||||||
|
high = partners.get(entry["id"])
|
||||||
|
if high is not None and order[high] > last and high not in kept.values():
|
||||||
|
kept[entry["id"]] = high
|
||||||
|
last = order[high]
|
||||||
|
return kept
|
||||||
|
|
||||||
|
|
||||||
def palette_ids(rows) -> list[str]:
|
def palette_ids(rows) -> list[str]:
|
||||||
"""What the palette offers: everything not shown, and always both
|
"""What the palette offers: everything not shown, and always both
|
||||||
spacers (dragging one in makes a new instance)."""
|
spacers (dragging one in makes a new instance)."""
|
||||||
|
|||||||
@@ -874,6 +874,7 @@ class TransportBar(QWidget):
|
|||||||
"""The layout engine's slots for ``row``. Row 1's automatic items
|
"""The layout engine's slots for ``row``. Row 1's automatic items
|
||||||
follow what they belong under: the sidebar, the view, row 0."""
|
follow what they belong under: the sidebar, the view, row 0."""
|
||||||
split = self._split()
|
split = self._split()
|
||||||
|
partners = toolbar.column_partners(self._rows)
|
||||||
slots = []
|
slots = []
|
||||||
for entry in self._rows[row]:
|
for entry in self._rows[row]:
|
||||||
item, size = entry["id"], entry.get("size", "auto")
|
item, size = entry["id"], entry.get("size", "auto")
|
||||||
@@ -885,7 +886,7 @@ class TransportBar(QWidget):
|
|||||||
if size == "fill":
|
if size == "fill":
|
||||||
slots.append(Slot(item, fill=True, min_width=least))
|
slots.append(Slot(item, fill=True, min_width=least))
|
||||||
continue
|
continue
|
||||||
above = self._rects[0].get(toolbar.ANCHORED_UNDER.get(base, ""))
|
above = self._rects[0].get(partners.get(item, ""))
|
||||||
if row == 1 and base == "library" and split is not None:
|
if row == 1 and base == "library" and split is not None:
|
||||||
slots.append(Slot(item, anchor=(split[0], split[1]), min_width=least))
|
slots.append(Slot(item, anchor=(split[0], split[1]), min_width=least))
|
||||||
elif row == 1 and above is not None:
|
elif row == 1 and above is not None:
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
"""Round 117: automatic buttons ending the second row line up, column by
|
||||||
|
column, under the buttons ending the first."""
|
||||||
|
from lintunes.gui import toolbar
|
||||||
|
from tests.test_round101 import _bar
|
||||||
|
|
||||||
|
|
||||||
|
def _rows(top, bottom):
|
||||||
|
return [[e if isinstance(e, dict) else {"id": e, "size": "auto"} for e in top],
|
||||||
|
[e if isinstance(e, dict) else {"id": e, "size": "auto"} for e in bottom]]
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_default_pairs_are_unchanged():
|
||||||
|
assert toolbar.column_partners(toolbar.default_config()) == {
|
||||||
|
"seek": "now_playing", "bpm": "dj"}
|
||||||
|
|
||||||
|
|
||||||
|
def test_trailing_buttons_pair_right_to_left():
|
||||||
|
rows = _rows(["transport", "now_playing", "theme", "dj"],
|
||||||
|
["library", "view", "seek", "speakers", "bpm"])
|
||||||
|
assert toolbar.column_partners(rows) == {
|
||||||
|
"seek": "now_playing", "speakers": "theme", "bpm": "dj"}
|
||||||
|
|
||||||
|
|
||||||
|
def test_exact_widths_and_spacers_end_the_run():
|
||||||
|
rows = _rows(["now_playing", "theme", "dj"],
|
||||||
|
["library", "view", "seek",
|
||||||
|
{"id": "speakers", "size": "exact", "width": 60}, "bpm"])
|
||||||
|
assert toolbar.column_partners(rows) == {"seek": "now_playing", "bpm": "dj"}
|
||||||
|
rows = _rows(["now_playing", "theme", "space:1", "dj"],
|
||||||
|
["library", "view", "seek", "speakers", "bpm"])
|
||||||
|
assert toolbar.column_partners(rows) == {"seek": "now_playing", "bpm": "dj"}
|
||||||
|
|
||||||
|
|
||||||
|
def test_pairs_never_cross():
|
||||||
|
# positionally speakers would sit under dj and bpm under theme; bpm's
|
||||||
|
# own partner (dj) wins and speakers, which would cross it, stays free
|
||||||
|
rows = _rows(["now_playing", "theme", "dj"],
|
||||||
|
["library", "view", "seek", "bpm", "speakers"])
|
||||||
|
partners = toolbar.column_partners(rows)
|
||||||
|
assert partners["seek"] == "now_playing"
|
||||||
|
assert list(partners.values()) == sorted(
|
||||||
|
partners.values(), key=["now_playing", "theme", "dj"].index)
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_window_lines_them_up(qapp, tmp_path):
|
||||||
|
rows = _rows(["transport", "volume", "now_playing", "theme", "dj"],
|
||||||
|
["library", "view", "seek", "speakers", "bpm"])
|
||||||
|
bar, _prefs = _bar(tmp_path, rows)
|
||||||
|
top, bottom = bar._rects[0], bar._rects[1]
|
||||||
|
for low, high in (("speakers", "theme"), ("bpm", "dj"), ("seek", "now_playing")):
|
||||||
|
assert bottom[low].left() == top[high].left(), low
|
||||||
|
assert bottom[low].right() == top[high].right(), low
|
||||||
Reference in New Issue
Block a user