def take_screenshot(fullscreen=True): """Returns a wx.Bitmap screenshot taken of fullscreen or program window.""" wx.YieldIfNeeded() if fullscreen: rect = wx.Rect(0, 0, *wx.DisplaySize()) else: window = wx.GetApp().TopWindow rect = window.GetRect() # adjust widths for Linux (figured out by John Torres # http://article.gmane.org/gmane.comp.python.wxpython/67327) if "linux2" == sys.platform: client_x, client_y = window.ClientToScreen((0, 0)) border_width = client_x - rect.x title_bar_height = client_y - rect.y rect.width += (border_width * 2) rect.height += title_bar_height + border_width dc = wx.ScreenDC() bmp = wx.EmptyBitmap(rect.width, rect.height) dc_bmp = wx.MemoryDC() dc_bmp.SelectObject(bmp) dc_bmp.Blit(0, 0, rect.width, rect.height, dc, rect.x, rect.y) dc_bmp.SelectObject(wx.NullBitmap) # Hack to drop screen transparency, wx issue when blitting from screen bmp = wx.BitmapFromIcon(wx.IconFromBitmap(bmp)) return bmp
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 create_bitmap_from_icon(icon): if IS_WXP4: bmp = wx.Bitmap(icon.GetWidth(), icon.getHeight()) bmp.CopyFromIcon(icon) return bmp else: return wx.BitmapFromIcon(icon)
def __init__(self, *args, **kwargs): kwargs[ 'agwStyle'] = fnb.FNB_NO_X_BUTTON | fnb.FNB_VC8 | fnb.FNB_SMART_TABS | fnb.FNB_NO_NAV_BUTTONS | fnb.FNB_DROPDOWN_TABS_LIST super(Notebook, self).__init__(*args, **kwargs) bitmap = wx.BitmapFromIcon(self.TopLevelParent.GetIcon()) if bitmap: # Despite its name, we need to pass a bitmap to SetNavigatorIcon self.SetNavigatorIcon(bitmap)
def OnContextMenu(self, event): if not hasattr(self, "pp_SAVE"): self.pp_SAVE = wx.NewId() self.pp_CLOSE = wx.NewId() self.pp_HIDE = wx.NewId() self.pp_DELETE = wx.NewId() self.pp_TEST = wx.NewId() self.pp_GRAP = wx.NewId() self.pp_HIDE_OTHER = wx.NewId() self.pp_SHOW_ALL = wx.NewId() self.pp_FRAMEMANAGER = wx.NewId() self.pp_SHOWINEXPLORER = wx.NewId() self.pp_test = wx.NewId() self.pp_RENAME = wx.NewId() self.pp_EXIT = wx.NewId() self.Bind(wx.EVT_MENU, self.onSave, id=self.pp_SAVE) self.Bind(wx.EVT_MENU, self.onClose, id=self.pp_CLOSE) self.Bind(wx.EVT_MENU, self.onDelete, id=self.pp_DELETE) self.Bind(wx.EVT_MENU, self.showALL_FRAME, id=self.pp_SHOW_ALL) self.Bind(wx.EVT_MENU, self.hideOther_FRAME, id=self.pp_HIDE_OTHER) self.Bind(wx.EVT_MENU, self.onHide, id=self.pp_HIDE) self.Bind(wx.EVT_MENU, self.grapScreen, id=self.pp_GRAP) self.Bind(wx.EVT_MENU, self.showFrameManager, id=self.pp_FRAMEMANAGER) self.Bind(wx.EVT_MENU, self.showInExplorer, id=self.pp_SHOWINEXPLORER) self.Bind(wx.EVT_MENU, self.reName, id=self.pp_RENAME) self.Bind(wx.EVT_MENU, self.closeApp, id=self.pp_EXIT) bmp = wx.BitmapFromIcon(wx.Icon(os.getcwd() + '/App.ico')) menu = wx.Menu() if self.path != "imagePin.png": menu.Append(self.pp_RENAME, (LANGUAGE_PACK["menu_reName_pre"] + self.name)) menu.AppendSeparator() # menu.Append(self.pp_test, self.name) menu.Append(self.pp_RENAME, (LANGUAGE_PACK["rename"])) #+"--- "+self.name)) menu.AppendSeparator() menu.Append(self.pp_GRAP, LANGUAGE_PACK["grap"]) menu.Append(self.pp_SHOWINEXPLORER, LANGUAGE_PACK["show_in_explorer"]) menu.Append(self.pp_HIDE, LANGUAGE_PACK["hide"]) menu.Append(self.pp_HIDE_OTHER, LANGUAGE_PACK["hide_others"]) menu.Append(self.pp_SHOW_ALL, LANGUAGE_PACK["show_all_windows"]) if self.path != "imagePin.png": menu.AppendSeparator() item = wx.MenuItem(menu, self.pp_SAVE, LANGUAGE_PACK["save"]) menu.AppendItem(item) menu.Append(self.pp_CLOSE, LANGUAGE_PACK["close"]) menu.Append(self.pp_DELETE, LANGUAGE_PACK["delete"]) menu.Append(self.pp_EXIT, LANGUAGE_PACK["exit"]) self.PopupMenu(menu) menu.Destroy()
def paint(e): dc = wx.PaintDC(f) #dc.DrawBitmap(bitmap, 16, 0, True) dc.SetBrush(wx.WHITE_BRUSH) dc.SetPen(wx.TRANSPARENT_PEN) dc.DrawRectangleRect(f.ClientRect) dc.DrawBitmap(bad, 16, 16, True) dc.DrawBitmap(wx.BitmapFromIcon(icon), 32, 16, True) dc.DrawBitmap(reference, 48, 16, True)
def __init__(self, parent, info): title = _("About") + " " + info.Name wx.Dialog.__init__(self, parent, title=title) self.info = info if parent and parent.GetIcon(): self.SetIcon(parent.GetIcon()) image = None if self.info.Icon: bitmap = wx.BitmapFromIcon(self.info.Icon) image = wx.StaticBitmap(self, bitmap=bitmap) name = wx.StaticText(self, label="%s %s" % (info.Name, info.Version)) description = wx.StaticText(self, label=info.Description) description.Wrap(400) copyright = wx.StaticText(self, label=info.Copyright) url = HyperLinkCtrl(self, label=info.WebSite[0], URL=info.WebSite[1]) font = name.GetClassDefaultAttributes().font font.SetWeight(wx.FONTWEIGHT_BOLD) font.SetPointSize(18) name.SetFont(font) credits = wx.Button(self, id=wx.ID_ABOUT, label=_("C&redits")) license = wx.Button(self, label=_("&License")) close = wx.Button(self, id=wx.ID_CANCEL, label=_("&Close")) btnSizer = wx.BoxSizer(wx.HORIZONTAL) btnSizer.Add(credits, flag=wx.CENTER | wx.LEFT | wx.RIGHT, border=5) btnSizer.Add(license, flag=wx.CENTER | wx.RIGHT, border=5) btnSizer.Add(close, flag=wx.CENTER | wx.RIGHT, border=5) sizer = wx.BoxSizer(wx.VERTICAL) if image: sizer.Add(image, flag=wx.CENTER | wx.TOP | wx.BOTTOM, border=5) sizer.Add(name, flag=wx.CENTER | wx.BOTTOM, border=10) sizer.Add(description, flag=wx.CENTER | wx.BOTTOM, border=10) sizer.Add(copyright, flag=wx.CENTER | wx.BOTTOM, border=10) sizer.Add(url, flag=wx.CENTER | wx.BOTTOM, border=15) sizer.Add(btnSizer, flag=wx.CENTER | wx.BOTTOM, border=5) container = wx.BoxSizer(wx.VERTICAL) container.Add(sizer, flag=wx.ALL, border=10) self.SetSizer(container) self.Layout() self.Fit() self.Centre() self.Show(True) self.SetEscapeId(close.GetId()) credits.Bind(wx.EVT_BUTTON, self.on_credits) license.Bind(wx.EVT_BUTTON, self.on_license) close.Bind(wx.EVT_BUTTON, lambda evt: self.Destroy())
def _get_icon_bitmap_from_shell32_dll(index_number, size): assert isinstance(index_number, int) assert is_win import win32api width, height = size shell32_dll = win32api.GetModuleFileName( win32api.GetModuleHandle('shell32.dll')) return wx.BitmapFromIcon( wx.Icon('%s;%s' % (shell32_dll, index_number), wx.BITMAP_TYPE_ICO, desiredWidth=width, desiredHeight=height))
def take_screenshot(): """Returns a wx.Bitmap screenshot taken of the whole screen.""" wx.YieldIfNeeded() rect = wx.Rect(0, 0, *wx.DisplaySize()) bmp = wx.EmptyBitmap(rect.width, rect.height) dc = wx.ScreenDC() dc_bmp = wx.MemoryDC() dc_bmp.SelectObject(bmp) dc_bmp.Blit(0, 0, rect.width, rect.height, dc, rect.x, rect.y) dc_bmp.SelectObject(wx.NullBitmap) # Hack to drop screen transparency, wx issue when blitting from screen bmp = wx.BitmapFromIcon(wx.IconFromBitmap(bmp)) return bmp
def SetIcon(self, icon): pParentFrame = self.GetMDIParentFrame() if not pParentFrame: raise Exception("Missing MDI Parent Frame") self._icon = icon bmp = wx.BitmapFromIcon(self._icon) pClientWindow = pParentFrame.GetClientWindow() if pClientWindow is not None: idx = pClientWindow.GetPageIndex(self) if idx != -1: pClientWindow.SetPageBitmap(idx, bmp)
def bitmap_from_extension(extension): ''' Get the bitmap of extension. @param extension: The extension. @return The image. ''' if extension == 'folder': bm = wx.Bitmap(name='icons/folder.png', type=wx.BITMAP_TYPE_PNG) bm.SetSize((16, 16)) return bm else: flags = win32com.shell.shellcon.SHGFI_SMALLICON | win32com.shell.shellcon.SHGFI_ICON | win32com.shell.shellcon.SHGFI_USEFILEATTRIBUTES retval, info = win32com.shell.shell.SHGetFileInfo( extension, win32con.FILE_ATTRIBUTE_NORMAL, flags) icon = wx.EmptyIcon() icon.SetHandle(info[0]) return wx.BitmapFromIcon(icon)
def __init__(self): super(TaskBarBalloon, self).__init__() # Setup icon = wx.Icon("face-monkey.png", wx.BITMAP_TYPE_PNG) self.SetIcon(icon) # Setup BallooTip title="BalloonTip Recipe" msg = "Welcome to the Balloon Tip Recipe" bmp = wx.BitmapFromIcon(icon) self.tip = btip.BalloonTip(topicon=bmp, toptitle=title, message=msg, shape=btip.BT_ROUNDED, tipstyle=btip.BT_BUTTON) self.tip.SetStartDelay(1000) self.tip.SetTarget(self) # Event Handlers self.Bind(wx.EVT_MENU, self.OnMenu)
def BusyInfo(title, msg, image=None): ''' Show a "busy" message. Will not block but return the busy-object. Important: this will NEVER disappear - except when you delete this object! E.g. by setting busy = None oder del busy. ''' import wx.lib.agw.pybusyinfo as PBI app = wx.App() if not image: img = wx.NullBitmap elif type(image) == type(u""): if image.endswith(".ico"): icon = wx.Icon(image, wx.BITMAP_TYPE_ICO) img = wx.BitmapFromIcon(icon) else: img = wx.Bitmap(image, wx.BITMAP_TYPE_ANY) else: img = image.GetBitmap() busy = PBI.PyBusyInfo(msg, parent=None, title=title, icon=img) wx.Yield() return busy
def __init__(self, parent, message, caption="Message Box", msg2="", style=wx.OK | wx.CANCEL, pos=wx.DefaultPosition, icon=None, btnLabels=None): if 'wxMac' not in wx.PlatformInfo: title = caption # the caption will be displayed inside the dialog on Macs else: title = "" wx.Dialog.__init__(self, parent, -1, title, pos, style=wx.DEFAULT_DIALOG_STYLE | style & (wx.STAY_ON_TOP | wx.DIALOG_NO_PARENT)) bitmap = None isize = (32, 32) # was an icon passed to us? if icon is not None: if isinstance(icon, wx.Icon): bitmap = wx.BitmapFromIcon(icon) elif isinstance(icon, wx.Image): bitmap = wx.Bitmap(icon) else: assert isinstance(icon, wx.Bitmap) bitmap = icon else: # check for icons in the style flags artid = None if style & wx.ICON_ERROR or style & wx.ICON_HAND: artid = wx.ART_ERROR elif style & wx.ICON_EXCLAMATION: artid = wx.ART_WARNING elif style & wx.ICON_QUESTION: artid = wx.ART_QUESTION elif style & wx.ICON_INFORMATION: artid = wx.ART_INFORMATION if artid is not None: bitmap = wx.ArtProvider.GetBitmap(artid, wx.ART_MESSAGE_BOX, isize) if bitmap: bitmap = wx.StaticBitmap(self, -1, bitmap) else: bitmap = isize # will be a spacer when added to the sizer # Sizer to contain the icon, text area and buttons sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(bitmap, 0, wx.TOP | wx.LEFT, 12) sizer.Add((10, 10)) # Make the text area messageSizer = wx.BoxSizer(wx.VERTICAL) if 'wxMac' in wx.PlatformInfo and caption: caption = wx.StaticText(self, -1, caption) caption.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD)) messageSizer.Add(caption) messageSizer.Add((10, 10)) stext = wx.StaticText(self, -1, message) #stext.SetLabelMarkup(message) Wrap() causes all markup to be lost, so don't try to use it yet... stext.Wrap(self.CONTENT_MAX_W) messageSizer.Add(stext) if msg2: messageSizer.Add((15, 15)) t = wx.TextCtrl(self, style=wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_RICH | wx.TE_DONTWRAP) t.SetValue(msg2) # Set size to be used by the sizer based on the message content, # with good maximums dc = wx.ClientDC(t) dc.SetFont(t.GetFont()) w, h = dc.GetFullMultiLineTextExtent(msg2) w = min(self.CONTENT_MAX_W, 10 + w + wx.SystemSettings.GetMetric(wx.SYS_VSCROLL_X)) h = min(self.CONTENT_MAX_H, 10 + h) t.SetMinSize((w, h)) messageSizer.Add(t, 0, wx.EXPAND) # Make the buttons buttonSizer = self.CreateStdDialogButtonSizer( style & (wx.OK | wx.CANCEL | wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL_DEFAULT | wx.YES_DEFAULT | wx.OK_DEFAULT)) self.Bind(wx.EVT_BUTTON, self.OnButton) if btnLabels: for sid, label in btnLabels.iteritems(): btn = self.FindWindowById(sid) if btn: btn.SetLabel(label) messageSizer.Add(wx.Size(1, 15)) messageSizer.Add(buttonSizer, 0, wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, 12) sizer.Add(messageSizer, 0, wx.LEFT | wx.RIGHT | wx.TOP, 12) self.SetSizer(sizer) self.Fit() if parent: self.CenterOnParent() else: self.CenterOnScreen() for c in self.Children: if isinstance(c, wx.Button): wx.CallAfter(c.SetFocus) break