robotools / vanilla

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

vanilla.Tabs bug when vanilla.List2 used with textField inside #188

Open HugoJourdan opened 1 year ago

HugoJourdan commented 1 year ago

Python : 3.11.2 Vanilla : 0.3.1.dev10+g8303f24 pyobj : 9.0.1

With the following code :

import vanilla
from vanilla import*

class TEST:

    def __init__(self):
        self.w = Window((500,300))
        items = []
        for file in ["ABC Light", "ABC Regular", "ABC Bold"]:
            d = dict(
                checkBox=True,
                textField=file,
                )

            items.append(d)

        columnDescriptions = [

            dict(
                identifier="checkBox",
                width=20,
                cellClass=vanilla.CheckBoxList2Cell,
                editable=True,
            ),
            dict(
                identifier="textField",
                width=300,
                editable=False
            ),

        ]
        self.w.list = vanilla.List2((10,10,200,200),
            items=items,
            columnDescriptions=columnDescriptions,
            showColumnTitles=False,
        )
        self.w.tab = Tabs((230, 10, 200, 100), ["Tab One", "Tab Two"])
        self.w.open()

if __name__ == "__main__":
    from vanilla.test.testTools import executeVanillaTest
    executeVanillaTest(TEST)

This is what I got when it's run from Terminal : Screenshot 2023-07-05 at 10 27 08

And from DrawBot :

Screenshot 2023-07-05 at 10 27 21

Note that if I remove the textField column, it works as expected when run from the terminal. I presume that is maybe again a problem with pyobj ?

typemytype commented 1 year ago

super strange how the List2 object influences the tab view. Looks like the tab view does not receive a move to window notification when a List2 object is around

typesupply commented 11 months ago

Even more strange. The tab positions are only messed up if items are given to the list:

import vanilla

class Test:

    def __init__(self):
        self.w = vanilla.Window((500, 300))
        self.w.list = vanilla.List2((10, 10, 200, 200), [])
        self.w.tab = vanilla.Tabs((230, 10, 200, 100), ["One", "Two"])
        self.w.open()

Test()
image
import vanilla

class Test:

    def __init__(self):
        self.w = vanilla.Window((500, 300))
        self.w.list = vanilla.List2((10, 10, 200, 200), ["a", "b", "c"])
        self.w.tab = vanilla.Tabs((230, 10, 200, 100), ["One", "Two"])
        self.w.open()

Test()
image
typesupply commented 11 months ago

I've tracked this down to the EditTextList2Cell being a subclass of Group. As soon as the group has a subview added to it, things go haywire. I ave no idea why a view (the subview) inside of a view (the group) inside of another view (the table) inside of another view (the scroll view) would affect a view outside of that hierarchy.

typesupply commented 11 months ago

Here's the test for when I try to fix this in the future:

import vanilla
import objc
objc.setVerbose(True)

class Test:

    def __init__(self):
        self.w = vanilla.Window((500, 300))
        self.w.list = vanilla.List2(
            (10, 10, 200, 200),
            [
                dict(value=50, text="A")
            ],
            columnDescriptions=[
                # dict(
                #     identifier="value",
                #     cellClass=vanilla.SliderList2Cell
                # ),
                dict(
                    identifier="text",
                    cellClass=vanilla.EditTextList2Cell
                ),
            ]
        )
        self.w.tab = vanilla.Tabs((230, 10, 200, 100), ["One", "Two"])
        self.w.open()

from vanilla.test.testTools import executeVanillaTest
executeVanillaTest(Test)