I'm using wxFormBuilder to create a wxPython app. The application then
loads the widgets from an XRC file.
I cannot get wxFormBuilder to add bitmap icons to a listbook. For
whatever reason, it refuses to write the file paths out to the XRC
file. So I decided to try to add the icons to the listbook pages after
the XRC was already loaded. Here is the code I used:
imageList = wx.ImageList(84, 40, True, 3)
for i in xrange(v.m_GraphsListBox.GetPageCount()):
fn = 'Resources/Images/button' + str(i+1) + '.bmp'
image = wx.Bitmap(fn, wx.BITMAP_TYPE_BMP)
imageList.Add(image)
v.m_GraphsListBox.SetImageList(imageList)
for i in xrange(v.m_GraphsListBox.GetPageCount()):
v.m_GraphsListBox.SetPageImage(i, i)
v is a reference to the view. The icon files do exist. m_GraphsListBox
is a wx.ListBook. This code is called after the XRC file is loaded.
When I try to open the page containing the ListBook, m_GraphsListBox,
the application crashes with no good information in the log.
Am I handling this properly? What could cause a crash in this code?
Thanks,
Alan
Here's a report from the OS; it shows that there was a seg fault in
wxListLineData::CalculateSize(wxDC*, int).
I did get it run once; the icons were not there, though, and the
listbook header (at the top) was about 10 pixels high with a scrollbar
underneath.
Mostly, it just crashes.
Date/Time: 2009-09-21 21:08:26.516 -0500
OS Version: Mac OS X 10.5.6 (9G55)
Report Version: 6
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000061727473
Crashed Thread: 0
Thread 0 Crashed:
0 ??? 0x61727473 0 + 1634890867
1 libwx_macud-2.8.0.dylib 0x015eb8bd
wxListLineData::CalculateSize(wxDC*, int) + 531
2 libwx_macud-2.8.0.dylib 0x015f3cea
wxListMainWindow::RecalculatePositions(bool) + 1476
3 libwx_macud-2.8.0.dylib 0x015f41e9
wxGenericListCtrl::OnInternalIdle() + 49
4 libwx_macud-2.8.0.dylib 0x01616402 wxAppBase::SendIdleEvents
(wxWindow*, wxIdleEvent&) + 22
5 libwx_macud-2.8.0.dylib 0x0161643c wxAppBase::SendIdleEvents
(wxWindow*, wxIdleEvent&) + 80
6 libwx_macud-2.8.0.dylib 0x0161643c wxAppBase::SendIdleEvents
(wxWindow*, wxIdleEvent&) + 80
7 libwx_macud-2.8.0.dylib 0x0161643c wxAppBase::SendIdleEvents
(wxWindow*, wxIdleEvent&) + 80
8 libwx_macud-2.8.0.dylib 0x0161643c wxAppBase::SendIdleEvents
(wxWindow*, wxIdleEvent&) + 80
9 libwx_macud-2.8.0.dylib 0x0161643c wxAppBase::SendIdleEvents
(wxWindow*, wxIdleEvent&) + 80
10 libwx_macud-2.8.0.dylib 0x0161643c wxAppBase::SendIdleEvents
(wxWindow*, wxIdleEvent&) + 80
11 libwx_macud-2.8.0.dylib 0x0161643c wxAppBase::SendIdleEvents
(wxWindow*, wxIdleEvent&) + 80
12 libwx_macud-2.8.0.dylib 0x0161643c wxAppBase::SendIdleEvents
(wxWindow*, wxIdleEvent&) + 80
13 libwx_macud-2.8.0.dylib 0x016169ad wxAppBase::ProcessIdle()
+ 127
14 libwx_macud-2.8.0.dylib 0x0163fbdb wxEventLoopManual::Run()
+ 79
15 libwx_macud-2.8.0.dylib 0x01616146 wxAppBase::MainLoop() +
76
16 _core_.so 0x01342774 wxPyApp::MainLoop() + 52
17 _core_.so 0x013901f6 wxIntersectRect(wxRect*,
wxRect*) + 220430
18 org.python.python 0x00309b00 PyObject_Call + 45
19 org.python.python 0x00392b67 PyEval_EvalFrameEx +
13791
20 org.python.python 0x00395e0e PyEval_EvalCodeEx + 1819
21 org.python.python 0x0032ae6b PyFunction_SetClosure +
2019
22 org.python.python 0x00309b00 PyObject_Call + 45
23 org.python.python 0x003117ae PyMethod_New + 2432
24 org.python.python 0x00309b00 PyObject_Call + 45
25 org.python.python 0x00390d2f PyEval_EvalFrameEx +
6055
26 org.python.python 0x003949ce PyEval_EvalFrameEx +
21574
27 org.python.python 0x00395e0e PyEval_EvalCodeEx + 1819
28 org.python.python 0x0032ae6b PyFunction_SetClosure +
2019
29 org.python.python 0x00309b00 PyObject_Call + 45
30 org.python.python 0x003117ae PyMethod_New + 2432
31 org.python.python 0x00309b00 PyObject_Call + 45
32 org.python.python 0x0038e6fe
PyEval_CallObjectWithKeywords + 112
33 org.python.python 0x00313ce9 PyInstance_New + 114
34 org.python.python 0x00309b00 PyObject_Call + 45
35 org.python.python 0x00390d2f PyEval_EvalFrameEx +
6055
36 org.python.python 0x00395e0e PyEval_EvalCodeEx + 1819
37 org.python.python 0x00395fc2 PyEval_EvalCode + 87
38 org.python.python 0x003b936d PyRun_FileExFlags + 260
39 org.python.python 0x0038a5e7 PyAST_FromNode + 7521
40 org.python.python 0x00395593 PyEval_EvalFrameEx +
24587
41 org.python.python 0x00395e0e PyEval_EvalCodeEx + 1819
42 org.python.python 0x00393618 PyEval_EvalFrameEx +
16528
43 org.python.python 0x00395e0e PyEval_EvalCodeEx + 1819
44 org.python.python 0x00395fc2 PyEval_EvalCode + 87
45 org.python.python 0x003b936d PyRun_FileExFlags + 260
46 org.python.python 0x003b9707 PyRun_SimpleFileExFlags
+ 640
47 org.python.python 0x003b98aa PyRun_SimpleFile + 40
The following code displays properly (almost). The crashing may have
been a result of the BMP files being corrupted. However, the code
below still has a problem in that the list header displays, but is
overlapped by the page contents (i.e. the page contents do not move
down to accommodate the new icons with their larger height).
imageList = wx.ImageList(84, 40, True, 3)
for i in xrange(v.m_GraphsListBox.GetPageCount()):
fn = 'Resources/Images/button_0' + str(i+1) + '.png'
#image = wx.Bitmap(fn, wx.BITMAP_TYPE_BMP)
image = wx.Image(fn)
imageList.Add(image.ConvertToBitmap())
v.m_GraphsListBox.AssignImageList(imageList)
for i in xrange(v.m_GraphsListBox.GetPageCount()):
v.m_GraphsListBox.SetPageImage(i, i)
v.m_GraphsListBox.GetListView().SetSize(wx.Size(-1, 50))
v.m_GraphsListBox.GetListView().Refresh()
v.m_GraphsListBox.GetCurrentPage().Refresh()
v.m_GraphsListBox.Refresh()
The following code displays properly (almost). The crashing may have
been a result of the BMP files being corrupted. However, the code
below still has a problem in that the list header displays, but is
overlapped by the page contents (i.e. the page contents do not move
down to accommodate the new icons with their larger height).
imageList = wx.ImageList(84, 40, True, 3)
for i in xrange(v.m_GraphsListBox.GetPageCount()):
fn = 'Resources/Images/button_0' + str(i+1) + '.png'
#image = wx.Bitmap(fn, wx.BITMAP_TYPE_BMP)
image = wx.Image(fn)
imageList.Add(image.ConvertToBitmap())
v.m_GraphsListBox.AssignImageList(imageList)
for i in xrange(v.m_GraphsListBox.GetPageCount()):
v.m_GraphsListBox.SetPageImage(i, i)
v.m_GraphsListBox.GetListView().SetSize(wx.Size(-1, 50))
v.m_GraphsListBox.GetListView().Refresh()
v.m_GraphsListBox.GetCurrentPage().Refresh()
v.m_GraphsListBox.Refresh()
I ended up manually resetting the Y dimension to get the initial
layout right. From there, everything now works fine.
imageList = wx.ImageList(84, 40, True, 3)
for i in xrange(v.m_GraphsListBox.GetPageCount()):
fn = 'Resources/Images/button_0' + str(i+1) + '.png'
#image = wx.Bitmap(fn, wx.BITMAP_TYPE_BMP)
image = wx.Image(fn)
imageList.Add(image.ConvertToBitmap())
v.m_GraphsListBox.AssignImageList(imageList)
for i in xrange(v.m_GraphsListBox.GetPageCount()):
v.m_GraphsListBox.SetPageImage(i, i)
v.m_GraphsListBox.GetListView().SetSize(wx.Size(-1, 50))
v.m_GraphsListBox.GetListView().Refresh()
v.m_BodyWeightPage.SetDimensions(-1, 60, -1, -1,
wx.SIZE_USE_EXISTING)
v.m_BodyWeightPage.Refresh()