Skip to content

add ComboListCell #68

@typemytype

Description

@typemytype
import AppKit

def ComboListCell(items, completes=True):    
    """
     An object that displays a combo box in a List column.

    **This object should only be used in the *columnDescriptions*
    argument during the construction of a List.**

    **items** The items that should appear in the combo box.
    
    **completes** Boolean representing if the combo box auto completes entered text.
    
    Example:
        
        from vanilla import *

        class ComboListCellDemo(object):

            def __init__(self):
                self.w = Window((200, 300), minSize=(100, 100))
                self.w.myList = List((0, 0, -0, -0),
                            [{"value": "a"}],
                            columnDescriptions=[
                                {
                                    "title": "value",
                                    "cell": ComboListCell(["a", "b", "c", "hello", "world"]),
                                },
                            ],
                            editCallback=self.editCallback)
                self.w.open()

            def editCallback(self, sender):
                print(sender.get())

        ComboListCellDemo()
    """
    cell = AppKit.NSComboBoxCell.alloc().init()
    cell.setButtonBordered_(False)
    cell.setBordered_(False)
    cell.setDrawsBackground_(False)
    cell.setEditable_(True)
    cell.setCompletes_(completes)
    cell.setControlSize_(AppKit.NSMiniControlSize)
    titles = []
    for title in items:
        if isinstance(title, (AppKit.NSString, AppKit.NSAttributedString)):
            title = title.string()
        titles.append(title)
    cell.addItemsWithObjectValues_(titles)
    return cell



from vanilla import *

class ComboListCellDemo(object):

    def __init__(self):
        self.w = Window((200, 300), minSize=(100, 100))
        self.w.myList = List((0, 0, -0, -0),
                    [{"value": "a"}],
                    columnDescriptions=[
                        {
                            "title": "value",
                            "cell": ComboListCell(["a", "b", "c", "hello", "world"]),
                        },
                    ],
                    editCallback=self.editCallback)
        self.w.open()

    def editCallback(self, sender):
        print(sender.get())

ComboListCellDemo()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions