I'm a R&D / Hardware guy for a gaming company, and the developers are
working on a game (the use C#) and the front end using is full of
artifacting, and flickering when various events fire (almost on any
paint event) but they are using a full screen frame so it's not as
pronounced as there aren't many move or size events, but it still
shows a huge lack of polish (to me...)
I make various apps using Python to test hardware since most of the
games we make are not PC based (various logic platforms like Pot-O-
Gold [casino stuff]) and I know I can show them a "better way"... I'm
not trying to sell them on Python, just show them that their code
could use some more finesse. On top of that one of the guys rolls his
eyes and scoffs at the very mention of Python.
So I'm trying to replicate the game's front end GUI in Python and I'm
having an issue with an EVT_PAINT event. I'm trying to store a bitmap
(660kb) as a brush (wx.BrushFromBitmap) and paint the background, but
all I get is a black background. The bitmap isn't black.
Can one of you guys tell me what I'm doing wrong please.
Here is the super slimmed down code that shows my failure to
understand the proper way. The issue seems to be in the OnPaint
event. It's seems the brush never becomes the bitmap if I change the
setbackground to a color that seems to work.
## Code
import wx
class BasePanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1)
self.ScreenResolution = wx.GetDisplaySize()
self.GP = self.GetParent()
self.DC = wx.ClientDC(self)
CloseWindowResource = 'Graphic Resources\Close Window.png'
self.CloseWindowBMP = wx.Bitmap(CloseWindowResource)
self.CloseWindowBMPMask = wx.Mask(self.CloseWindowBMP,
wx.WHITE)
self.CloseWindowBMP.SetMask(self.CloseWindowBMPMask)
self.CloseWindowSBMP = wx.StaticBitmap(self, -1,
self.CloseWindowBMP, (self.ScreenResolution[0] - 45, 10))
self.Bind(wx.EVT_PAINT, self.OnPaint)
wx.EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
self.CloseWindowSBMP.Bind(wx.EVT_ENTER_WINDOW,
self.OnCloseWindowSBMPEnter)
self.CloseWindowSBMP.Bind(wx.EVT_LEAVE_WINDOW,
self.OnCloseWindowSBMPLeave)
self.CloseWindowSBMP.Bind(wx.EVT_LEFT_DOWN,
self.OnCloseWindowClick)
def OnPaint(self, event):
ClientSize = self.GetClientSizeTuple()
Buffer = wx.EmptyBitmap(ClientSize[0], ClientSize[1])
Paint = wx.BufferedPaintDC(self, Buffer)
BGBrush = wx.BrushFromBitmap(wx.Bitmap('Graphic Resources
\Panel Background.png'))
Paint.SetBackground(BGBrush)
Paint.Clear()
def OnEraseBackground(self, event):
None
def OnCloseWindowSBMPEnter(self, event):
self.DC.SetPen(wx.Pen("WHITE"))
self.DC.DrawLine(50, 60, 190, 60)
self.DC.EndDrawing()
def OnCloseWindowSBMPLeave(self, event):
self.Refresh()
def OnCloseWindowClick(self, event):
self.GP.Close()
class BaseFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1)
self.BP = BasePanel(self)
self. ShowFullScreen(True, style = wx.DEFAULT_FRAME_STYLE |
wx.NO_FULL_REPAINT_ON_RESIZE | wx.FULLSCREEN_ALL)
class SomaApp(wx.App):
def OnInit(self):
BF = BaseFrame()
BF.Show(True)
return True
App = SomaApp(False)
App.MainLoop()
## End Code