Hi,
I am working on a registration program for my daughters ballet school
and I have chosen TreeListCtrl as the main widget.
After reading that there is a new implementation of this control in the
upcoming
version of wxPython I though I will give a daily build a whirl and see what
happens.
1) I have noticed that in previous version the whole row was highlighted by
default.
The new version highlights only the tree part of the list.
Then I have read that wx.TR_NO_LINES|wx.TR_FULL_ROW_HIGHLIGHT brings this
behavior back.
2) I am changing background color of certain rows but this does not seem to
work in the new
version. Is it a bug or am I missing some flag somewhere?
3) HitTest does not return proper id. From my observations if I right click
on a label the id
of the item above is returned and not the one clicked.
Additionally, in the demo right click does not bring the menu up at all.
Comments?
Test program demonstrating the behavior follows.
Waldemar
···
##########################################################################
#!/usr/bin/env python
# generated by wxGlade 0.3.3 on Thu Jun 24 21:22:47 2004
import wx
from wx import gizmos
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.tree = gizmos.TreeListCtrl(self, -1)
self.__set_properties()
self.__do_layout()
self.SetSize((450, 300))
# end wxGlade
self.tree.AddColumn("")
[self.tree.AddColumn("") for idx in range(4)]
self.tree.SetMainColumn(0)
self.tree.SetColumnWidth(0, 100)
for idx in range(1,5):
self.tree.SetColumnWidth(idx, 75)
self.tree.SetColumnAlignment(idx, wx.LIST_FORMAT_RIGHT)
self.tree.GetMainWindow().Bind(wx.EVT_RIGHT_DOWN,
self.OnRightClickTree)
self.OnShowTree(None)
def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle("Test TreeListCtrl")
# end wxGlade
def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_1.Add(self.tree, 1, wx.EXPAND, 0)
self.SetAutoLayout(1)
self.SetSizer(sizer_1)
sizer_1.Fit(self)
sizer_1.SetSizeHints(self)
self.Layout()
# end wxGlade
def OnShowTree(self, evt):
root = self.tree.AddRoot("Family Name")
cols = ("Class Fee","Prod.Fee","Costume","Total")
for idx, col in enumerate(cols):
self.tree.SetItemText(root, col, idx+1)
self.tree.SetItemBold(root)
self.tree.SetItemBackgroundColour(root, wx.CYAN)
for kid in ("Kid1", "Kid2"):
branch = self.tree.AppendItem(root, kid)
for cl in ("Class1", "Class2"):
leaf = self.tree.AppendItem(branch, cl)
self.tree.SetItemText(leaf, "38", 1)
self.tree.SetItemText(leaf, "5", 2)
self.tree.SetItemText(leaf, "5", 3)
self.tree.SetItemText(leaf, "48", 4)
# add transactions list
branch = self.tree.AppendItem(root, 'Transactions')
cols = ("Type","Amount")
for idx, col in enumerate(cols):
self.tree.SetItemText(branch, col, idx+1)
self.tree.SetItemBold(branch)
self.tree.SetItemBackgroundColour(branch, wx.GREEN)
for dt, ttype, amt in
(("12/12/03","PMT","55.00"),("12/28/03","PMT","45.00")):
leaf = self.tree.AppendItem(branch, dt)
self.tree.SetItemText(leaf, ttype, 1)
self.tree.SetItemText(leaf, amt, 2)
# expand the first level
self.tree.Expand(root)
def OnRightClickTree(self, evt):
pos = evt.GetPosition()
idx, flags, col = self.tree.HitTest(pos)
if idx:
lbl = self.tree.GetItemText(idx)
menu = wx.Menu()
menu.SetTitle(lbl)
# depending on lbl name show different commands
if lbl=="Family Name":
mid = menu.Append(wx.NewId(), 'Add Member')
self.Bind(wx.EVT_MENU, self.OnAddMember, mid)
elif lbl.startswith("Kid"):
mid = menu.Append(wx.NewId(), 'Add Class')
self.Bind(wx.EVT_MENU, self.OnAddClass, mid)
elif lbl=="Transactions":
mid = menu.Append(wx.NewId(), 'Add Transaction')
self.Bind(wx.EVT_MENU, self.OnAddPayment, mid)
else:
menu.Destroy()
return
# postion menu just right
x, y = self.tree.ClientToScreen(pos)
mx, my = self.GetPosition()
self.PopupMenu(menu, (x-mx, y-my))
menu.Destroy()
def NotImplemented(self, evt):
dlg = wx.MessageDialog(self, 'Not Implemented',
'Info', wx.OK|wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
OnAddMember = OnEditMember = OnAddPayment = OnAddClass = NotImplemented
# end of class MyFrame
class MyApp(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
frmMain = MyFrame(None, -1, "")
self.SetTopWindow(frmMain)
frmMain.Show(1)
return 1
# end of class MyApp
if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.710 / Virus Database: 466 - Release Date: 6/23/2004