def OnPaint(self, event):
     ps = PAINTSTRUCT()
     ps.fErase = True
     hdc = self.BeginPaint(ps)
     rect = self.GetClientRect()
     status, graphics = gdiplus.GdipCreateFromHDC(hdc)
     status = gdiplus.GdipGraphicsClear(graphics, self.color_background)
     self.grid.draw(graphics)
     gdiplus.GdipDeleteGraphics(graphics)
     self.EndPaint(ps)
 def OnMouseMove(self, event):
     self.grid.current_point = GET_POINT_LPARAM(event.lParam)
     if self.grid.is_cell_changed():
         hdc = self.GetDC()
         status, graphics = gdiplus.GdipCreateFromHDC(hdc)
         clip_rect = self.grid.current_cell + self.grid.old_cell
         status = gdiplus.GdipSetClipRectI(graphics, clip_rect.left,
                                           clip_rect.top, clip_rect.width,
                                           clip_rect.height,
                                           gdiplus.CombineModeReplace)
         status = gdiplus.GdipGraphicsClear(graphics, self.color_background)
         self.grid.draw(graphics)
         gdiplus.GdipDeleteGraphics(graphics)
         self.ReleaseDC(hdc)
 def OnDestroy(self, event):
     if self.graphics:
         status = gdiplus.GdipDeleteGraphics(self.graphics)
     application.Quit()