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()