I fixed my initial problem, which turned out not to be a wxPython problem
after all - thanks to all the helpful suggestions, which I used to
diagnose what the problem actually was!
I'm having trouble now with the same piece of code. I want to set the
window up so that it will add a scroll bar when the buttons no longer fit
inside the panel. I've added the code that I think should do that, but
the panel never adds the scroll bar. Could someone help me figure out how
to get it to work? I've included the code below.
Thank you!
Shari
class HistoryView(scrolled.ScrolledPanel):
SPACING = 1
def __init__(self, parent):
scrolled.ScrolledPanel.__init__(self, parent, -1, size=(840, 200))
self.parent = parent
self.history = self.parent.currAppData.history
self.boxSizer = wx.BoxSizer(wx.HORIZONTAL)
self.myVizEngine = vizGenerator.vizEngine.vizEngine(MAP_FILE_NAME,
DATA_FILE_NAME)
# Add initial position to history
print "Adding initial position: ", self.parent.currAppData.position
self.AddPosition(self.parent.currAppData.position)
self.SetSizer(self.boxSizer)
self.boxSizer.Fit(self)
self.SetupScrolling(scroll_x=True, scroll_y=False)
self.FitInside()
def AddPosition(self, position):
print "In HistoryView.AddPosition, adding position ",
position.toString()
historyButton = HistoryButton(self, position, self.myVizEngine)
print "History button ID: ", historyButton.GetId()
self.boxSizer.Add(historyButton, 0, wx.ALL, self.SPACING)
self.boxSizer.Fit(self)
self.SetSizer(self.boxSizer)
self.SetupScrolling(scroll_x=True, scroll_y=False)
self.FitInside()
class HistoryButton(buttons.GenBitmapButton):
SCALE_FACTOR = 0.75
def __init__(self, parent, position, vizEngine):
self.position = position.copy()
print "Button created with position: ", self.position.toString()
self.parent = parent
textureFilename = vizEngine.getViz([position.x, position.z])
image = wx.Image(textureFilename, wx.BITMAP_TYPE_BMP)
width = image.GetWidth()
height = image.GetHeight()
scaledImage = image.Scale(width * self.SCALE_FACTOR, height *
self.SCALE_FACTOR)
bitmapImage = scaledImage.ConvertToBitmap()
buttons.GenBitmapButton.__init__(self, parent, -1, bitmapImage,
pos=(0, 0), style=0)
self.Bind(wx.EVT_BUTTON, self.OnClick, self)
print "Button Object: ", self
def OnClick(self, event):
print "Button Position clicked: ", self.position.toString()
print "Button ID: ", self.GetId()
self.parent.parent.navigationPanel.OnStep(self.position)
print "Button object clicked: ", self