私が書いているプログラムでいくつかの問題が発生しているので、助けや入力をいただければ幸いです。いくつかの背景として、ストリーミングWebカメラクライアントを実行するためにPython2.7とwxPythonを使用しています。クライアントは、サーバーから独自のスレッドで画像を取得し、それらをキューに入れます。次に、GUIスレッドはそれらの画像をキューから取得し、それらをwxBitmap
オブジェクトに変換します。これは0.5秒ごとに発生し、うまく機能します。オブジェクトをファイルとして保存できるwxBitmap
ので、すべてが正常に機能していることがわかります。
私が抱えている問題は、実際にwxBitmap
オブジェクトをGUIに表示させることです。GUIにできるように見えるのは、Webカメラの画像があるはずの場所に灰色の長方形を表示することだけです。
onPaint()
画面を更新したいときに呼び出されるのは次のとおりです。
def onPaint(self,e):
## this is the function that actually draws and redraws the window
## to be displayed. I think it is something similar to blit()
## in other graphical display frameworks
print "in onPaint"
## create the device context object (graphics painter)
dc = wx.PaintDC(self)
dc.BeginDrawing()
## draw the bitmap to the screen
dc.DrawBitmap(self.imageBit,0,0,True)
dc.EndDrawing()
## test code.
## the following works and updates, which means that
## everything is being converted properly and updated.
## not sure why the dc won't paint it to the window.
self.imageBit.SaveFile("bit.bmp", wx.BITMAP_TYPE_BMP)
簡単に言えば、なぜそれが機能しないのか私は途方に暮れています。調査の結果、Windowsマシンを使用しているため、BeginDrawing()
とEndDrawing()
関数が必要であることがわかったので、それらを追加しました。それでも動作しません。スローされるエラーや例外はありません。
この問題の解決に役立つ可能性のあるその他の質問:
- オブジェクトを更新してい
wxFrame
ます。たぶん、wxPaintDC
動作するために別のタイプのコンテナで動作する必要がありますか? - ?
実際、私の__init__
機能は問題を抱えているものかもしれません。これを正しく設定していますか?
class viewWindow(wx.Frame):
imgSizer = (480,360)
def __init__(self, *args, **kw):
## this is called when an instance of this class is created
super(viewWindow,self).__init__(*args,**kw)
## here is where the actual stuff inside the frame is set up.
self.pnl = wx.Panel(self)
## create a button that opens up a Connection Window
#test = wx.Button(self.pnl, label='Connection Settings')
## test.Bind(wx.EVT_BUTTON, self.openConnectionWindow)
## create the wxImage for the web cam pic
self.image = wx.EmptyImage(self.imgSizer[0],self.imgSizer[1])
## create the wxBitmap so that the wxImage can be displayed
self.imageBit = wx.BitmapFromImage(self.image)
## create a timer that will update the window based of frame rate
self.timex = wx.Timer(self, wx.ID_OK)
self.timex.Start(500)
self.Bind(wx.EVT_TIMER, self.redraw, self.timex)
## need to do the following in order to display images in wxPython:
self.Bind(wx.EVT_PAINT, self.onPaint)
self.SetSize(self.imgSizer)
self.SetTitle('View Window')
self.Show()
とにかく、よろしくお願いします。
編集:行を削除して、誤って問題を解決しましたself.pnl = wx.Panel(self)
。
どうやらそれは適切にレンダリングされていたようですが、ビットマップはパネルの下にありました。多分?よくわかりません。私はこのwxPython全体に不慣れです。