robotools / vanilla

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

Widgets inside GridView (sometimes) don't show up #201

Closed simoncozens closed 11 months ago

simoncozens commented 11 months ago

This code:

from PyObjCTools import AppHelper

import vanilla

w = vanilla.Window((200,200))
w.textEditor = vanilla.TextEditor((0,0,100,20), "Standalone")
w.gridView = vanilla.GridView(
            (0,30, 200, 200),
            [{"cells": [
                vanilla.TextBox((0,0,-0,-0), "Widget1"),
                vanilla.TextEditor((0,0,100,20), "Widget2"),
                vanilla.TextBox((0,0,-0,-0), "Widget3"),
             ]}],
        )
w.show()

AppHelper.runEventLoop()

gives a window like so:

Screenshot 2023-12-21 at 12 42 00

Put them inside a group and all is well:

w = vanilla.Window((300, 300))
w.textEditor = vanilla.TextEditor((0,0,100,20), "Standalone")
g = vanilla.Group("auto")
g.widget1 = vanilla.TextBox((0,0,-0,-0), "Widget1")
g.widget2 = vanilla.TextEditor((0,0,100,20), "Widget2")
g.widget3 = vanilla.TextBox((0,0,100,20), "Widget3")
w.gridView = vanilla.GridView(
    (0,30, 200, 200),
    [{"cells": [g.widget1, g.widget2, g.widget3]}],
)

w.open()
Screenshot 2023-12-21 at 12 59 00
simoncozens commented 11 months ago

(In the version of Vanilla in Glyphs.app, the "put them in a group" trick doesn't work either.)

typemytype commented 11 months ago

see the example in the vanilla documentation: https://vanilla.robotools.dev/en/latest/objects/GridView.html#module-vanilla

The "trick" is to keep a reference of the vanilla object.