我们从Python开源项目中,提取了以下34个代码示例,用于说明如何使用wx.SOLID。
def refresh(self): dc = wx.MemoryDC(self.drawingBuffer) dc.SelectObject(self.drawingBuffer) dc.SetBackground(wx.Brush(self.background, style=wx.SOLID)) dc.Clear() gc = wx.GraphicsContext.Create(dc) # do not draw if window is very small, right solution? XXX - idfah if self.winRadius < 1.0e-3: return self.draw(gc) dc.SelectObject(wx.NullBitmap) self.triggerRepaint()
def Clear(self): """Erase the window.""" self.last_PointLabel = None # reset pointLabel dc = wx.BufferedDC(wx.ClientDC(self.canvas), self._Buffer) bbr = wx.Brush(self.GetBackgroundColour(), wx.SOLID) dc.SetBackground(bbr) dc.SetBackgroundMode(wx.SOLID) dc.Clear() if self._antiAliasingEnabled: try: dc = wx.GCDC(dc) except Exception: pass dc.SetTextForeground(self.GetForegroundColour()) dc.SetTextBackground(self.GetBackgroundColour()) self.last_draw = None
def DrawHighlightment(self, dc): scalex, scaley = dc.GetUserScale() dc.SetUserScale(1, 1) dc.SetPen(MiterPen(HIGHLIGHTCOLOR, (3 * scalex + 5), wx.SOLID)) dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.SetLogicalFunction(wx.AND) # Draw a two circle arcs for representing the coil dc.DrawEllipticArc(round(self.Pos.x * scalex), round((self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1) * scaley), round(self.Size[0] * scalex), round((int(self.Size[1] * sqrt(2)) - 1) * scaley), 135, 225) dc.DrawEllipticArc(round(self.Pos.x * scalex), round((self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1) * scaley), round(self.Size[0] * scalex), round((int(self.Size[1] * sqrt(2)) - 1) * scaley), -45, 45) dc.SetLogicalFunction(wx.COPY) dc.SetUserScale(scalex, scaley) # Adds an highlight to the connection
def draw(self): l, t, r, b = 35,35,15,35 w = self.width - l - r h = self.height - t - b if self.data is None:return dc = wx.BufferedDC(wx.ClientDC(self), self.buffer) dc.Clear() left, low, right, high = self.extent self.draw_coord(dc, w, h, l, t, r, b) for xs, ys, c, lw in self.data: ys = h+t - (ys - low)*(h/(high-low)) xs = l+(xs-left)*(1.0/(right-left)*w) pts = list(zip(xs, ys)) dc.SetPen(wx.Pen(c, width=lw, style=wx.SOLID)) dc.DrawLines(pts)
def draw(self, dc, f, **key): dc.SetTextForeground((255,255,0)) font = wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False) dc.SetFont(font) dc.SetPen(wx.Pen((0,255,0), width=1, style=wx.SOLID)) dc.SetBrush(wx.Brush((0,255,0))) pos = [f(*(i[1], i[0])) for i in self.xy[self.msk]] for i in pos:dc.DrawCircle(int(i[0]), int(i[1]), 2) dc.SetPen(wx.Pen((255,0,0), width=1, style=wx.SOLID)) dc.SetBrush(wx.Brush((255,0,0))) pos = [f(*(i[1], i[0])) for i in self.xy[~self.msk]] for i in pos:dc.DrawCircle(int(i[0]), int(i[1]), 2)
def draw(self, dc, f, **key): dc.SetPen(wx.Pen(Setting['color'], width=1, style=wx.SOLID)) dc.SetTextForeground(Setting['tcolor']) font = wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False) dc.SetFont(font) dc.DrawLines([f(*i) for i in self.buf]) for i in self.buf:dc.DrawCircle(f(*i),2) for line in self.body: dc.DrawLines([f(*i) for i in line]) for i in line:dc.DrawCircle(f(*i),2) pts = np.array(line) mid = (pts[:-1]+pts[1:])/2 dis = norm((pts[:-1]-pts[1:]), axis=1) unit = 1 if self.unit is None else self.unit[0] for i,j in zip(dis, mid): dc.DrawText('%.2f'%(i*unit), f(*j))
def draw(self, dc, f, **key): dc.SetPen(wx.Pen(Setting['color'], width=1, style=wx.SOLID)) dc.SetTextForeground(Setting['tcolor']) linefont = wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False) dc.SetFont(linefont) dc.DrawLines([f(*i) for i in self.buf]) for i in self.buf:dc.DrawCircle(f(*i),2) for line in self.body: dc.DrawLines([f(*i) for i in line]) for i in line:dc.DrawCircle(f(*i),2) pts = np.array(line) v1 = pts[:-2]-pts[1:-1] v2 = pts[2:]-pts[1:-1] a = np.sum(v1*v2, axis=1)*1.0 a/=norm(v1,axis=1)*norm(v2,axis=1) ang = np.arccos(a)/np.pi*180 for i,j in zip(ang,line[1:-1]): dc.DrawText('%.0f'%i, f(*j))
def draw(self, dc, f, **key): dc.SetPen(wx.Pen(Setting['color'], width=1, style=wx.SOLID)) dc.SetTextForeground(Setting['tcolor']) font = wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False) dc.SetFont(font) dc.DrawLines([f(*i) for i in self.buf]) for i in self.buf:dc.DrawCircle(f(*i),2) for pg in self.body: plg = Polygon(pg) dc.DrawLines([f(*i) for i in pg]) for i in pg: dc.DrawCircle(f(*i),2) area, xy = plg.area, plg.centroid if self.unit!=None: area *= self.unit[0]**2 dc.DrawText('%.1f'%area, f(xy.x, xy.y))
def draw(self, dc, f, **key): dc.SetPen(wx.Pen(Setting['color'], width=1, style=wx.SOLID)) dc.SetTextForeground(Setting['tcolor']) linefont = wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False) dc.SetFont(linefont) if len(self.buf)>1: dc.DrawLines([f(*i) for i in self.buf]) for i in self.buf:dc.DrawCircle(f(*i),2) for line in self.body: dc.DrawLines([f(*i) for i in line]) for i in line:dc.DrawCircle(f(*i),2) pts = np.array(line) mid = (pts[:-1]+pts[1:])/2 dxy = (pts[:-1]-pts[1:]) dis = norm(dxy, axis=1) unit = 1 if self.unit is None else self.unit[0] for i,j in zip(dis, mid): dc.DrawText('%.2f'%(i*unit), f(*j))
def refresh(self): """Refresh the drawing area after a change has been made. This method sets up a drawing context, calls self.draw to update the drawing and then calls self.triggerRepaint in order to update the drawing area on the screen. This method should be called each time a change is made that requires the drawing area to be updated. """ dc = wx.MemoryDC(self.drawingBuffer) dc.SelectObject(self.drawingBuffer) dc.SetBackground(wx.Brush(self.background, style=wx.SOLID)) dc.Clear() # do not draw if window is very small, right solution? XXX - idfah if self.winRadius < 1.0e-3: return #dc.BeginDrawing() self.draw(dc) #dc.EndDrawing() #del dc dc.SelectObject(wx.NullBitmap) self.triggerRepaint()
def draw(self, dc, f, **key): dc.SetPen(wx.Pen((255,0,0), width=2, style=wx.SOLID)) for line in self.foreline: dc.DrawLines([f(*i) for i in line]) dc.SetPen(wx.Pen((0,0,255), width=2, style=wx.SOLID)) for line in self.backline: dc.DrawLines([f(*i) for i in line])
def MiterPen(colour, width=1, style=wx.SOLID): pen = wx.Pen(colour, width, style) pen.SetJoin(wx.JOIN_MITER) pen.SetCap(wx.CAP_PROJECTING) return pen # ------------------------------------------------------------------------------- # Helpers for highlighting text # -------------------------------------------------------------------------------
def draw(self, dc, f): dc.SetPen(wx.Pen(RoiManager.get_color(), width=RoiManager.get_lw(), style=wx.SOLID)) if len(self.body)>1: dc.DrawLines([f(*i) for i in self.body]) for i in [self.lt, (self.lt+self.rt)/2, self.rt]: for j in [self.tp, (self.tp+self.bm)/2, self.bm]: dc.DrawCircle(f(i,j),2)
def draw(self, dc, f): dc.SetPen(wx.Pen(RoiManager.get_color(), width=RoiManager.get_lw(), style=wx.SOLID)) for line in self.body: if len(line)>1: dc.DrawLines([f(*i) for i in line]) for i in line:dc.DrawCircle(f(*i),2)
def draw(self, dc, f): dc.SetPen(wx.Pen(RoiManager.get_color(), width=RoiManager.get_lw(), style=wx.SOLID)) if(len(self.body)>1): dc.DrawLines([f(*i) for i in self.body]) for i in self.body:dc.DrawCircle(f(*i),2) dc.DrawCircle(f(self.lt, (self.tp+self.bm)/2),2) dc.DrawCircle(f(self.rt, (self.tp+self.bm)/2),2) dc.DrawCircle(f((self.lt+self.rt)/2, self.tp),2) dc.DrawCircle(f((self.lt+self.rt)/2, self.bm),2)
def draw(self, dc, f): dc.SetPen(wx.Pen(RoiManager.get_color(), width=RoiManager.get_lw(), style=wx.SOLID)) for i in self.body: dc.DrawCircle(f(*i), 2)
def draw(self, dc, f): dc.SetPen(wx.Pen(RoiManager.get_color(), width=RoiManager.get_lw(), style=wx.SOLID)) for pg in self.body: dc.DrawLines([f(*i) for i in pg[0]]) if self.issimple(): for i in pg[0]: dc.DrawCircle(f(*i),2) for hole in pg[1]: dc.DrawLines([f(*i) for i in hole])
def draw_ruler(self, dc): dc.SetPen(wx.Pen((255,255,255), width=2, style=wx.SOLID)) x1 = max(self.imgbox[0], self.box[0])+5 x2 = min(self.imgbox[2], self.box[2])+x1-10 pixs = (x2-x1+10)*self.ips.size[1]/10.0/self.imgbox[2] h = min(self.imgbox[1]+self.imgbox[3],self.box[3])-5 dc.DrawLineList([(x1,h,x2,h)]) dc.DrawLineList([(i,h,i,h-8) for i in np.linspace(x1, x2, 3)]) dc.DrawLineList([(i,h,i,h-5) for i in np.linspace(x1, x2, 11)]) dc.SetTextForeground((255,255,255)) k, unit = self.ips.unit text = 'Unit = %.1f %s'%(k*pixs, unit) dw,dh = dc.GetTextExtent(text) dc.DrawText(text, (x2-dw, h-10-dh))
def draw_coord(self, dc, w, h, l, t, r, b): xs = [5, 10, 20, 40, 50, 100, 200, 400, 500, 1000, 2000, 4000, 10000] n, dx, dy = len(self.data), 0, 0 left, low, right, high = self.extent for i in xs[::-1]: if (right-left)*1.0/i<=10:dx=i for i in xs[::-1]: if (high-low)*1.0/i<=10:dy=i dc.SetPen(wx.Pen((0, 0, 0), width=1, style=wx.SOLID)) dc.DrawRectangle(l, t, w+1, h+1) dc.SetPen(wx.Pen((100, 100, 100), width=1, style=wx.SOLID)) for i in range(int(ceil(left*1.0/dx)*dx), int(right)+1, dx): x = l+(i-left)*1.0/(right-left)*w dc.DrawLine(x, t, x, t+h) dc.DrawText(str(i), x-5, t+h) for i in range(int(ceil(low*1.0/dy)*dy), int(high)+1, dy): y = h+t-(i-low)*1.0/(high-low)*h dc.DrawLine(l, y, l+w, y) dc.DrawText(str(i), 5, y-5) titlefont = wx.Font(18, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False) dc.SetFont(titlefont) dw,dh = dc.GetTextExtent(self.title) dc.DrawText(self.title, l+w/2-dw/2, 3) lablelfont = wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False) dc.SetFont(lablelfont) dw,dh = dc.GetTextExtent(self.labelx) dc.DrawText(self.labelx, l+w-dw, t+h+15) dc.DrawText(self.labely, 5, 10)
def draw(self, dc, f, **key): dc.SetPen(wx.Pen((255,255,0), width=3, style=wx.SOLID)) dc.SetTextForeground((255,255,0)) font = wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False) dc.SetFont(font) ids = self.graph.nodes() pts = [self.graph.node[i]['o'] for i in ids] pts = [f(i[1], i[0]) for i in pts] dc.DrawPointList(pts) dc.DrawTextList([str(i) for i in ids], pts)
def draw(self, dc, f): print(self.x, self.y) dc.SetPen(wx.Pen((255,255,0), width=1, style=wx.SOLID)) dc.DrawLines([f(0,self.y),f(self.w,self.y)]) dc.DrawLines([f(self.x,0),f(self.x,self.h)])
def draw(self, dc, f, **key): dc.SetPen(wx.Pen((0,255,0), width=1, style=wx.SOLID)) sox, soy = f(self.para['ox'], self.para['oy']) dc.DrawCircle((sox, soy), 5) a = np.linspace(0, 2*np.pi, 20) dc.DrawLines(list(zip(sox+np.cos(a)*40, soy+np.sin(a)*40))) a = self.para['ang']*np.pi/180 dc.DrawCircle((sox+np.cos(a)*40, soy+np.sin(a)*40), 3)
def draw(self, dc, f, **key): body = [(self.lt,self.bm),(self.rt,self.bm), (self.rt,self.tp),(self.lt,self.tp),(self.lt,self.bm)] dc.SetPen(wx.Pen((0,255,0), width=1, style=wx.SOLID)) dc.DrawLines([f(*i) for i in body]) for i in body:dc.DrawCircle(f(*i),2) dc.DrawCircle(f(self.lt, (self.tp+self.bm)/2),2) dc.DrawCircle(f(self.rt, (self.tp+self.bm)/2),2) dc.DrawCircle(f((self.lt+self.rt)/2, self.tp),2) dc.DrawCircle(f((self.lt+self.rt)/2, self.bm),2)
def draw(self, dc, f, **key): dc.SetPen(wx.Pen((255,0,0), width=2, style=wx.SOLID)) dc.DrawLines([f(*i) for i in self.line])
def draw(self, dc, f, **key): dc.SetPen(wx.Pen((0,255,0), width=1, style=wx.SOLID)) if len(self.buf[0])>1: dc.DrawLines([f(*i) for i in self.buf[0]]) for i in self.buf[0]: dc.DrawCircle(f(*i),2)
def draw(self, dc, f, **key): dc.SetPen(wx.Pen((0,255,255), width=1, style=wx.SOLID)) if len(self.buf)>1: dc.DrawLines([f(*i) for i in self.buf]) for i in self.buf:dc.DrawCircle(f(*i),2)
def draw(self, dc, f, **key): dc.SetPen(wx.Pen(Setting['color'], width=1, style=wx.SOLID)) dc.SetTextForeground(Setting['tcolor']) font = wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False) dc.SetFont(font) for i in self.body: x,y = f(*i) unit = 1 if self.unit is None else self.unit[0] dc.DrawCircle(x, y, 2) dc.DrawText('(%.1f,%.1f)'%(i[0]*unit, i[1]*unit), x, y)
def __init__( self, parent=None, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL|wx.NO_BORDER|wx.FULL_REPAINT_ON_RESIZE, name='SquareMap', model = None, adapter = None, labels = True, # set to True to draw textual labels within the boxes highlight = True, # set to False to turn of highlighting padding = 2, # amount to reduce the children's box from the parent's box ): super( SquareMap, self ).__init__( parent, id, pos, size, style, name ) self.model = model self.padding = padding self.labels = labels self.highlight = highlight self.selectedNode = None self.highlightedNode = None self.Bind( wx.EVT_PAINT, self.OnPaint) self.Bind( wx.EVT_SIZE, self.OnSize ) if highlight: self.Bind( wx.EVT_MOTION, self.OnMouse ) self.Bind( wx.EVT_LEFT_UP, self.OnClickRelease ) self.Bind( wx.EVT_LEFT_DCLICK, self.OnDoubleClick ) self.Bind( wx.EVT_KEY_UP, self.OnKeyUp ) self.hot_map = [] self.adapter = adapter or DefaultAdapter() self.DEFAULT_PEN = wx.Pen( wx.BLACK, 1, wx.SOLID ) self.SELECTED_PEN = wx.Pen( wx.WHITE, 2, wx.SOLID ) self.OnSize(None)
def draw_bitmap_rectangle(bitmap, faces): """Draw rectangle on bitmap.""" dc = wx.MemoryDC(bitmap.bmp) dc.SetPen(wx.BLUE_PEN) dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.SetTextBackground('black') dc.SetTextForeground('white') dc.SetBackgroundMode(wx.SOLID) dc.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)) for face in faces: dc.DrawRectangle( face.rect.left * bitmap.scale, face.rect.top * bitmap.scale, face.rect.width * bitmap.scale, face.rect.height * bitmap.scale, ) if face.name: text_width, text_height = dc.GetTextExtent(face.name) dc.DrawText(face.name, face.rect.left * bitmap.scale, face.rect.top * bitmap.scale - text_height) dc.SelectObject(wx.NullBitmap) bitmap.bitmap.SetBitmap(bitmap.bmp)
def DrawValue(self, dc, rect, property, text): print 'DrawValue:', text #dc.SetPen( wxPen(propertyGrid->GetCellTextColour(), 1, wxSOLID) ) #pen = dc.GetPen() #print pen.GetColour(), pen.GetStyle(), wx.PENSTYLE_SOLID #dc.SetPen(wx.Pen(wx.Colour(0, 0, 255, 255), 1, wx.SOLID)) cell_renderer = property.GetCellRenderer(1) cell_renderer.DrawText(dc, rect, 0, text) # property.get_value())#rect.x+15, rect.y) #dc.DrawText(property.get_value(), rect.x+15, rect.y) # if not property.IsValueUnspecified(): # dc.DrawText(property.get_value(), rect.x+5, rect.y)
def create_background(self): w,h = self.GetSize() self.background_bitmap = wx.EmptyBitmap(w, h) dc = wx.MemoryDC(self.background_bitmap) gc = wx.GraphicsContext_Create(dc) dc.SetBrush(wx.Brush("#FFFFFF")) dc.Clear() dc.DrawRectangle(0,0,w,h) off = h // self.chnls // 2 gc.SetPen(wx.Pen('#000000', width=1, style=wx.SOLID)) gc.SetBrush(wx.Brush("#FFFFFF", style=wx.TRANSPARENT)) dc.SetTextForeground("#444444") if sys.platform in "darwin": font, ptsize = dc.GetFont(), dc.GetFont().GetPointSize() font.SetPointSize(ptsize - 3) dc.SetFont(font) else: font = dc.GetFont() font.SetPointSize(8) dc.SetFont(font) tickstep = w // 10 if tickstep < 40: timelabel = "%.1f" elif tickstep < 80: timelabel = "%.2f" elif tickstep < 120: timelabel = "%.3f" else: timelabel = "%.4f" timestep = (self.end - self.begin) * 0.1 for i, samples in enumerate(self.img): y = h // self.chnls * i if len(samples): gc.DrawLines(samples) dc.SetPen(wx.Pen('#888888', width=1, style=wx.DOT)) dc.DrawLine(0, y+off, w, y+off) # for j in range(10): # dc.SetPen(wx.Pen('#888888', width=1, style=wx.DOT)) # dc.DrawLine(j*tickstep, 0, j*tickstep, h) # dc.DrawText(timelabel % (self.begin+j*timestep), j*tickstep+2, h-y-12) dc.SetPen(wx.Pen('#000000', width=1)) dc.DrawLine(0, h-y, w, h-y) dc.SelectObject(wx.NullBitmap)
def __init__( self, parent=None, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL|wx.NO_BORDER|wx.FULL_REPAINT_ON_RESIZE, name='SquareMap', model = None, adapter = None, labels = True, highlight = True, padding = 2, margin = 0, square_style = False, ): """Initialise the SquareMap adapter -- a DefaultAdapter or same-interface instance providing SquareMap data api labels -- set to True (default) to draw textual labels within the boxes highlight -- set to True (default) to highlight nodes on mouse-over padding -- spacing within each square and its children (within the square's border) margin -- spacing around each square (on all sides) square_style -- use a more-recursive, less-linear, more "square" layout style which works better on objects with large numbers of children, such as Meliae memory dumps, works fine on profile views as well, but the layout is less obvious wrt what node is "next" "previous" etc. """ super( SquareMap, self ).__init__( parent, id, pos, size, style, name ) self.model = model self.padding = padding self.square_style = square_style self.margin = margin self.labels = labels self.highlight = highlight self.selectedNode = None self.highlightedNode = None self._buffer = wx.Bitmap(20, 20) # Have a default buffer ready self.Bind( wx.EVT_PAINT, self.OnPaint) self.Bind( wx.EVT_SIZE, self.OnSize ) if highlight: self.Bind( wx.EVT_MOTION, self.OnMouse ) self.Bind( wx.EVT_LEFT_UP, self.OnClickRelease ) self.Bind( wx.EVT_LEFT_DCLICK, self.OnDoubleClick ) self.Bind( wx.EVT_KEY_UP, self.OnKeyUp ) self.hot_map = [] self.adapter = adapter or DefaultAdapter() self.DEFAULT_PEN = wx.Pen( wx.BLACK, 1, wx.SOLID ) self.SELECTED_PEN = wx.Pen( wx.WHITE, 2, wx.SOLID ) self.OnSize(None)
def draw(self, dc, f, **key): dc.SetPen(wx.Pen((255,255,0), width=1, style=wx.SOLID)) dc.SetTextForeground((255,255,0)) font = wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False) dc.SetFont(font) data = self.data[0 if len(self.data)==1 else key['cur']] for i in range(len(data)): pos = f(*(data[i][0], data[i][1])) dc.SetBrush(wx.Brush((255,255,255))) dc.DrawCircle(pos[0], pos[1], 2) dc.SetBrush(wx.Brush((0,0,0), wx.BRUSHSTYLE_TRANSPARENT)) dc.DrawCircle(pos[0], pos[1], data[i][2]*key['k']) dc.DrawText('id={}, r={}'.format(i, data[i][2]), pos[0], pos[1])