expanding layout in traits UI editor

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

expanding layout in traits UI editor

Andrew Straw
Hi,

I'm attempting to create my own wx-based traits.ui editor, and I'm
running into trouble getting a wx panel that fills the remaining space
without gobbling the entire containing panel. In the attached example
as-is, I would like the green panel to expand to fill the remaining
space in the wx.Frame. Currently, however, it fills only about 1 lines
of text's worth of height. If I uncomment the "resizable=True" line, the
green panel extends down off the bottom of the Frame, meaning that
value2 is not seen.

How do I get the green panel to expand to fill the available space
without extending off the bottom? It would be ideal if it also covered
the red of its parent panel.

Thanks,
Andrew

import enthought.traits.api as traits
import wx
from enthought.traits.ui.api import View, Item, Group
from enthought.traits.ui.wx.editor import Editor
from enthought.traits.ui.basic_editor_factory import BasicEditorFactory

class _RedEditor ( Editor ):
    def init ( self, parent ):
        id = -1
        pos=wx.DefaultPosition
        size=wx.DefaultSize
        style=wx.CLIP_CHILDREN
        parent_sizer = parent.GetSizer()
        self.control = panel = wx.Panel( parent, id )#, pos, size, style )
        panel.SetBackgroundColour( wx.Color( 0, 255, 0) ) # green
        parent.SetBackgroundColour( wx.Color( 255, 0, 0) ) # red
        parent_sizer.Add( panel, 1, wx.EXPAND )
        parent.Layout()

    def update_editor ( self ):
        pass

class RedEditor ( BasicEditorFactory ):
    klass = _RedEditor

class Red(traits.HasTraits):
    value = traits.Int
    traits_view = View(Group(Item('value',
                                  #resizable=True,  # <-------- uncomment to be too big
                                  show_label=False,
                                  editor=RedEditor())))

class Container(traits.HasTraits):
    value1 = traits.Int
    red = traits.Instance( Red )
    value2 = traits.Int
    traits_view = View(Group(Item('value1'),
                             Item('red',
                                  style='custom'),
                             Item('value2')))

if __name__=='__main__':
    app = wx.PySimpleApp()
    frame = wx.Frame(None, wx.ID_ANY)

    c = Container(value1=123,
                  red=Red(),
                  value2=456)
    panel = c.edit_traits(parent=frame, kind='subpanel').control

    frame.Show()
    app.MainLoop()

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev