How to load files containing NUL bytes into wxPython STC?

Hello,

···

On Thu, Jun 6, 2013 at 3:05 PM, Johnsons in DE rj_google@objectmail.com wrote:

Hi all,

    I am trying to load files

containing NUL bytes into a wxPython StyledTextCtrl. The problem is that the files are
truncated at the first NUL byte.

    I noticed that Editra does not have

this problem, and I looked at its source code to see how it
works around it. It said something about loading the file into a
buffer being necessary, but I tried that and it did not fix the
problem. I can not figure out exactly what I need to do to fix
this. Could someone please edit the following (simplified) code
to show me what I need to do?

      input = open(self.filename,

‘rb’)

      text = input.read()

      input.close()
      # Encoding stuff goes

here…

self.SetText(text)

In order to handle arbitrary / unknown file encodings as transparently as possible the file loading in Editra is rather complicated.

In order to display NULL’s in the STC you need to do the following:

myTextWithNULLs = ‘\0’.join(bytes_from_file) + ‘\0’

self.AddStyledText(myTextWithNULLs)

The AddStyledText call is a way to add raw formated text into the STC buffer. The other methods will truncate on NULL. The added NULLs in the join call are to set the style bytes for each character as needed by the AddStyledText call.

Cody