2010-02-27 59 views
1

此應用程序中的簡單曲線只有在從屏幕拖出或調整窗口大小時纔會出現。當應用程序剛剛啓動時,它不會出現,並且當窗口最大化或最小化時,它也會消失。然而,所有這些時間,「繪製路徑」都被打印出來,所以所有的繪畫功能都被調用。有沒有什麼我做錯了關於創建和繪製graphicscontext?如果沒有,我怎麼能在這些特殊情況下完全刷新窗口?GraphicsPath並不總是自動刷新

import wx 

class Path(object): 
    def paint(self,gc): 
     print "Path Drawn" 
     gc.SetPen(wx.Pen("#000000",1)) 
     path=gc.CreatePath() 
     path.MoveToPoint(wx.Point2D(10,10)) 
     path.AddCurveToPoint(wx.Point2D(10,50), 
          wx.Point2D(10,150), 
          wx.Point2D(100,100)) 
     gc.DrawPath(path) 


class TestPane(wx.Panel): 
    def __init__(self,parent=None,id=-1): 
     wx.Panel.__init__(self,parent,id,style=wx.TAB_TRAVERSAL) 
     self.SetBackgroundColour("#FFFFFF") 
     self.Bind(wx.EVT_PAINT,self.onPaint) 
     self.SetDoubleBuffered(True) 
     self.path=Path() 

    def onPaint(self, event): 
     event.Skip() 

     dc=wx.PaintDC(self) 
     dc.BeginDrawing() 
     gc = wx.GraphicsContext.Create(dc) 

     gc.PushState() 
     self.path.paint(gc) 
     gc.PopState() 
     dc.EndDrawing() 

    def drawTestRects(self,dc): 
     dc.SetBrush(wx.Brush("#000000",style=wx.SOLID)) 
     dc.DrawRectangle(50,50,50,50) 
     dc.DrawRectangle(100,100,100,100) 

class TestFrame(wx.Frame): 
    def __init__(self, parent, title): 
     wx.Frame.__init__(self, parent, title=title, size=(640,480)) 
     self.mainPanel=TestPane(self,-1) 

     self.Show(True) 


app = wx.App(False) 
frame = TestFrame(None,"Test App") 
app.MainLoop() 

回答

2

註釋掉self.SetDoubleBuffered(True)部分,它會工作,因爲由於錯誤http://trac.wxwidgets.org/ticket/11138窗口,如果SetDoubleBuffered和GraphicsContext一起使用不正確地刷新。

如果您必須自己需要雙緩衝工具,例如首先繪製到MeomryDC,然後blit或繪製位圖來繪製直流。