Georgia Tech has just started a Corsera Massive Open Online Course (MOOC, www.coursera.org/course/phys1) in which students use their smartphones to capture video of moving objects and then model the motion in 3D using VPython (vpython.org). As some of you know, the recent VPython 6.x is based on wxPython, whereas VPython 5.x had platform-dependent C++ code for key elements of the module.
VPython has a “label” object which displays 2D text “billboarded” in the scene – that is, the text always faces forward. The implementation is quite different between VPython 5.x and 6.x. For some students in the Georgia Tech MOOC, trying to execute the label object causes a crash. Based on reports in the course forum, the number of students experiencing the bug is very small. Nearly all of the MOOC students use the python.org 32-bit Windows Python 2.7, including all those who have reported the label problem. None of the Windows computers I have access to show this bug, nor has it been previously reported outside the MOOC.
Below I display the guts of the VPython 6.x implementation of label (there’s also some platform-independent C++ code). Because I don’t have access to the computers that have the bug, I don’t have any detailed information, just that there is a crash. I realize that it’s a very long shot, but does this ring any bells with anyone? Thanks.
dc = _wx.MemoryDC() # wx was imported as _wx; currently using classic wxPython
height = int(fudge*height + 0.5)
dc.SetFont(_wx.Font(height, wfont, wstyle, wweight))
while text and text[0] == ‘\n’: text = text[1:]
while text and text[-1] == ‘\n’: text = text[:-1]
lines = text.split(’\n’)
maxwidth = 0
totalheight = 0
heights = []
for line in lines:
if line == ‘’: line = ’ ’
w,h = dc.GetTextExtent(line)
h += 1
w += 2
if w > maxwidth: maxwidth = w
heights.append(totalheight)
totalheight += h
if ‘phoenix’ in _wx.PlatformInfo:
bmp = _wx.Bitmap(maxwidth,totalheight) # Phoenix
else:
bmp = _wx.EmptyBitmap(maxwidth,totalheight) # classic
dc.SelectObject(bmp)
fore = (int(255*color[0]),
int(255*color[1]),
int(255*color[2]))
dc.SetTextForeground(fore)
back = (int(255*background[0]),
int(255*background[1]),
int(255*background[2]))
if (back == fore):
if fore == (0,0,0): back = (255,255,255)
elif fore == (255,255,255): back = (0,0,0)
else: back = (fore[0]//2, fore[1]//2, fore[2]//2)
brush = _wx.Brush(back)
dc.SetBackground(brush)
dc.Clear()
for n, line in enumerate(lines):
dc.DrawText(line, 1, heights[n])
dc.SelectObject( _wx.NullBitmap )
if ‘phoenix’ in _wx.PlatformInfo:
img = bmp.ConvertToImage() # Phoenix
data = asarray(img.GetData()) # Phoenix; maybe should be GetDataBuffer()
else:
img = _wx.ImageFromBitmap(bmp) # classic
data = fromstring(img.GetData(), dtype=uint8) # classic