def OnPaint(self, evt): dc = wx.PaintDC(self) #dc.Clear() w, h = dc.GetSizeTuple() dc.SetPen(wx.RED_PEN) cr = ContextFromDC(dc) cr.scale(w, h) cr.set_source_rgb(1, 0, 1) cr.set_line_width(0.002) path = self.path.send(cr) x, y = self.data.next() #dc.DrawLines(numpy.array([x*w,y*h]).T) cairo_tools.polyline(cr, x, y) cairo_tools.stamp_at(cr, path, x, y) cr.stroke()
def update_ownUI(self): """ This would get called if the drawing needed to change, for whatever reason. The idea here is that the drawing is based on some data generated elsewhere in the system. If that data changes, the drawing needs to be updated. This code re-draws the buffer, then calls Update, which forces a paint event. """ dc = wx.MemoryDC() dc.SelectObject(self._Buffer) dc.SetBackground(wx.Brush("White")) # start the DC and clear it dc.Clear() # make sure you clear the bitmap! ctx = ContextFromDC(dc) # load it into cairo self.DrawCairo(ctx) dc.SelectObject(wx.NullBitmap) # need to get rid of the MemoryDC before Update() is called. self.Refresh() self.Update()
def update_ownUI(self): """ This would get called if the drawing needed to change, for whatever reason. The idea here is that the drawing is based on some data generated elsewhere in the system. If that data changes, the drawing needs to be updated. This code re-draws the buffer, then calls Update, which forces a paint event. """ ##################### # remove buffered features, to force redraw: self.cairoStorage['features'] = None # The Buffer init is done here, to make sure the buffer is always # the same size as the Window wC, hC = self.parent.GetClientSize() wP, hP = self.parent.GetSize() self.SetSize(wx.Size(wC, self.minHeight)) self.parent.SetVirtualSize(wx.Size(wC - 30, self.minHeight)) # Make new offscreen bitmap: this bitmap will always have the # current drawing in it, so it can be used to save the image to # a file, or whatever. # if wC != 0 and hC !=0: # self._Buffer = wx.EmptyBitmap(wC, self.minHeight) # else: # self._Buffer = wx.EmptyBitmap(wP, hP) ########################## # start dc dc = wx.MemoryDC() dc.SelectObject(self._Buffer) dc.SetBackground(wx.Brush("White")) dc.Clear() # make a cairo context self.ctx = ContextFromDC(dc) # start pango as a font backend self.pango = pangocairo.CairoContext(self.ctx) self.pango.set_antialias(cairo.ANTIALIAS_SUBPIXEL) # reload dna self.dna = genbank.gb.GetDNA() if self.dna != None: self.cdna = dna.C(self.dna) else: self.dna = '' # no dna, if there is nothing self.cdna = '' # empty cdna # render the text self.displayText() # create colorful features here self.drawFeatures() # draw enzymes self.drawEnzymes() # draw a cursor self.drawCursor() # draw Tics above all! self.drawTicks() # end of canvas handling dc.SelectObject( wx.NullBitmap ) # need to get rid of the MemoryDC before Update() is called. self.Refresh() self.Update() return None