~callum/barszcz

a9fc9817213d1bea55ced97269c50e41d13d56ed — Callum Brown 1 year, 10 months ago 8249b14
Make gap a property of Things, add gap sizes

In preparation for viewing more detail and wanting a smaller gap
between each attribute.
2 files changed, 28 insertions(+), 8 deletions(-)

M README.md
M beetsplug/barszcz.py
M README.md => README.md +7 -2
@@ 81,7 81,10 @@ and if `left` or `right` is left blank, nothing will be displayed on that side.

- `format_album` is as above but for albums.

- `gap` is the number of blank lines between each item or album.
- `gap` has sub-options `regular` and `small`.
`regular` is used for the number of blank lines between each item or album.
`small` is used for the number of blank lines between attributes when viewing
more detail about an item or album.

### Shortcuts



@@ 119,7 122,9 @@ barszcz:
			- $albumartist ($year)
		right:
			- $albumtotal tracks
	gap: 1
	gap:
		regular: 1
		small: 0
	shortcuts:
		KEY_UP: up {}
		k: up {}

M beetsplug/barszcz.py => beetsplug/barszcz.py +21 -6
@@ 33,7 33,10 @@ config["barszcz"].add(
            "left": ["$album", "$albumartist ($year)"],
            "right": ["$albumtotal tracks"],
        },
        "gap": 1,
        "gap": {
            "regular": 1,
            "small": 0,
        },
        "shortcuts": {
            "KEY_UP": "up {}",
            "k": "up {}",


@@ 56,6 59,18 @@ def shorten(text, width):
    return text[:(width-2)].strip() + ".."


def gap_lines(size):
    """Get the number of lines a gap of `size` should be.

    Arguments:
        size: string, key in the `gap` section of the configuration.
    """
    if size in config["barszcz"]["gap"]:
        return abs(config["barszcz"]["gap"][size].get(int))
    else:
        return 0


class InputLine(Textbox):
    """Modification of the curses.textpad.Textbox widget.



@@ 140,6 155,9 @@ class Thing:
    The proportion is used to shorten the text when the width is narrow
    (see `format_info()`).
    """
    # The number of blank lines that should be added after the Thing
    # in order to delineate Things and improve readability.
    gap = gap_lines("regular")

    def format_info(self, width, indent):
        """Format info to be displayed so it fits in width columns.


@@ 245,9 263,6 @@ class AlbumThing(LibModelThing):


class Group:
    # The number of blank lines between each Thing
    gap = abs(config["barszcz"]["gap"].get(int))

    def __init__(self, things, miny, minx, maxy, maxx):
        """Makes a group pad from a list of Things.



@@ 265,7 280,7 @@ class Group:
        # Number of lines the group pad should be
        self.h = 0
        for thing in self.things:
            self.h += thing.height + self.gap
            self.h += thing.height + thing.gap
        # Minimum is the available height
        if self.h < self.lines_visible:
            self.h = self.lines_visible


@@ 298,7 313,7 @@ class Group:
            thing_pad.addstr(0, 0, str(i), attr)
            self.thing_pads.append(thing_pad)
            # Leave blank lines between things
            start_line += thing.height + self.gap
            start_line += thing.height + thing.gap

    def refresh(self):
        self.pad.refresh(self.y, self.x, self.miny, self.minx, self.maxy, self.maxx)