sorry for my poor english
If I set the VListBox.SetSelection(0) before SplitVertically, all is right.
If I set the VListBox.SetSelection(1) after SplitVertically, all is right.
If I set the VListBox.SetSelection(0) after SplitVertically AND the VListBox is wrapped by a panel , all is right.
BUT if the VlistBox isn’t in a panel and I set the VListBox.SetSelection(0) after SplitVertically, it isn’t right
except I set VListBox.SetSelection(1) THEN VListBox.SetSelection(0)
see the code
two files:MyListBox.py,testVListBox.py
MyListBox.py
import wx
class MyListBox(wx.VListBox):
def SetListData(self,listdata):
self.listdata = listdata
def OnDrawItem(self, dc, rect, n):
''''''
if self.GetSelection() == n:
c = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT)
else:
c = self.GetForegroundColour()
#c = self.GetForegroundColour()
dc.SetFont(self.GetFont())
dc.SetTextForeground(c)
dc.DrawLabel(self._getItemText(n), rect,
wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
def OnMeasureItem(self, n):
height = 0
for line in self._getItemText(n).split('\n'):
w, h = self.GetTextExtent(line)
height += h
return height
def _getItemText(self, item):
return self.listdata[item]
#return 'item %d\nan extra line' %item
···
#######################################################################################
testVListBox.py
import wx
from MyListBox import *
class MyFrame(wx.Frame):
def init(self, parent, id, title):
wx.Frame.init(self, parent, id, “testVListBox”,(-1,-1),(500,300))
self.listdata = [str(i)10+’\n’+’’*20 for i in range(10)]
sp = wx.SplitterWindow(self,style=wx.SP_NOBORDER)
listBox1 = MyListBox(sp, -1,style=wx.LB_SINGLE,size=(120,100))
listBox1.SetListData(self.listdata)
listBox1.SetItemCount(10)
#listBox1.SetSelection(0)
listBox2 = MyListBox(sp, -1,style=wx.LB_SINGLE,size=(120,100))
listBox2.SetListData(self.listdata)
listBox2.SetItemCount(10)
listBox2.SetSelection(0)#listBox2 SetSelection before SplitVertically
sp.SplitVertically(listBox1,listBox2)
#listBox1 SetSelection after SplitVertically
#listBox1.SetSelection(1)
listBox1.SetSelection(0)
#listBox1.SetScrollPos(wx.VERTICAL,0,True)
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(parent=None, id=-1, title=‘Bare’)
frame.Show()
return True
if name == ‘main’:
app = MyApp(redirect=False)
app.MainLoop()