[wxPython] tree control on a panel

I can't seem to get a tree control to show up on a panel in a frame.
This is on winNT with Python 1.5.2 in case that matters. The following
example illustrates:

···

===================

from wxPython.wx import *

def Filltree(parental):
  # creates tree with contents
  tree = wxTreeCtrl(parental, NewId(), wxDefaultPosition,
wxDefaultSize, wxTR_HAS_BUTTONS)
  root = tree.AddRoot('The Root Item')

  for x in range(15):
    child = tree.AppendItem(root, "Item %d" % x)
    for y in range(5):
      last = tree.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)))
      for z in range(5):
        item = tree.AppendItem(last, "item %d-%s-%d" % (x,
chr(ord("a")+y), z))
  tree.Expand(root)

class MyFrame2(wxFrame):
  # tree in a frame -- works fine
  def __init__(self, parent, ID, title):
    wxFrame.__init__(self, parent, ID, title, wxDefaultPosition,
(300,300))
    Filltree(self)

class MyFrame3(wxFrame):
  # tree in a panel in a frame -- huh?
  def __init__(self, parent, ID, title):
    wxFrame.__init__(self, parent, ID, title, wxDefaultPosition,
(300,300))
    panel = wxPanel(self, -1, wxDefaultPosition, wxDefaultSize,
wxSUNKEN_BORDER)
    Filltree(panel)

class MyApp(wxApp):
  def OnInit(self):
    # try one or the other of these:
    # frame = MyFrame2(NULL, -1, 'hi')
    # frame = MyFrame3(NULL, -1, 'hi')
    frame.Show(true)
    self.SetTopWindow(frame)
    return true

app = MyApp(0)
app.MainLoop()

-----
robin
robin.escalation@acm.org
'the ideal copy makes me happy'

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

On my system (Win2K, Python 2.0, wxPython 2.2.2), your example shows a small (maybe 50x50) tree control when it is placed on a grid. Setting the size of the tree control explicitly to (300,300), instead of wxDefaultSize, makes it take up the whole panel. You might want to try explicitly setting the size just to ensure that nothing is showing up.

-greg

···

At 02:06 PM 2/6/2001, Robin Parmar wrote:

I can't seem to get a tree control to show up on a panel in a frame.
This is on winNT with Python 1.5.2 in case that matters. The following
example illustrates:

----
greg Landrum (greglandrum@earthlink.net)
Software Carpenter/Computational Chemist

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

I can't seem to get a tree control to show up on a panel in a frame.
This is on winNT with Python 1.5.2 in case that matters. The following
example illustrates:

[...]

tree = wxTreeCtrl(parental, NewId(), wxDefaultPosition,
wxDefaultSize, wxTR_HAS_BUTTONS)

You don't set the size or position anywhere. It's probably there, but very
small. See the demo for plenty of examples of doing layout of windows and
controls. You can use explicit positions and sizes or use layout
constraints or sizers to do it automatically.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

I can't seem to get a tree control to show up on a panel in a frame.
This is on winNT with Python 1.5.2 in case that matters. The following
example illustrates:

Try manually resizing panel and tree in OnSize event - will work as
expected.

def Filltree(parental):
...
  return tree

class MyFrame3(wxFrame):
  # tree in a panel in a frame -- huh?
  def __init__(self, parent, ID, title):
    wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, (300,300))
    self.panel = wxPanel(self, -1, wxDefaultPosition, wxDefaultSize,
wxSUNKEN_BORDER)
    self.tree = Filltree(self.panel)
    EVT_SIZE(self, self.OnSize)

  def OnSize(self, event):
    w,h = self.GetClientSizeTuple()
    self.panel.SetDimensions(0, 0, w, h)
    self.tree.SetDimensions(0, 0, w, h)

mak

···

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users