Linux Mint 17,Python 2.7,wx'2.8.12.1'
我是wx的新手,可能,我无法做出正确的搜索队列。 我已经通读了 Dialog's ShowModal() won't send EVT_PAINT 并尝试用self取代self.pnl,但显然不起作用。
代码来自“OpenCV with Python Blueprints”一书,见第19-21页。
我已经制作了丑陋的补丁以使其正常工作(在代码中标记),但对此情况感到好奇。
import cv2
import wx
class BaseLayout(wx.Frame):
def __init__(self, parent, id, title, capture, fps=24):
self.fps=fps
self.capture = capture
_, frame = self.capture.read()
self.imgHeight,self.imgWidth = frame.shape[:2]
self.bmp = wx.BitmapFromBuffer(self.imgWidth,
self.imgHeight, frame)
wx.Frame.__init__(self, parent, id, title,size=(self.imgWidth, self.imgHeight+20))
self._init_base_layout()
self._create_base_layout()
def _init_base_layout(self):
self.timer = wx.Timer(self)
self.timer.Start(1000./self.fps)
self.Bind(wx.EVT_TIMER, self._on_next_frame)
self.Bind(wx.EVT_PAINT, self._on_paint)
def _on_next_frame(self, event):
ret, frame = self.capture.read()
if ret:
frame = self._process_frame(cv2.cvtColor(frame,cv2.COLOR_BGR2RGB))
self.bmp.CopyFromBuffer(frame)
self.Refresh(eraseBackground=False)#this intended to work
deviceContext = wx.BufferedPaintDC(self.pnl)#this works (ugly patch from on_paint)
deviceContext.DrawBitmap(self.bmp, 0, 0)#this works(ugly patch from on_paint)
def _on_paint(self, event):
print('I can never see this line')
deviceContext = wx.BufferedPaintDC(self.pnl)
deviceContext.DrawBitmap(self.bmp, 0, 0)
def _create_base_layout(self):
self.pnl = wx.Panel(self, -1,size=(self.imgWidth, self.imgHeight))
self.pnl.SetBackgroundColour(wx.BLACK)
self.panels_vertical = wx.BoxSizer(wx.VERTICAL)
self.panels_vertical.Add(self.pnl, 1, flag=wx.EXPAND)
self.SetMinSize((self.imgWidth, self.imgHeight))
self.SetMaxSize((self.imgWidth, self.imgHeight))
self.SetSizer(self.panels_vertical)
self.Centre()
def _process_frame(self, frame):
return frame#stub
def main():
capture = cv2.VideoCapture("ScreenFlow9.mov")
if not(capture.isOpened()):
capture.open()
capture.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 640)
capture.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 480)
app = wx.App()
layout = BaseLayout(None, -1, 'Test', capture)
layout.Show(True)
app.MainLoop()
main()
答案 0 :(得分:0)
框架没有获得EVT_PAINT
事件,因为框架的客户区域都不可见。小组完全覆盖了它。