robotools / vanilla

A Pythonic wrapper around Cocoa.
MIT License
78 stars 28 forks source link

List2.EditTextList2Cell needs an alignment kwarg. #161

Closed typesupply closed 10 months ago

typesupply commented 2 years ago

This should have the same alignment options as TextBox. In the meantime, here's a workaround for @LettError:

import AppKit
import vanilla

class RightAlignEditTextList2Cell(vanilla.EditTextList2Cell):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.editText.getNSTextField().setAlignment_(AppKit.NSTextAlignmentRight)

class Test:

    def __init__(self):
        items = [
            dict(left="A", right="A"),
            dict(left="BB", right="BB"),
            dict(left="CCC", right="CCC"),
        ]
        columnDescriptions = [
            dict(
                identifier="left",
                width=75
            ),
            dict(
                identifier="right",
                width=75,
                cellClass=RightAlignEditTextList2Cell
            )
        ]

        self.w = vanilla.Window((200, 200))
        self.w.l = vanilla.List2(
            (10, 10, -10, -10),
            items,
            columnDescriptions=columnDescriptions
        )
        self.w.open()

Test()