2

I'm using the enaml toolkit and would like to know how to initialize Splitter / SplitItem layouts.

Below is some very simple sample code. I'd like the window to start with the left SplitItem taking about 2/3 of the window width with the right SplitItem getting the other third. I've tried a variety of constraints in a variety of places but can't seem to hit on what I need to do.

Window starts like this: equal width split items

I want it to start like this: left split item wider

from enaml.widgets.api import (
    Window, Container, Splitter, SplitItem, Html
    )

enamldef Left(Container):
    Html:
        source = '<center><h1>Hello Left!</h1></center>'

enamldef Right(Container):
    Html:
        source = '<center><h1>Hello Right!</h1></center>'

enamldef Main(Window):
    initial_size = (800,400)
    Container:

        Splitter:

            SplitItem:
                Left:lt:
                    pass

            SplitItem:
                Right:rt:
                    pass
tillsten
  • 14,491
  • 5
  • 32
  • 41
JefferyRPrice
  • 895
  • 5
  • 17

1 Answers1

3

Use the stretch attribute on each SplitItem. The initial widths will be proportional to the fraction of total stretch values. So for the left one, use stretch = 3 and the right one stretch = 1. This will allocate 3/4 of the space to the left side and 1/4 of the space to the right side. The stretch values must be integers, not floating point values since this is what the underlying toolkits are expecting.

Robert Kern
  • 13,118
  • 3
  • 35
  • 32
  • That was it. Thanks, Robert! Also, I'd like to suggest that someone with more reputation than me create a new `enaml` tag. It sure would've been nice to see that property in the [docs](http://docs.enthought.com/enaml/api_ref/widgets/enaml.widgets.split_item.SplitItem.html#enaml.widgets.split_item.SplitItem). – JefferyRPrice Mar 15 '13 at 00:39
  • @JefferyRPrice: I added the enaml tag. – Warren Weckesser Mar 15 '13 at 18:50