def OnFileViewHTML(self, evt): # Get an instance of the html file handler, use it to save the # document to a StringIO stream, and then display the # resulting html text in a dialog with a HtmlWindow. handler = rt.RichTextHTMLHandler() handler.SetFlags(rt.RICHTEXT_HANDLER_SAVE_IMAGES_TO_MEMORY) handler.SetFontSizeMapping([7, 9, 11, 12, 14, 22, 100]) stream = BytesIO() if not handler.SaveStream(self.rtc.GetBuffer(), stream): return import wx.html dlg = wx.Dialog(self, title="HTML", style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) html = wx.html.HtmlWindow(dlg, size=(500, 400), style=wx.BORDER_SUNKEN) html.SetPage(stream.getvalue()) btn = wx.Button(dlg, wx.ID_CANCEL) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(html, 1, wx.ALL | wx.EXPAND, 5) sizer.Add(btn, 0, wx.ALL | wx.CENTER, 10) dlg.SetSizer(sizer) sizer.Fit(dlg) dlg.ShowModal() handler.DeleteTemporaryImages()
def OnFileViewHTML(self, evt): # Get an instance of the html file handler, use it to save the # document to a StringIO stream, and then display the # resulting html text in a dialog with a HtmlWindow. handler = rt.RichTextHTMLHandler() handler.SetFlags(rt.RICHTEXT_HANDLER_SAVE_IMAGES_TO_MEMORY) handler.SetFontSizeMapping([7,9,11,12,14,22,100]) stream = BytesIO() if not handler.SaveStream(self.rtc.GetBuffer(), stream): return import wx.html dlg = wx.Dialog(self, title="HTML", style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER) html = wx.html.HtmlWindow(dlg, size=(500,400), style=wx.BORDER_SUNKEN) html.SetPage(stream.getvalue()) btn = wx.Button(dlg, wx.ID_CANCEL) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(html, 1, wx.ALL|wx.EXPAND, 5) sizer.Add(btn, 0, wx.ALL|wx.CENTER, 10) dlg.SetSizer(sizer) sizer.Fit(dlg) dlg.ShowModal() handler.DeleteTemporaryImages()
def test_outputStreamParam(self): # This tests being able to pass a Python file-like object to a # wrapped function expecting a wxOutputStream. image = wx.Image(pngFile) stream = FileLikeObject() image.SaveFile(stream, wx.BITMAP_TYPE_PNG) del image stream = FileLikeObject(stream.getvalue()) image = wx.Image(stream) self.assertTrue(image.IsOk())
def getTokens(command): """Return list of token tuples for command.""" # In case the command is unicode try encoding it if isinstance(command, string_types): try: command = command.encode('utf-8') except UnicodeEncodeError: pass # otherwise leave it alone f = BytesIO(command) # tokens is a list of token tuples, each looking like: # (type, string, (srow, scol), (erow, ecol), line) tokens = [] # Can't use list comprehension: # tokens = [token for token in tokenize.generate_tokens(f.readline)] # because of need to append as much as possible before TokenError. try: if not PY3: def eater(*args): tokens.append(args) tokenize.tokenize_loop(f.readline, eater) else: tokens = list(tokenize.tokenize(f.readline)) except tokenize.TokenError: # This is due to a premature EOF, which we expect since we are # feeding in fragments of Python code. pass return tokens
def __init__(self, parent, log): wx.Panel.__init__(self, parent, -1) data = open(opj('bitmaps/image.png'), "rb").read() stream = BytesIO(data) bmp = wx.Bitmap(wx.Image(stream)) wx.StaticText(self, -1, "This image was loaded from a Python file-like object:", (15, 15)) wx.StaticBitmap(self, -1, bmp, (15, 45)) #, (bmp.GetWidth(), bmp.GetHeight()))
def AddBitmap(self, data, width, height, filters): """ Add wx.Bitmap from data, processed by filters. """ if '/A85' in filters or '/ASCII85Decode' in filters: data = _AsciiBase85DecodePYTHON(data) if '/Fl' in filters or '/FlateDecode' in filters: data = FlateDecode.decode(data, None) if '/DCT' in filters or '/DCTDecode' in filters: stream = BytesIO(data) image = wx.Image(stream, wx.BITMAP_TYPE_JPEG) bitmap = wx.Bitmap(image) else: bitmap = wx.BitmapFromBuffer(width, height, data) return ['DrawBitmap', (bitmap, 0, 0-height, width, height), {}]
def getMoveButtonImage(): stream = BytesIO(getMoveButtonData()) return ImageFromStream(stream)
def getMagMinusImage(): stream = BytesIO(getMagMinusData()) return ImageFromStream(stream)
def GetCollapsedIconImage(): stream = BytesIO(GetCollapsedIconData()) return wx.Image(stream)
def getHand16Image(): stream = BytesIO(getHand16Data()) return ImageFromStream(stream)
def getMondrianImage(): stream = BytesIO(getMondrianData()) return ImageFromStream(stream)
def getGrabHandImage(): stream = BytesIO(getGrabHandData()) return ImageFromStream(stream)
def getMoveUDCursorImage(): stream = BytesIO(getMoveUDCursorData()) return ImageFromStream(stream)
def GetExpandedIconImage(): stream = BytesIO(GetExpandedIconData()) return wx.Image(stream)
def GetMondrianImage(): stream = BytesIO(GetMondrianData()) return wx.Image(stream)
def GetImage(self): stream = BytesIO(self.GetData()) return wx.Image(stream)
def getMagPlus16Image(): stream = BytesIO(getMagPlus16Data()) return ImageFromStream(stream)
def getPyImage(shellName='PyCrust'): stream = BytesIO(getPyData(shellName)) return wx.Image(stream)
def getPointerImage(): stream = BytesIO(getPointerData()) return ImageFromStream(stream)