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()
python类SOLID的实例源码
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((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)