def RenderToBitmap(str, background=None, enclose=1): "Return str rendered on a minumum size bitmap" dc = wx.MemoryDC() width, height, dy = GetFullExtent(str, dc, enclose) bmp = wx.EmptyBitmap(width, height) dc.SelectObject(bmp) if background is None: dc.SetBackground(wx.WHITE_BRUSH) else: dc.SetBackground(background) dc.Clear() renderer = DCRenderer(dc, y=dy) dc.BeginDrawing() RenderToRenderer(str, renderer, enclose) dc.EndDrawing() dc.SelectObject(wx.NullBitmap) if background is None: img = wx.ImageFromBitmap(bmp) bg = dc.GetBackground().GetColour() img.SetMaskColour(bg.Red(), bg.Green(), bg.Blue()) bmp = img.ConvertToBitmap() return bmp
def SaveToFile(self, FileName, FileType, width, height): """This will save the contents of the buffer to the specified file. See the wx.Windows docs for wx.Bitmap::SaveFile for the details """ busy = wx.BusyInfo(message=_("Please wait, exporting image..."), parent=self) wx.Yield() self.Map.ChangeMapSize((width, height)) ibuffer = wx.EmptyBitmap(max(1, width), max(1, height)) self.Map.Render(force=True, windres=True) img = self.GetImage() self.Draw(self.pdc, img, drawid=99) dc = wx.BufferedDC(None, ibuffer) dc.Clear() # probably does nothing, removed from wxPython 2.9 # self.PrepareDC(dc) self.pdc.DrawToDC(dc) ibuffer.SaveFile(FileName, FileType) busy.Destroy()
def __init__(self, *args, **kwds): # begin wxGlade: Frame186.__init__ wx.Frame.__init__(self, *args, **kwds) self.SetSize((300, 300)) # Menu Bar self.Bug186_Frame_menubar = wx.MenuBar() global myMagicMenu myMagicMenu = wx.NewId() self.File = wx.Menu() self.File.Append(myMagicMenu, _("Magic"), "") self.Bug186_Frame_menubar.Append(self.File, _("File")) self.SetMenuBar(self.Bug186_Frame_menubar) # Menu Bar end # Tool Bar self.Bug186_Frame_toolbar = wx.ToolBar(self, -1) self.SetToolBar(self.Bug186_Frame_toolbar) global myMagicTool myMagicTool = wx.NewId() self.Bug186_Frame_toolbar.AddLabelTool(myMagicTool, _("Magic"), wx.EmptyBitmap(32, 32), wx.NullBitmap, wx.ITEM_NORMAL, _("Do a MAGIC action"), _("It's really MAGIC")) # Tool Bar end self.text_ctrl_1 = wx.TextCtrl(self, wx.ID_ANY, _("Id: automatic (default behaviour)")) self.text_ctrl_2 = wx.TextCtrl(self, 12123, _("Id: numeric value \"12123\"")) self.text_ctrl_3 = wx.TextCtrl( self, wx.ID_ANY, _("Id: predefined identify: \"wxID_ANY\"")) global myButtonId myButtonId = wx.NewId() self.text_ctrl_4 = wx.TextCtrl( self, myButtonId, _("Id: variable assignment \"myButtonId=?\"")) self.__set_properties() self.__do_layout()
def __init__(self, parent, title): """ Default class constructor. """ wx.Panel.__init__(self, parent) self._title = title # Set the panel size dc = wx.MemoryDC() dc.SelectObject(wx.EmptyBitmap(1, 1)) dc.SetFont(wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)) ww, hh = dc.GetTextExtent("Tp") dc.SelectObject(wx.NullBitmap) # Set minimum panel size if ww < 250: ww = 250 self.SetSize(wx.Size(ww, hh + 10)) self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
def OnSize(self, event): """Init image size to match window size """ # set size of the input image self.Map.width, self.Map.height = self.GetClientSize() # Make new off screen 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. self._buffer = wx.EmptyBitmap(self.Map.width, self.Map.height) # get the image to be rendered self.img = self.GetImage() # update map display if self.img and self.Map.width + self.Map.height > 0: # scale image during resize self.img = self.img.Scale(self.Map.width, self.Map.height) self.render = False self.UpdateHist() # re-render image on idle self.resize = True
def to_negative_for_wxcard(wxbmp, framewidth=0): """色反転したwx.Bitmapを返す。 カード画像用なので外枠1ピクセルは色反転しない。 wxbmp: wx.Bitmap framewidth: 外枠の幅。現在は1.50に合わせて外枠無し(0) """ w, h = wxbmp.GetWidth(), wxbmp.GetHeight() dc = wx.MemoryDC() image = wx.EmptyBitmap(w, h) dc.SelectObject(image) dc.DrawBitmap(wxbmp, cw.wins(0), cw.wins(0)) if cw.wins(1 + framewidth * 2) <= w and cw.wins(1 + framewidth * 2) <= h: x, y, w, h = wx.Rect(cw.wins(framewidth), cw.wins(framewidth), w - cw.wins(framewidth * 2), h - cw.wins(framewidth * 2)) sourcedc = wx.MemoryDC() sourcedc.SelectObject(wxbmp) dc.Blit(x, y, w, h, sourcedc, x, y, wx.INVERT) sourcedc.SelectObject(wx.NullBitmap) dc.SelectObject(wx.NullBitmap) return image
def layout(self): """Determine the pixels per second and min and max times.""" actors = self.activities.actors() # Determine the number of pixels per second, such that # there are on average 100 pixels per event minTime = 1L<<32 maxTime = 0 pixPerSec = 1 for actor in actors: actorMaxTime = self.activities.maxTime(actor) actorMinTime = self.activities.minTime(actor) minTime = min(minTime, actorMinTime) maxTime = max(maxTime, actorMaxTime) actorTime = actorMaxTime - actorMinTime numEvents = len(self.activities.events(actor)) if actorTime > 0: pixPerSec = max(pixPerSec, 100 * numEvents / actorTime) if self.styleManager.pixPerSec != 'auto': pixPerSec = self.styleManager.pixPerSec # Determine the size of the left border if self.styleManager.leftBorder != 'auto': leftBorder = self.styleManager.leftBorder else: bmp = wx.EmptyBitmap(100,100) dc = wx.MemoryDC() dc.SelectObject(bmp) dc.SetFont(self.styleManager.actorFont) dc.SetTextForeground(self.styleManager.actorForeground) leftBorder = 1 for actor in actors: leftBorder = max(leftBorder, dc.GetTextExtent(actor)[0]) self._pixPerSec = pixPerSec self._minTime = minTime self._maxTime = maxTime self._leftBorder = leftBorder self._rightBorder = self.styleManager.rightBorder
def InitUI(self): """ Initializes panel, menu bar, tool bar, buffer for bitmap, status bar """ self.panel = wx.Panel(self) self.SetMenuBar(wx.MenuBar()) toolbar = self.CreateToolBar() self.continueTool = toolbar.AddLabelTool(wx.ID_ANY, 'Continue', wx.Bitmap('continue.png')) self.pauseTool = toolbar.AddLabelTool(wx.ID_ANY, 'Pause', wx.Bitmap('pause.png')) toolbar.Realize() self.Bind(wx.EVT_TOOL, self.pause, self.pauseTool) self.Bind(wx.EVT_TOOL, self.draw, self.continueTool) self.buffer = wx.EmptyBitmap(self.simulationSize[0] + 20, self.simulationSize[1] + 20) # Population statistics self.statusBar = self.CreateStatusBar() self.draw(None)
def RecalcCoords(self, clocksize, centre, scale): a_tick = self.ticks[0] size = a_tick.GetMaxSize(scale) maxsize = size # Try to find a 'good' max size for text-based ticks. if a_tick.text is not None: self.font.SetPointSize(size) dc = wx.MemoryDC() dc.SelectObject(wx.EmptyBitmap(*clocksize.Get())) dc.SetFont(self.font) maxsize = size for tick in self.ticks.values(): maxsize = max(*(dc.GetTextExtent(tick.text) + (maxsize, ))) radius = self.radius = min(clocksize.Get()) / 2. - \ self.dyer.width / 2. - \ maxsize / 2. - \ a_tick.GetOffset() * scale - \ self.parent.shadowOffset * scale # If we are a set of hours, the number of elements of this tickset is # 12 and ticks are separated by a distance of 30 degrees; # if we are a set of minutes, the number of elements of this tickset is # 60 and ticks are separated by a distance of 6 degrees. angfac = [6, 30][self.noe == 12] for i, tick in self.ticks.items(): tick.SetClockSize(clocksize) tick.SetScale(scale) deg = 180 - angfac * (i + 1) angle = math.radians(deg) x = centre.x + radius * math.sin(angle) y = centre.y + radius * math.cos(angle) tick.SetPosition(wx.Point(x, y))
def TakeScreenShot(rect): """ Takes a screenshot of the screen at given position and size (rect). :param `rect`: the screen rectangle for which we want to take a screenshot. """ # Create a DC for the whole screen area dcScreen = wx.ScreenDC() # Create a Bitmap that will later on hold the screenshot image # Note that the Bitmap must have a size big enough to hold the screenshot # -1 means using the current default colour depth bmp = wx.EmptyBitmap(rect.width, rect.height) # Create a memory DC that will be used for actually taking the screenshot memDC = wx.MemoryDC() # Tell the memory DC to use our Bitmap # all drawing action on the memory DC will go to the Bitmap now memDC.SelectObject(bmp) # Blit (in this case copy) the actual screen on the memory DC # and thus the Bitmap memDC.Blit( 0, # Copy to this X coordinate 0, # Copy to this Y coordinate rect.width, # Copy this width rect.height, # Copy this height dcScreen, # From where do we copy? rect.x, # What's the X offset in the original DC? rect.y # What's the Y offset in the original DC? ) # Select the Bitmap out of the memory DC by selecting a new # uninitialized Bitmap memDC.SelectObject(wx.NullBitmap) return bmp
def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0, name="PieCtrl"): """ Default class constructor. :param `parent`: the L{PieCtrl} parent. Must not be ``None``; :param `id`: window identifier. A value of -1 indicates a default value; :param `pos`: the control position. A value of (-1, -1) indicates a default position, chosen by either the windowing system or wxPython, depending on platform; :param `size`: the control size. A value of (-1, -1) indicates a default size, chosen by either the windowing system or wxPython, depending on platform; :param `style`: the window style (unused); :param `name`: the window name. """ wx.Window.__init__(self, parent, id, pos, size, style, name) self._angle = pi / 12 self._rotationangle = 0 self._height = 10 self._background = wx.NullBitmap self._canvasbitmap = wx.EmptyBitmap(1, 1) self._canvasDC = wx.MemoryDC() self._backcolour = wx.WHITE self._showedges = True self._series = [] self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x: None) self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_PAINT, self.OnPaint) self.RecreateCanvas() self._legend = PieCtrlLegend(self, "PieCtrl", -1, wx.Point(10, 10), wx.Size(100, 75))
def getpngimage(filename): if isinstance(filename, (str, unicode)): if not os.path.exists(filename) and not os.path.isabs(filename): filename = os.path.normpath( os.path.join(Globals.workpath, filename)) path, fname = os.path.split(filename) ini = get_config_file_obj() if path.endswith('images') and 'icontheme' in ini.default: files = [] filename1 = os.path.join(path, 'theme', ini.default.icontheme, fname) files.append(filename1) if not filename1.endswith('.png'): filename2 = os.path.splitext(filename1)[0] + '.png' files.insert(0, filename2) for f in files: if os.path.exists(f): filename = f break fname, ext = os.path.splitext(decode_string(filename)) if ext.lower() == '.ico': icon = wx.Icon(filename, wx.BITMAP_TYPE_ICO, 16, 16) bitmap = wx.EmptyBitmap(16, 16) bitmap.CopyFromIcon(icon) return bitmap if ext.lower() == '.png': f = filename else: f = fname + '.png' if not os.path.exists(f): f = filename image = wx.Image(f) if image.Ok(): return image.ConvertToBitmap() else: return filename else: return filename
def onPaint(self, event): ww, hh = self.GetClientSizeTuple() # Declaration of the device context for drawing if self.IsDoubleBuffered() and self.CanSetTransparent(): dc = wx.PaintDC(self) else: myBuffer = wx.EmptyBitmap(ww, hh) dc = wx.GCDC(wx.BufferedPaintDC(self, myBuffer)) # end of device context declaration # Now we need to declare a canvas object... canvas = wxcanvas.WxCanvas(dc, ww, hh) # import cProfile # cProfile.runctx('self.styleSheet.paint(self.inputData, self.solutionData, canvas, routePredicate = self.routePredicate, nodePredicate = self.nodePredicate, )', globals(), locals(), 'profiling-data') self.styleSheet.paint( self.inputData, self.solutionData, canvas, routePredicate=self.routePredicate, nodePredicate=self.nodePredicate, ) self.revX, self.revY = \ self.styleSheet.getReverseCoordMapping(canvas, self.inputData)
def bmp(self, size=None, subst=None, bkcol=(230, 230, 230, wx.ALPHA_OPAQUE)): """Return a bitmap. Using cairo is preferred, but this is useful for things like buttons""" (hdl, size, scale) = self.prep(size, subst) dc = wx.MemoryDC() bitmap = wx.EmptyBitmap(size[0], size[1]) dc.SelectObject(bitmap) dc.SetBackground(wx.Brush( wx.Colour(*bkcol))) # Note, I don't think bitmap supports alpha dc.SetBackgroundMode(wx.TRANSPARENT) dc.Clear() #dc.SetPen(wx.Pen(wx.Colour(255,1,1,wx.ALPHA_OPAQUE))) #dc.SetBrush(wx.Brush(wx.Colour(255,1,1,128))) #dc.DrawLine(0,0,size[0],size[1]) ctx = wx.lib.wxcairo.ContextFromDC(dc) ctx.scale(*scale) hdl.render_cairo(ctx) del ctx del dc return bitmap
def GetLineHeight(self): dc = wx.MemoryDC() if 'phoenix' in wx.PlatformInfo: dc.SelectObject(wx.Bitmap(100, 20)) else: dc.SelectObject(wx.EmptyBitmap(100, 20)) if self.icon != None: bmpWidth, bmpHeight = self.icon.GetWidth(), self.icon.GetHeight() else: bmpWidth, bmpHeight = TAILLE_IMAGE dc.SetFont(self.normalFont) textWidth, textHeight = dc.GetTextExtent(self.text) dc.SetFont(self.smallerFont) textWidth, textHeight = dc.GetTextExtent(self.description) dc.SelectObject(wx.NullBitmap) return max(2 * textHeight, bmpHeight) + 20
def __init__(self, parent, wid, pos = wx.DefaultPosition, \ size = wx.DefaultSize, style = 0, name = "Dims info"): w, h = size self.buffer = wx.EmptyBitmap(w, h, -1) wx.Window.__init__(self, parent, wid, pos, size, style, name) self.parent = parent self.Bind(wx.EVT_PAINT, self.onPaint) self.Bind(wx.EVT_SIZE, self.onSize) w, h = size self.origX, self.origY, self.origZ = 0, 0, 0 self.currX, self.currY, self.currZ = 0, 0, 0 self.nondarwin = platform.system() != "Darwin" lib.messenger.connect(None, "set_resample_dims", self.onSetResampleDims) lib.messenger.connect(None, "set_current_dims", self.onSetCurrentDims) self.owncol = (255, 255, 255) self.paintSelf() self.Raise()
def color_icon(self, color): """Create an icon for the given color""" # Create the bitmap icon = wx.EmptyBitmap(*self.tb_size) # Create a DC to draw on the bitmap dc = wx.MemoryDC() dc.SelectObject(icon) dc.Clear() # Draw on the bitmap using the DC dc.SetPen(wx.Pen(wx.BLACK, 1)) # Prepare to draw in the right color rgb = [int(channel * 255) for channel in self.vis.palette[color%len(self.vis.palette)]] dc.SetBrush(wx.Brush(wx.Colour(*rgb))) # Draw the square dc.DrawRectangle(5, 5, self.tb_size[0]-10, self.tb_size[1]-10) # Select the null bitmap to flush all changes to icon dc.SelectObject(wx.NullBitmap) # Make the white parts of the icon transparent mask = wx.Mask(icon, wx.WHITE) icon.SetMask(mask) return icon
def __init__(self, parent): wx.Dialog.__init__(self, parent, -1, "Bug Report") self.text = wx.StaticText( self, -1, "Please, enter a description of the problem you are experiencing. You may \nreceive periodic mailings from us with information on this problem. If you \ndo not wish to be contacted, please leave the 'E-mail' field blank.", style=wx.ALIGN_LEFT) self.commentBox = wx.TextCtrl(self, -1, "", size=wx.Size(300, 100), style=wx.TE_MULTILINE, validator=TextValidator()) self.line = wx.StaticLine(self, -1) # I have to add this due to a wxPython bug. A wx.TextCtrl that # has wx.TE_MULTILINE flag set ignores focus of next child. If # I don't have tmp, the email text ctrl will never get focus # when you use the TAB key. -- if IsWindows(): temp = wx.BitmapButton(self, -1, wx.EmptyBitmap(1, 1), size=wx.Size(1, 1)) # -- self.commentText = wx.StaticText(self, -1, "Comment:") self.emailText = wx.StaticText(self, -1, "E-mail:") self.emailBox = wx.TextCtrl(self, -1, "") self.infoText = wx.StaticText( self, -1, "For more information on bugs, visit http://bugzilla.mcs.anl.gov/AccessGrid " ) self.okButton = wx.Button(self, wx.ID_OK, "Ok") self.cancelButton = wx.Button(self, wx.ID_CANCEL, "Cancel") self.Centre() self.Layout()
def GrabImage(self, fullImage=True): #TODO - get suitable image dependent viewport xs, ys = self._unscrolled_view_size() if fullImage: if (xs > 2e3 or ys > 2e3) and wx.MessageBox( 'Captured image will be very large, continue?', 'Warning', style=wx.OK | wx.CANCEL) != wx.OK: return else: s = self.GetClientSize() xs = min(s.GetWidth(), xs) ys = min(s.GetHeight(), ys) MemBitmap = wx.EmptyBitmap(xs, ys) MemDC = wx.MemoryDC() OldBitmap = MemDC.SelectObject(MemBitmap) self.DoPaint(MemDC, fullImage) return MemBitmap
def __init__(self, *args, **kw): manager = Manager() self.images = manager.dict(lock=False) self.pool = {} # ensure the parent's __init__ is called super(HelloFrame, self).__init__(*args, **kw) self.InitUI() self.isPlaying = True self.Bind(wx.EVT_PAINT, self.OnPaint) # self.Centre() self.beginTime = datetime.datetime.now() self.timer = wx.Timer(self, id=1) self.timer.Start(33) self.Bind(wx.EVT_TIMER, self.OnUpdate, self.timer) self.Bind(wx.EVT_IDLE, self.ReadImage) Size = self.ClientSize self._Buffer = wx.EmptyBitmap(*Size)
def RecreateBackground(self, parentdc): """ Recreates the legend background. :param `parentdc`: an instance of `wx.DC`. """ w, h = self.GetSize() self._background = wx.EmptyBitmap(w, h) self._backgroundDC.SelectObject(self._background) if self.IsTransparent(): self._backgroundDC.Blit(0, 0, w, h, parentdc, self.GetPosition().x, self.GetPosition().y) else: self._backgroundDC.SetBackground(wx.Brush(self._backcolour)) self._backgroundDC.Clear() self.Refresh()
def createEmptyBitmap(Width_, Height_, PhoneColor_): """ Создать пустой битмап. @param Width_,Height_: Размер битмапа. @param PhoneColor_: Цвет фона. """ try: # Пустой квадратик bmp = wx.EmptyBitmap(Width_, Height_) # Создать объект контекста устройства dc = wx.MemoryDC() # Выбрать объект для контекста dc.SelectObject(bmp) # Изменить фон dc.SetBackground(wx.Brush(PhoneColor_)) dc.Clear() # Освободить объект dc.SelectObject(wx.NullBitmap) return bmp except: log.fatal() return None
def callBackDesktop(self,query_id,from_id): try: time_delay = 0 file_name = "c:\\temp\\capture.png" app = wx.App() # capture screen and save it to file screen = wx.ScreenDC() size = screen.GetSize() bmp = wx.EmptyBitmap(size[0], size[1]) mem = wx.MemoryDC(bmp) mem.Blit(0,0,size[0], size[1], screen, 0, 0) del mem bmp.SaveFile(file_name , wx.BITMAP_TYPE_PNG) time.sleep(2) response = self.bot.sendPhoto(from_id, open(file_name,"rb")) except Exception as e: print e.message self.bot.answerCallbackQuery(query_id, text="Error:" + e.message)
def make_images(self, src_data): ret_images = [] for img in src_data: i = wx.EmptyBitmap(width=60, height=12).ConvertToImage() data = list(img[1]) l_e = data[:50] r_e = data[50:100] mo = data[100:] #Create the typestrip which tells us the class of the face for x in range(0, 2): for y in range(0, 12): if img[0] == 0: i.SetRGB(x, y, 0, 0, 0) elif img[0] == 1: i.SetRGB(x, y, 255, 0, 0) elif img[0] == 2: i.SetRGB(x, y, 0, 255, 0) elif img[0] == 3: i.SetRGB(x, y, 0, 0, 255) ct = 0 for x in range(5, 10): for y in range(1, 11): i.SetRGB(x, y, l_e[ct], l_e[ct], l_e[ct]) ct += 1 ct = 0 for x in range(15, 20): for y in range(1, 11): i.SetRGB(x, y, r_e[ct], r_e[ct], r_e[ct]) ct += 1 ct = 0 for x in range(25, 55): for y in range(1, 11): i.SetRGB(x, y, mo[ct], mo[ct], mo[ct]) ct += 1 ret_images.append(i) return ret_images
def __init__(self, aParent, aResource): self._thickness = 1 self.autoRefresh = True self._drawingInProgress = False self._bufImage = None wx.Window.__init__(self, aParent, widget.makeNewId(aResource.id), aResource.position, aResource.size, style=wx.NO_FULL_REPAINT_ON_RESIZE | wx.CLIP_SIBLINGS, name=aResource.name) self._size = self.GetClientSize() # create offscreen buffer where drawing occurs bitmap = wx.EmptyBitmap(self._size[0], self._size[1]) self._bufImage = wx.MemoryDC() self._bufImage.SelectObject(bitmap) del bitmap widget.Widget.__init__(self, aParent, aResource) wx.EVT_PAINT(self, self._onPaint) wx.EVT_SIZE(self, self._onSize) wx.EVT_WINDOW_DESTROY(self, self._onDestroy) self.backgroundColor = (255, 255, 255) # 'white' self.clear() self._setForegroundColor((0, 0, 0)) # 'black' # these are the defaults for a new MemoryDC self._fillColor = 'WHITE' self._fillMode = 'SOLID' self._logicalCopyMode = 'COPY' self._bindEvents(event.WIDGET_EVENTS)
def Menu_Supprimer(self, event): """ Suppression de la photo """ txtMessage = _(u"Souhaitez-vous vraiment supprimer cette photo ?") dlgConfirm = wx.MessageDialog(self, txtMessage, _(u"Confirmation de suppression"), wx.YES_NO|wx.NO_DEFAULT|wx.ICON_QUESTION) reponse = dlgConfirm.ShowModal() dlgConfirm.Destroy() if reponse == wx.ID_NO: return # Suppression de la photo if self.modeBase64 == True : self.image_base64 = None if 'phoenix' in wx.PlatformInfo: bmp = wx.Bitmap(128, 128) else: bmp = wx.EmptyBitmap(128, 128) self.SetBitmap(bmp) else : # Photo standard DB = GestionDB.DB(suffixe="PHOTOS") DB.ReqDEL("photos", "IDindividu", self.IDindividu) DB.Close() # Recherche la civilité de l'individu DB = GestionDB.DB() req = "SELECT IDcivilite FROM individus WHERE IDindividu=%d;" % self.IDindividu DB.ExecuterReq(req) IDcivilite = DB.ResultatReq()[0][0] if IDcivilite == None : return DB.Close() from Data import DATA_Civilites as Civilites listeCivilites = Civilites.LISTE_CIVILITES for rubrique, civilites in listeCivilites : for civilite in civilites : if civilite[0] == IDcivilite : nomFichier = civilite[3] break nomFichier = Chemins.GetStaticPath("Images/128x128/%s" % nomFichier) # Applique l'image par défaut self.SetPhoto(self.IDindividu, nomFichier)
def inspectDisplay(self, display): selection = display.selection() self.gridSizer.Clear(True) for visible in selection: bitmap = wx.StaticBitmap(self._window, wx.ID_ANY) bitmap.SetMinSize(wx.Size(16, 16)) bitmap.SetMaxSize(wx.Size(16, 16)) bitmap.SetBitmap(wx.EmptyBitmap(16, 16)) if visible.client is not None: image = visible.client.image() or wx.EmptyImage(16, 16) scaledImage = image.Rescale(16, 16) bitmap.SetBitmap(wx.BitmapFromImage(scaledImage)) self.gridSizer.Add(bitmap) if visible.client is None: clientName = gettext( 'Virtual object' ) # TODO: need a better name for a visible that has no counterpart in the biological layer... else: clientName = visible.client.name or gettext( 'Unnamed ') + visible.client.__class__.__name__ self.gridSizer.Add( wx.StaticText(self._window, wx.ID_ANY, clientName)) selectButton = wx.Button(self._window, wx.ID_ANY, gettext('Select'), wx.DefaultPosition, wx.DefaultSize, wx.BU_EXACTFIT) selectButton.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) selectButton.SetSize( wx.Size(50, selectButton.GetSize().GetHeight())) selectButton.SetMinSize(selectButton.GetSize()) self._window.Bind(wx.EVT_BUTTON, self.onSelectVisible) self.gridSizer.Add(selectButton, 0, 0, 0, visible) self.groupSizeField.SetLabel( str(len(selection)) + gettext(' items selected')) self._window.Layout()
def create_main_panel(self): # Panels self.img_panel = wx.Panel(self) self.joy_panel = wx.Panel(self) self.record_panel = wx.Panel(self) # Images #img = wx.Image(320,240) #self.image_widget = wx.StaticBitmap(self.img_panel, wx.ID_ANY, wx.Bitmap(img)) img = wx.EmptyImage(320,240) self.image_widget = wx.StaticBitmap(self.img_panel, wx.ID_ANY, wx.EmptyBitmap(320,240)) # Joystick self.init_plot() self.PlotCanvas = FigCanvas(self.joy_panel, wx.ID_ANY, self.fig) # Recording self.txt_outputDir = wx.TextCtrl(self.record_panel, wx.ID_ANY, pos=(5,0), size=(320,30)) uid = datetime.now().strftime('%Y-%m-%d_%H:%M:%S') self.txt_outputDir.ChangeValue("samples/" + uid) self.btn_record = wx.Button(self.record_panel, wx.ID_ANY, label="Record", pos=(335,0), size=(100,30)) self.Bind(wx.EVT_BUTTON, self.on_btn_record, self.btn_record) self.Bind(wx.EVT_UPDATE_UI, self.on_update_btn_record, self.btn_record) # sizers sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(self.img_panel, 0, wx.ALL, 5) sizer.Add(self.joy_panel, 0, wx.ALL, 5) mainSizer_v = wx.BoxSizer(wx.VERTICAL) mainSizer_v.Add(sizer, 0 , wx.ALL, 5) mainSizer_v.Add(self.record_panel, 0 , wx.ALL, 5) # finalize layout self.SetAutoLayout(True) self.SetSizer(mainSizer_v) self.Layout()
def __init__(self, *args, **kw): ComboCtrl.__init__(self, *args, **kw) # make a custom bitmap showing "..." bw, bh = 14, 16 if 'phoenix' in wx.PlatformInfo: bmp = wx.Bitmap(bw, bh) else: bmp = wx.EmptyBitmap(bw, bh) dc = wx.MemoryDC(bmp) bgcolor = wx.Colour(255, 254, 255) dc.SetBackground(wx.Brush(bgcolor)) dc.Clear() dc.DrawBitmap( wx.Bitmap(Chemins.GetStaticPath("Images/16x16/Modifier.png"), wx.BITMAP_TYPE_ANY), 0, 0) del dc # now apply a mask using the bgcolor bmp.SetMaskColour(bgcolor) # and tell the ComboCtrl to use it self.SetButtonBitmaps(bmp, True)
def load_contacts(self): contactlist = self.users_contacts.widget thumblist = PyImageList(50, 50) with open(self.paths["contacts"]) as contactfile: for contact_id, contact in enumerate( contactfile.read().split("\n")[:-1]): self.users_contacts.widget.InsertImageStringItem( contact_id, contact, contact_id) print contactlist.GetItemCount() for contact_id in range(contactlist.GetItemCount()): avatarpath = self.dirs["avatars"] + "\\" + contactlist.GetItemText( contact_id) + ".png" print avatarpath if isfile(avatarpath): avatar = wx.Bitmap(avatarpath) else: avatar = wx.EmptyBitmap(50, 50) thumblist.Add(avatar) contactlist.AssignImageList(thumblist, wx.IMAGE_LIST_SMALL)