Beispiel #1
0
    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()
Beispiel #2
0
    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()
Beispiel #3
0
    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())
Beispiel #4
0
    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())
Beispiel #5
0
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    
Beispiel #6
0
    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()))
Beispiel #7
0
 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), {}]
Beispiel #8
0
def getMoveButtonImage():
    stream = BytesIO(getMoveButtonData())
    return ImageFromStream(stream)
Beispiel #9
0
def getMagMinusImage():
    stream = BytesIO(getMagMinusData())
    return ImageFromStream(stream)
Beispiel #10
0
def GetCollapsedIconImage():
    stream = BytesIO(GetCollapsedIconData())
    return wx.Image(stream)
Beispiel #11
0
def getHand16Image():
    stream = BytesIO(getHand16Data())
    return ImageFromStream(stream)
Beispiel #12
0
def getMondrianImage():
    stream = BytesIO(getMondrianData())
    return ImageFromStream(stream)
Beispiel #13
0
def getGrabHandImage():
    stream = BytesIO(getGrabHandData())
    return ImageFromStream(stream)
Beispiel #14
0
def getMoveUDCursorImage():
    stream = BytesIO(getMoveUDCursorData())
    return ImageFromStream(stream)
Beispiel #15
0
def GetExpandedIconImage():
    stream = BytesIO(GetExpandedIconData())
    return wx.Image(stream)
def GetMondrianImage():
    stream = BytesIO(GetMondrianData())
    return wx.Image(stream)
Beispiel #17
0
 def GetImage(self):
     stream = BytesIO(self.GetData())
     return wx.Image(stream)
Beispiel #18
0
def getMagPlus16Image():
    stream = BytesIO(getMagPlus16Data())
    return ImageFromStream(stream)
Beispiel #19
0
def getPyImage(shellName='PyCrust'):
    stream = BytesIO(getPyData(shellName))
    return wx.Image(stream)
Beispiel #20
0
def getPointerImage():
    stream = BytesIO(getPointerData())
    return ImageFromStream(stream)