Reputation: 159
I have problem with wxpython on showing panel background images. I declared a wx.frame of size 800x600 on my win10 surface pro. Then in the frame, I first declared a background panel of the same size. I then filled its staticbitmap with a bitmap of the same size.
Then I declared a little panel of size 320x320 in the middle bottom. I also filled in its staticbitmap with a bitmap of 320x320.
But somehow the first background panel is always the background color (240,240,240,255) without the picture that I put in its staticbitmap. However, the picture for the small panel always showed up correctly.
The code is as follows.
class backgroundPanel(wx.Panel):
def __init__(self, *args, **kw):
x = 0
y = 0
w = 800
h = 600
kw.update({'pos':wx.Position(x, y), 'size':wx.Size(w, h)})
super(backgroundPanel, self).__init__(*args, **kw)
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
currentBitmap = util.queryGuiFrame().canvasBackgroundBitmap
self.staticBitmap = wx.StaticBitmap(self, wx.ID_ANY, currentBitmap)
self.Enable()
self.Refresh()
return
class actioner(wx.Panel):
def __init__(self, *args, **kw):
x = 240
y = 360
w = 320
h = 320
newCanvasState = kw.pop('newCanvasState', None)
print("New actioner from state: ", canvasState, " to :", newCanvasState)
kw.update({'pos':wx.Position(x, y), 'size':wx.Size(w, h)})
super(actioner, self).__init__(*args, **kw)
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
self.currentBitmap = util.queryGuiFrame().testerSittingBitmap
if newCanvasState == None:
#draw the initial actioner
currentBitmap = util.queryGuiFrame().testerSittingBitmap
elif newCanvasState == 'standbyFirst' \
or newCanvasState == 'standby' \
or newCanvasState == 'clockwise1' \
or newCanvasState == 'clockwise2' \
or newCanvasState == 'counterClockwise1' \
or newCanvasState == 'counterClockwise2':
print("drawing actioner standby at (", util.queryGuiFrame().actionerPanelX, ",",
util.queryGuiFrame().actionerPanelY, ")")
currentBitmap = util.queryGuiFrame().testerCuteBitmap
self.staticBitmap = wx.StaticBitmap(self, wx.ID_ANY, currentBitmap)
self.Enable(False)
self.Refresh()
return
I have worked on this for 1 day without any clue what wxpython hides from me.
I checked the properties of the two panels and did not see any difference.
I also tried to switch the two panels in declaration order.
It is the same, only that smaller panel is now hidden by the large beige background panel.
I have also tried to put the background panel bitmap to the frame's staticbitmap. The result is the same, a panel of all (240,240,240,255) pixels.
Also, it is annoying that the IDEs make different assumptions and interpretation to wxpython.
I used pyscriptor and there seemed less problem.
Especially, the boundary of the whole window need be declared.
However pyscriptor does not accept breakpoints in child threads.
So I switched to PyDev.
But it interprets the whole window boundary differently and my layout looks misplaced.
I am not sure what my clients will see when they run the app.
Any suggestion will be appreciated.
Upvotes: 0
Views: 246
Reputation: 159
Thanks for your attention. The problem has been solved. Now I also removed the background panel and draw directly on the frame background. The background panel seems irrelevant.
The problem is caused by two issues. First, we do need double buffer. If we make the staticBitmap directly out my canvasbitmap, the frame background is still blank.
Second, I was kind of trying to dynamically declare some other panels of the frame after the frame instantiation. That seems also causing the problem.
Now I instantiated all the panels in the frame instantiation.
Then the problem went away after a clueless day.
But this kind of unsaid rules sometimes can be very frustrating and exhausting to the newbies.
Upvotes: 1