def __init__(self, parent): wx.ScrolledWindow.__init__(self, parent, -1) self.SetBackgroundColour(wx.Colour(0,128,0)) # A reference bitmap that we won't mask self.bmp_nomask = images.TestStar2.GetBitmap() # One that we will self.bmp_withmask = images.TestStar2.GetBitmap() # This mask comes from a monochrome bitmap self.bmp_themask = images.TestMask.GetImage().ConvertToMonoBitmap(red=255, green=255, blue=255) mask = wx.Mask(self.bmp_themask) # Set the mask on our bitmap self.bmp_withmask.SetMask(mask) # Now we'll create a mask in a bit of an easier way, by picking a # colour in the image that is to be the transparent colour. self.bmp_withcolourmask = images.TestStar2.GetBitmap() mask = wx.Mask(self.bmp_withcolourmask, wx.WHITE) self.bmp_withcolourmask.SetMask(mask) self.SetScrollbars(20, 20, 700//20, 460//20) self.Bind(wx.EVT_PAINT, self.OnPaint)
def test_BitmapMask(self): img = wx.Image(pngFile) img = img.ConvertToMono(0, 0, 0) bmp = wx.Bitmap(img, 1) m = wx.Mask() m = wx.Mask(bmp) m = wx.Mask(bmp, wx.Colour(1, 2, 3))
def __init__(self, parent, log): wx.Panel.__init__(self, parent, -1, style=wx.NO_FULL_REPAINT_ON_RESIZE) self.log = log if 0: # a test case for catching wx.PyAssertionError #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_SUPPRESS) #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_EXCEPTION) #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_DIALOG) #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_EXCEPTION | wx.PYAPP_ASSERT_DIALOG) try: bmp = wx.Bitmap("nosuchfile.bmp", wx.BITMAP_TYPE_BMP) mask = wx.Mask(bmp, wx.BLUE) except wx.PyAssertionError: self.log.write( "Caught wx.PyAssertionError! I will fix the problem.\n") bmp = images.getTest2Bitmap() mask = wx.MaskColour(bmp, wx.BLUE) else: bmp = images.getTest2Bitmap() mask = wx.Mask(bmp, wx.BLUE) bmp.SetMask(mask) b = wx.BitmapButton(self, 30, bmp, (20, 20), (bmp.GetWidth() + 10, bmp.GetHeight() + 10)) b.SetToolTipString("This is a bitmap button.") self.Bind(wx.EVT_BUTTON, self.OnClick, b)
def process( self,dc,values): hue=values['hue'] import wx src=dc.GetAsBitmap() w,h=dc.GetSizeTuple() #Fill dc with blank newdc=wx.MemoryDC() white=wx.EmptyBitmapRGBA(w,h,255,255,255,0) newdc.SelectObject(white) newdc.Brush=wx.Brush(wx.NamedColour('white'),wx.SOLID) newdc.DrawRectangle(0,0,w,h) #First apply chips mask on the pict mask=wx.Mask(wx.Bitmap('plugins/chips/chips_mask.png'),wx.NamedColour('white')) src.SetMask(mask) newdc.DrawBitmap(src,0,0,True) #Then apply chip border on the pict img=wx.Image('plugins/chips/chips_border.png') img.RotateHue(hue) bmp=wx.BitmapFromImage(img) #bmp=wx.Bitmap('plugins/chips/chips_border.png') mask=wx.Mask(wx.Bitmap('plugins/chips/chips_border_mask.png'),wx.NamedColour('white')) bmp.SetMask(mask) newdc.DrawBitmap(bmp,0,0,True) newdc.SelectObject(wx.NullBitmap) del newdc #Now, clear the old one & paste the modified bitmap dc.Clear() #dc.SetBrush(wx.Brush(wx.NamedColour('white'),wx.SOLID)) #dc.DrawRectangle(0,0,w,h) #dc.DrawBitmap(white),0,0) dc.DrawBitmap(wx.BitmapFromImage(white.ConvertToImage()),0,0)
def __init__(self, parent): """ Standardconstructor. @type parent: view.workspace.CabelFrame @param parent: Parent frame. """ wx.StatusBar.__init__(self, parent, -1) Observer.__init__(self) # Config Vars Csound self.config = parent._controller._model.config.csound # View workspace self.workspace = parent self.workspace._controller._model.addObserver(self) # Number of Fields and it's widths self.SetFieldsCount(4) self.SetStatusWidths([-3, 80, 60, 115]) self.Bind(wx.EVT_SIZE, self.onSize) #play button self.playBmp = wx.Bitmap( os.path.join(os.getcwd(), 'stuff', 'play.jpg'), wx.BITMAP_TYPE_JPEG) playMask = wx.Mask(self.playBmp, wx.LIGHT_GREY) self.stopBmp = wx.Bitmap( os.path.join(os.getcwd(), 'stuff', 'stop.jpg'), wx.BITMAP_TYPE_JPEG) stopMask = wx.Mask(self.stopBmp, wx.LIGHT_GREY) self.playBmp.SetMask(playMask) self.stopBmp.SetMask(stopMask) self.playBtn = wx.BitmapButton(self, wx.NewId(), self.playBmp) self.playBtn.SetToolTipString("Start Csound. [CTRL-Y]") self.Bind(wx.EVT_BUTTON, self.onPlayStopButton, self.playBtn) #autoplay checkbox self.autoplayCb = wx.CheckBox(self, wx.NewId(), "autoplay") self.Bind(wx.EVT_CHECKBOX, self.onAutoplayCheckBox, self.autoplayCb) self.autoplayCb.SetValue( self.config.getVal(tools.config.Csound.AUTOPLAY)) #zoom combobox self.zoomTxtCtrl = wx.TextCtrl(self, wx.NewId(), str(self.workspace.zoom) + ' %', style=wx.TE_PROCESS_ENTER | wx.TE_RIGHT) self.zoomTxtCtrl.SetToolTipString("Zoom the Modules on the Workspace.") self.Bind(wx.EVT_TEXT_ENTER, self.onZoomEntered, self.zoomTxtCtrl) self._reposition() self._play = False
def AddColumnDefn(self, defn): # Enlève l'espace gauche sur tous les headers du listctrl sous Phoenix en ajoutant une image transparente if 'phoenix' in wx.PlatformInfo: if defn.headerImage == -1 : smallImage = wx.Bitmap(16, 16) mask = wx.Mask(smallImage, wx.BLACK) smallImage.SetMask(mask) self.smallImageList.AddNamedImage("vide", smallImage) normalImage = wx.Bitmap(32, 32) mask = wx.Mask(normalImage, wx.BLACK) normalImage.SetMask(mask) self.normalImageList.AddNamedImage("vide", normalImage) defn.headerImage = "vide" super(ObjectListView, self).AddColumnDefn(defn)
def Draw(self, dc = None): global model, hubsize (width, height) = self.GetSizeTuple() if not dc: dc = wx.ClientDC(self) if (self._BackgroundBuffer == None): self.UpdateBackground() if ((self._ForegroundMaskBuffer == None) or model.has_changed()): self.UpdateForegroundMask() model.set_changed(False) BlitBuffer = wx.EmptyBitmap(width, height) blitdc = wx.MemoryDC() blitdc.SelectObject(BlitBuffer) blitdc.DrawBitmap(self._BackgroundBuffer,0,0) self.mask = wx.Mask(self._ForegroundMaskBuffer, wx.WHITE) # mask with white transparent self.RedBuffer.SetMask(self.mask) blitdc.DrawBitmap(self.RedBuffer,0,0, True) blitdc.SelectObject(wx.NullBitmap) dc.DrawBitmap(BlitBuffer, 0, 0)
def layout(self): self.mainSizer = wx.BoxSizer(wx.VERTICAL) hSizer = wx.BoxSizer(wx.HORIZONTAL) img = wx.Image(self.photoMaxWidth, self.photoMaxHeight) # img.Replace(0, 0, 0, 255, 255, 255) # change empty image to grey bmp = wx.Bitmap(img) mask = wx.Mask(bmp, wx.BLACK) bmp.SetMask(mask) img = bmp.ConvertToImage() self.imageCtrl = wx.StaticBitmap(self, wx.ID_ANY, wx.Bitmap(img)) self.photoTxt = wx.TextCtrl(self, size=(self.photoMaxHeight - 200, -1)) self.photoTxt.Bind(wx.EVT_SET_FOCUS, self.onFocus) self.photoTxt.Bind(wx.EVT_KILL_FOCUS, self.onKillFocus) loadImageButton = wx.Button(self, label='URL Image') loadImageButton.Bind(wx.EVT_BUTTON, self.onLoad) self.imageLabel = wx.StaticText(self, label="") self.imageLoaded = False openClientButton = wx.Button(self, label='Client Image') openClientButton.Bind(wx.EVT_BUTTON, self.onOpenClient) hSizer.Add(self.photoTxt, 0, wx.ALL, 5) hSizer.Add(loadImageButton, 0, wx.ALL, 5) hSizer.Add(openClientButton, 0, wx.ALL, 5) self.mainSizer.Add(hSizer, 0, wx.CENTER) self.mainSizer.Add(self.imageCtrl, 0, wx.ALL | wx.CENTER, 10) self.mainSizer.Add(self.imageLabel, 0, wx.ALL | wx.CENTER, 5) self.SetSizer(self.mainSizer)
def __init__(self, parent, title, app, input, output): wx.Frame.__init__(self, parent, title=title, size=(900, 680), style=wx.FRAME_SHAPED | wx.NO_FULL_REPAINT_ON_RESIZE | wx.CLIP_CHILDREN) self.SetDoubleBuffered(True) # Things like the XButton need access to the app, so that they can tell the app to exit self.panel = LauncherPanel(self) self.panel.app = app # output is how we send stuff to the launcher self.panel.output = output # input is how the launcher sends stuff to us self.panel.input = input self.Centre() shape = Background.Alpha.GetBitmap() shape.SetMask(wx.Mask(shape, wx.WHITE)) self.SetShape(wx.RegionFromBitmap(shape)) self.Show()
def __init__(self, parent, ID, bmp1): wx.ScrolledWindow.__init__(self, parent, ID) self.shapes = [] self.dragImage = None self.dragShape = None self.hiliteShape = None self.SetCursor(wx.Cursor(wx.CURSOR_ARROW)) shape = DragShape(bmp1) shape.pos = (200, 5) self.shapes.append(shape) text = "Some Text" bg_colour = wx.Colour(115, 115, 115) # matches the bg image font = wx.Font(15, wx.FONTFAMILY_ROMAN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD) textExtent = self.GetFullTextExtent(text, font) bmp = wx.Bitmap(textExtent[0], textExtent[1]) dc = wx.MemoryDC() dc.SelectObject(bmp) dc.SetBackground(wx.Brush(bg_colour, wx.BRUSHSTYLE_SOLID)) dc.Clear() dc.SelectObject(wx.NullBitmap) mask = wx.Mask(bmp, bg_colour) bmp.SetMask(mask) self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_MIDDLE_DOWN, self.OnMidDown) self.Bind(wx.EVT_MIDDLE_UP, self.OnMidUp) self.Bind(wx.EVT_MOTION, self.OnMotion) self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow) self.Bind(wx.EVT_MOUSEWHEEL, self.OnWheel)
def MakeColorDropperBitmap(self): dc = wx.MemoryDC(wx.EmptyBitmap(*self.GetClientSize())) dc_SetBrush = dc.SetBrush # dc_SetPen = dc.SetPen maskColor = self.maskColor dc_SetBrush(wx.Brush(maskColor)) dc.Clear() # dc.DrawRectangle(x=0, y=0, width=self.Size[0], height=self.Size[1]) w, h = self.GetClientSize() frameColor = self.frameColor dc_SetBrush(wx.Brush(frameColor)) # compFrameColor = GetComplementaryColor(frameColor) # dc.SetPen(wx.Pen(compFrameColor)) dc.SetPen(wx.Pen(frameColor)) minWH = min(w, h) maxWH = max(w, h) minWH2 = min(w, h) // 2 maxWH2 = max(w, h) // 2 dc.DrawCircle(x=w // 2, y=h // 2, radius=minWH2) if w > h: dc.DrawRectangle(x=maxWH2 - minWH2, y=minWH2, width=minWH2, height=minWH2) elif w < h: dc.DrawRectangle(x=0, y=maxWH2, width=minWH2, height=minWH2 + 1) else: dc.DrawRectangle(x=0, y=maxWH2, width=minWH2, height=minWH2) bmp = dc.GetAsBitmap((0, 0, w, h)) bmp.SetMaskColour(maskColor) mask = wx.Mask(bmp, maskColor) bmp.SetMask(mask) self.bmp = bmp
def __init__(self, parent, id, log, size = wx.DefaultSize): wx.ScrolledWindow.__init__(self, parent, id, (0, 0), size=size, style=wx.SUNKEN_BORDER) self.lines = [] self.maxWidth = W self.maxHeight = H self.x = self.y = 0 self.curLine = [] self.drawing = False self.SetBackgroundColour("WHITE") bmp = images.Test2.GetBitmap() mask = wx.Mask(bmp, wx.BLUE) bmp.SetMask(mask) self.bmp = bmp self.SetVirtualSize((self.maxWidth, self.maxHeight)) self.SetScrollRate(20,20) # create a PseudoDC to record our drawing self.pdc = wx.PseudoDC() self.pen_cache = {} self.brush_cache = {} self.DoDrawing(self.pdc) log.write('Created PseudoDC draw list with %d operations!'%self.pdc.GetLen()) self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x:None) self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse) # vars for handling mouse clicks self.dragid = -1 self.lastpos = (0,0)
def __init__(self, parent, id=-1, size=wx.DefaultSize): wx.ScrolledWindow.__init__(self, parent, id, (0, 0), size=size, style=wx.SUNKEN_BORDER) self.lines = [] self.maxWidth = 1000 self.maxHeight = 1000 self.x = self.y = 0 self.curLine = [] self.drawing = False self.SetBackgroundColour("WHITE") self.SetCursor(wx.StockCursor(wx.CURSOR_PENCIL)) bmp = images.getTest2Bitmap() mask = wx.Mask(bmp, wx.BLUE) bmp.SetMask(mask) self.bmp = bmp self.SetScrollbars(20, 20, self.maxWidth / 20, self.maxHeight / 20) if BUFFERED: # Initialize the buffer bitmap. No real DC is needed at this point. self.buffer = wx.EmptyBitmap(self.maxWidth, self.maxHeight) dc = wx.BufferedDC(None, self.buffer) dc.SetBackground(wx.Brush(self.GetBackgroundColour())) dc.Clear() self.DoDrawing(dc) self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftButtonEvent) self.Bind(wx.EVT_LEFT_UP, self.OnLeftButtonEvent) self.Bind(wx.EVT_MOTION, self.OnLeftButtonEvent) self.Bind(wx.EVT_PAINT, self.OnPaint)
def ShadowBitmap(self, bmp, shadowcolour): """ Applies A Mask On The Bitmap Accordingly To User Input. """ mask = wx.Mask(bmp, shadowcolour) bmp.SetMask(mask) return bmp
def get_image_data(filename, mask=None, type_=wx.BITMAP_TYPE_PNG, raw=False): """Devuelve data de imagen compatible con ImageResource filename: Path del archivo mask: Mask de transparencia para aplicar a bmp type_: Tipo de imagen para la data raw: Si es true se lee archivo en modo binario sin transformaciones """ if raw: # Si es raw ignora mask e type_ data = get_file_data(filename, "rb") else: # Lee el archivo de imagen img = wx.Bitmap(filename, wx.BITMAP_TYPE_ANY) # Aplica mask si corresponde if not (mask is None): om = img.GetMask() nMask = wx.Mask(img, mask) img.SetMask(nMask) if om is not None: om.Destroy() # Graba archivo temporal con formato indicado tfname = "certempo_imagetemp.png" img.SaveFile(tfname, type_) # recupera data y elimina archivo temporal data = get_file_data(tfname, "rb") os.remove(tfname) return data
def OnSetTransparentMask(self, event): self.mDC.SelectObject(wx.NullBitmap) self.bmp.SetMask(wx.Mask(self.bmp, self.fgcol)) self.mDC.SelectObject(self.bmp) self.updateImageInfo() self.imageModified()
def drawXorLine( self, x, y ): if x is None or not self.times: return dc = wx.ClientDC( self ) dc.SetLogicalFunction( wx.XOR ) dc.SetPen( wx.WHITE_PEN ) winWidth, winHeight = self.GetClientSize() text = self.formatTime( self.tFromX(x) ) fontHeight = max(5, winHeight//20) font = wx.Font( (0,fontHeight), wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD ) dc.SetFont( font ) tWidth, tHeight = dc.GetTextExtent( text ) border = int(tHeight / 3) bm = wx.Bitmap( tWidth, tHeight ) memDC = wx.MemoryDC( bm ) memDC.SetBackground( wx.BLACK_BRUSH ) memDC.Clear() memDC.SetFont( font ) memDC.SetTextForeground( wx.WHITE ) memDC.DrawText( text, 0, 0 ) bmMask = wx.Bitmap( bm.ConvertToImage() ) bm.SetMask( wx.Mask(bmMask, wx.BLACK) ) dc.Blit( x+border, y - tHeight, tWidth, tHeight, memDC, 0, 0, useMask=True, logicalFunc=wx.XOR ) dc.DrawLine( x, 0, x, winHeight )
def convert(file, maskClr, outputDir, outputName, outType, outExt): img = wx.Bitmap(file, wx.BITMAP_TYPE_ANY) if not img.IsOk(): return 0, file + " failed to load!" else: if maskClr: om = img.GetMask() mask = wx.Mask(img, maskClr) img.SetMask(mask) if om is not None: om.Destroy() if outputName: newname = outputName else: newname = os.path.join( outputDir, os.path.basename(os.path.splitext(file)[0]) + outExt) if img.SaveFile(newname, outType): return 1, file + " converted to " + newname else: img = img.ConvertToImage() if img.SaveFile(newname, outType): return 1, "ok" else: return 0, file + " failed to save!"
def __init__(self, utility): ABCAction.__init__(self, utility, shortdesc='separator') self.menudesc = "--------------" mask = wx.Mask(wx.EmptyBitmap(24, 24)) self.bitmap = wx.EmptyBitmap(24, 24) self.bitmap.SetMask(mask)
def Get(self, l, r): s = "" + self.s_line for i in range(5): if i < (5 - l): sl = self.sl_off else: sl = self.sl_on if i < (5 - r): sr = self.sr_off else: sr = self.sr_on s += self.s_border + sl + self.s_point + sr + self.s_point s += self.s_border + sl + self.s_point + sr + self.s_point s += self.s_line image = wx.EmptyImage(16, 16) image.SetData(s) bmp = image.ConvertToBitmap() bmp.SetMask(wx.Mask(bmp, wx.WHITE)) #sets the transparency colour to white icon = wx.EmptyIcon() icon.CopyFromBitmap(bmp) return icon
def __init__(self, width=7, height=7): self.width = width self.height = height self.centerX = int((self.width - 1) / 2) self.centerY = int((self.height - 1) / 2) if wx.Platform != "__WXMAC__": # WX on some macs does not support monochrome bitmaps which # are necessary for bitmap masks. Thus we don't need to do # anything here dc = wx.MemoryDC() # Create the mask bitmap cursorMask = wx.Bitmap(self.width, self.height, depth=1) dc.SelectObject(cursorMask) dc.SetPen(wx.Pen(wx.Colour(255, 255, 255), width=3)) dc.DrawLine(0, self.centerY, self.width - 1, self.centerY) dc.DrawLine(self.centerX, 0, self.centerX, self.height - 1) # Create the cursor bitmap self.cursorBitmap = wx.Bitmap(self.width, self.height) dc.SelectObject(self.cursorBitmap) dc.SetPen(wx.Pen(wx.Colour(255, 255, 0))) dc.DrawLine(0, self.centerY, self.width - 1, self.centerY) dc.DrawLine(self.centerX, 0, self.centerX, self.height - 1) self.cursorBitmap.SetMask(wx.Mask(cursorMask)) # done with dc del dc
def __init__(self, parent, label_bitmap=None, selected_bitmap=None, toggled=False): # An image toggle button GenBitmapToggleButton.__init__(self, parent, id=-1, bitmap=None) if label_bitmap <> None: mask = wx.Mask(label_bitmap, wx.BLUE) label_bitmap.SetMask(mask) self.SetBitmapLabel(label_bitmap) if selected_bitmap <> None: mask = wx.Mask(selected_bitmap, wx.BLUE) selected_bitmap.SetMask(mask) self.SetBitmapSelected(selected_bitmap) self.SetToggle(toggled) self.SetInitialSize()
def ShadowBitmap(self, bmp, shadowcolour): """ Applies a mask on the bitmap accordingly to user input. """ mask = wx.Mask(bmp, shadowcolour) bmp.SetMask(mask) return bmp
def __init__(self, parent, bitmap_list): assert len(bitmap_list) > 0 self.bitmap_list = [] for bmp in bitmap_list: if '__WXMSW__' not in wx.PlatformInfo: # Setting a mask fails on Windows. # Therefore transparency is set only for other platforms mask = wx.Mask(bmp, wx.BLUE) bmp.SetMask(mask) self.bitmap_list.append(bmp) self.state = 0 super(BitmapToggleButton, self).__init__(parent, -1, self.bitmap_list[0], style=wx.BORDER_NONE) # For compatibility with toggle buttons setattr(self, "GetToolState", lambda x: self.state) self.Bind(wx.EVT_LEFT_UP, self.toggle, self)
def convert(file, maskClr, outputDir, outputName, outType, outExt): if os.path.splitext(file)[1].lower() == ".ico": icon = wx.Icon(file, wx.BITMAP_TYPE_ICO) img = wx.BitmapFromIcon(icon) else: img = wx.Bitmap(file, wx.BITMAP_TYPE_ANY) if not img.Ok(): return 0, file + " failed to load!" else: if maskClr: om = img.GetMask() mask = wx.Mask(img, maskClr) img.SetMask(mask) if om is not None: om.Destroy() if outputName: newname = outputName else: newname = os.path.join( outputDir, os.path.basename(os.path.splitext(file)[0]) + outExt) if img.SaveFile(newname, outType): return 1, file + " converted to " + newname else: img = wx.ImageFromBitmap(img) if img.SaveFile(newname, outType): return 1, "ok" else: return 0, file + " failed to save!"
def __set_bitmaps__(self, dw=400, dh=800): imageDir = "/home/e4ms/job_tracking/images/" imageList = ["red_button.png", "green_button.png", "gray_button.png"] bitmaps = [] bitmap_padding = 20 bitmapWidth = ((dw - (2 * self.gridSizerBorder) - self.grid_gap) / self.grids) - self.grid_gap - (2 * bitmap_padding) bitmapHeight = ((dh - (2 * self.gridSizerBorder) - self.grid_gap) / self.grids) - self.grid_gap - (2 * bitmap_padding) #bitmapWidth = (dw - 2 * self.gridSizerBorder - self.grid_gap)/self.grids - 2 * bitmap_padding #bitmapHeight = (dh - 2*self.gridSizerBorder - self.grid_gap) / self.grids - 2 * bitmap_padding #print dw,dh,bitmapWidth,bitmapHeight bitmapScale = bitmapHeight if bitmapHeight < bitmapWidth else bitmapWidth for image in imageList: bitmap = wx.Image(imageDir + image) W, H = bitmap.GetSize() proportion = float(W) / float(H) scaleH = bitmapScale scaleW = scaleH * proportion bitmap = bitmap.Scale(scaleW, scaleH, wx.IMAGE_QUALITY_HIGH) bitmaps.append(wx.BitmapFromImage(bitmap)) mask = wx.Mask(bitmaps[-1], wx.WHITE) bitmaps[-1].SetMask(mask) self.bitmaps = { "machineUp": bitmaps[1], "machineDown": bitmaps[0], "noMachine": bitmaps[2] }
def process(self, dc, values): from math import cos, sin, radians, pi olddc = dc w, h = olddc.GetSizeTuple() width = 1 #values['width'] fill = True #values['Fill'] scale = values['Scale'] dc = wx.MemoryDC() white = wx.EmptyBitmapRGBA(w, h, 255, 255, 255, 0) dc.SelectObject(white) #Fill with white dc.SetBrush(wx.Brush(wx.NamedColour('white'), wx.SOLID)) dc.DrawRectangle(0, 0, w, h) minimum = min(h, w) / 2 minimum *= scale dc.SetBrush(wx.Brush("black", wx.SOLID)) dc.DrawCircle(w / 2, h / 2, minimum) #Done with the drawing. dc.SelectObject(wx.NullBitmap) mask = wx.Mask(white, wx.NamedColour('white')) bmp = olddc.GetAsBitmap() bmp.SetMask(mask) dc = olddc dc.SetBrush(wx.Brush(wx.NamedColour('white'), wx.SOLID)) dc.DrawRectangle(0, 0, w, h) dc.DrawBitmap(bmp, 0, 0, True)
def draw_stop(self, dc): stop_pt = self.get_stop_point() stream = StringIO.StringIO(RED_DOT) image = wx.ImageFromStream(stream) bitmap = wx.BitmapFromImage(image) mask = wx.Mask(bitmap, wx.WHITE) bitmap.SetMask(mask) dc.DrawBitmap(bitmap, stop_pt.x - 12, stop_pt.y - 12, True)
def draw_marker(self, dc): rect = self.get_marker_rect() stream = StringIO.StringIO(MARKER) image = wx.ImageFromStream(stream) bitmap = wx.BitmapFromImage(image) mask = wx.Mask(bitmap, wx.WHITE) bitmap.SetMask(mask) dc.DrawBitmap(bitmap, rect.x, rect.y, True)
def loadImage( s ): print "Image %s loaded" % s a = wx.Bitmap( s ) bitmask = wx.Mask( a, wx.Colour( 255, 0, 128 ) ) a.SetMask( bitmask ) buff = wx.MemoryDC() buff.SelectObject( a ) return buff