newbie question, about writing a XML viewer with wxPython

Robin Dunn <robin@alldunn.com>:

> Well, i know that it can hide
> function/class definitions when wxStyledCtrl is

used for editing

> source files, but i got the feeling that it is

complicated to

> use this facility of the widget for XML files.

Once you figure out the basics of wxSTC then I don't

think it

would be too hard to do.

Yep, you were right: it's not that hard. I've managed to
use folding capabilities of StyledtextCtrl, and now i can
collapse/expand the nodes.
Now i'll have to use some styles to make the program look
nicer, and my xml viewer will be ready for use!

Thanks for your answer,

Adrian Maier

adrian_maier wrote:

Yep, you were right: it's not that hard. I've managed to use folding capabilities of StyledtextCtrl, and now i can collapse/expand the nodes. Now i'll have to use some styles to make the program look nicer, and my xml viewer will be ready for use!

Is it something you can share? It sounds like it would make a good sample app.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote

adrian_maier wrote:
>
> Yep, you were right: it's not that hard. I've managed to
> use folding capabilities of StyledtextCtrl, and now i can
> collapse/expand the nodes.
> Now i'll have to use some styles to make the program look
> nicer, and my xml viewer will be ready for use!

Is it something you can share? It sounds like it would make a good
sample app.

A few months ago, i wrote an XML Viewer for one of my projects. It's based
upon the toprettyxml() method, a simple algorithm to collect tag names of
the xml document.and of course the wxSTC demos. There are still strange
behaviours i dont understand and i join the code "as is". Comments are
welcome.

Thomas

sample.xml (516 Bytes)

XMLViewer.py (7.97 KB)

Thomas Paviot wrote:

A few months ago, i wrote an XML Viewer for one of my projects. It's based
upon the toprettyxml() method, a simple algorithm to collect tag names of
the xml document.and of course the wxSTC demos. There are still strange
behaviours i dont understand and i join the code "as is". Comments are
welcome.

Sorry for my late answer.

Your program was useful, because i got some ideas.
Unfortunately, I haven't been able to open most of my test files with your viewer. It simply
says "Parse error".

It seems that minidom didn't like something about my xml documents....
If you want to investigate this, i could send you my test xml files (but they are quite big:
between 70 kb and 500 kb).

For my viewer I have used SAX and had no such problems.

Cheers,
Adrian Maier

Adrian Maier:

The xml files can be in one of the Central European languages: Polish,
Hungarian,Estonian,Czech,Latvian,etc. Some special characters are not
correctly
displayed. I am reading the text using SAX: I add the characters to a
(unicode) string, then i use the encode method for obtaining the
string that
will be added to the STC widget. I am using "utf-8" but i'm not sure if
it's the correct encoding .
Do you have any ideas what can i do to display the right characters?

   I don't know if it works in wxSTC but on other platforms, setting the
code page to SC_CP_UTF8 works. You may have to find the correct wxSTC
spelling for the call and constant. May need to use the Unicode version of
wxWindows.

Is it possible to define a custom "lexer"?

   SetLexer(SCLEX_CONTAINER) and respond to StyleNeeded notifications.

   Neil

Adrian Maier wrote:

SetCodePage(wx.stc.SC_CP_UTF8) didn't make any difference, but :
setting the locale with : locale.setlocale(leocale.LC_ALL,'Czech') worked.
I haven't been able to set it to UTF-8 yet ( i'm on Windows, by the way. ).
I'll add a combobox or something similar, so that the user will be able to change the
locale according to the language of the current file.

wxSTC will automatically set SC_CP_UTF8 when wxWindows is built in unicode mode, and it will also automatically transcode to/from utf-8 when moving strings to/from Scintilla.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!