[wxPython-users] Displaying Nice XML with RichEdit

Werner F. Bruhin werner.bruhin at free.fr
Thu Jul 12 07:24:48 PDT 2007


Hi S=E9bastian,

S=E9bastien VINOT wrote:
> Hello everybody,
>
> I'm building a little wxPython App (using Boa) just for learning =

> wxPython. I have an XML document (parsed with minidom) and I'd to =

> display it (at the moment in a read-only mode). Of course I found =

> TextControl (I hope it is the good name) widget and that works.
Attached a small sample using amara to handle the xml reading and =

writing to a wx.StyledTextCtrl.  If it needs to be nicer, then you need =

to look into how to set the style etc for the control (you might want to =

check out the wxPython demo or the Boa code on how to do this).

Werner
-------------- next part --------------
#Boa:Frame:Frame1

import wx
import wx.stc

import os

from amara import binderytools

def create(parent):
    return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1STYLEDTEXTCTRL1, =

] =3D [wx.NewId() for _init_ctrls in range(2)]

class Frame1(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=3DwxID_FRAME1, name=3D'', parent=3Dprnt,
              pos=3Dwx.Point(504, 196), size=3Dwx.Size(847, 592),
              style=3Dwx.DEFAULT_FRAME_STYLE, title=3D'Frame1')
        self.SetClientSize(wx.Size(831, 556))

        self.styledTextCtrl1 =3D wx.stc.StyledTextCtrl(id=3DwxID_FRAME1STYL=
EDTEXTCTRL1,
              name=3D'styledTextCtrl1', parent=3Dself, pos=3Dwx.Point(0, 0),
              size=3Dwx.Size(831, 556), style=3D0)
##        self.styledTextCtrl1.SetLexer(wx.stc.STC_LEX_XML)

    def __init__(self, parent):
        self._init_ctrls(parent)
        # replace the file name below
        fileName =3D r'DomaineduPechLaBadinerie2000-102Rouge.xml'
        file =3D os.path.join(os.getcwd(), fileName)
        self.xmlDoc =3D binderytools.bind_file(file)
        =

        self.styledTextCtrl1.AddTextUTF8(self.xmlDoc.xml(indent=3Du'yes'))

if __name__ =3D=3D '__main__':
    app =3D wx.PySimpleApp()
    frame =3D create(None)
    frame.Show()

    app.MainLoop()


More information about the wxpython-users mailing list