[wxPython] Colored text in a wxTextCtrl

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] Colored text in a wxTextCtrl

Pieter Claerhout-3
Hello,

i have an app which uses a wxTextCtrl to display the contents of a
text file. What I want to do is colorzing the text based on some
very simple rules, for example:

- every line beginning with %ALD in red
- every line beginning with %SSi in blue
- All text between brackets () in green

Does anyone has a simple solution to accomplish this? One thing that
I have to mention is that the wxTextCtrl is set to read only, because
the user may not change the contents.

Kind regards,


Pieter

Pieter Claerhout - [hidden email]
Response Center - Applications Support

Creo Europe - Excelsiorlaan 21 - 1930 Zaventem - Belgium
Tel: +32 (2) 711 14 00 - Fax: +32 (2) 720 96 71


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Colored text in a wxTextCtrl

Robin Dunn
>
> i have an app which uses a wxTextCtrl to display the contents of a
> text file. What I want to do is colorzing the text based on some
> very simple rules, for example:
>
> - every line beginning with %ALD in red
> - every line beginning with %SSi in blue
> - All text between brackets () in green
>
> Does anyone has a simple solution to accomplish this? One thing that
> I have to mention is that the wxTextCtrl is set to read only, because
> the user may not change the contents.
>

The wxTextCtrl is not able to do this.  It's just not that smart.  I'm
working on a class that will let you do things like this fairly easily, but
until then your only solution is to draw the text yourself on possibly a
wxScrolledWindow using it's DC.

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!




_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Colored text in a wxTextCtrl

Bruce Rabine
In reply to this post by Pieter Claerhout-3

My first reaction to this problem was to use a wxHtmlWindow instead of
a wxTextCtrl.  Just parse the text first, placing the appropriate
html commands to change the text color where needed, and display the
text in an Html window, which seems to handle colors just fine.



> From: "Robin Dunn" <[hidden email]>
> To: "Pieter Claerhout" <[hidden email]>,
<[hidden email]>

> Subject: Re: [wxPython] Colored text in a wxTextCtrl
> Date: Wed, 1 Dec 1999 11:32:14 -0800
> >
> > i have an app which uses a wxTextCtrl to display the contents of a
> > text file. What I want to do is colorzing the text based on some
> > very simple rules, for example:
> >
> > - every line beginning with %ALD in red
> > - every line beginning with %SSi in blue
> > - All text between brackets () in green
> >
> > Does anyone has a simple solution to accomplish this? One thing that
> > I have to mention is that the wxTextCtrl is set to read only, because
> > the user may not change the contents.
> >
>
> The wxTextCtrl is not able to do this.  It's just not that smart.  I'm
> working on a class that will let you do things like this fairly easily,
> but until then your only solution is to draw the text yourself on
> possibly a wxScrolledWindow using it's DC.
>
> --
> Robin Dunn
> Software Craftsman
> [hidden email]
> http://AllDunn.com/robin/
> http://AllDunn.com/wxPython/  Check it out!
>


+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| Bruce Rabine              e-mail:  [hidden email] |
| Secure Computing Corp.                                              |
| 2675 Long Lake Road                                                 |
| Roseville, MN 55113, USA     web:           www.securecomputing.com |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +




_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Colored text in a wxTextCtrl

Robin Dunn
> > The wxTextCtrl is not able to do this.  It's just not that smart.  I'm
> > working on a class that will let you do things like this fairly easily,
> > but until then your only solution is to draw the text yourself on
> > possibly a wxScrolledWindow using it's DC.
> >
>
> My first reaction to this problem was to use a wxHtmlWindow instead of
> a wxTextCtrl.  Just parse the text first, placing the appropriate
> html commands to change the text color where needed, and display the
> text in an Html window, which seems to handle colors just fine.
>

Ah, yes.  There is this *easy* way to do exactly what I said.  (The
wxHtmlWindow draws it's own text on a wxScrolledWindow's DC.)  <grin>

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!






_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Colored text in a wxTextCtrl

Piet van Oostrum
In reply to this post by Robin Dunn
>>>>> "Robin Dunn" <[hidden email]> (RD) writes:

RD> The wxTextCtrl is not able to do this.  It's just not that smart.  I'm
RD> working on a class that will let you do things like this fairly easily, but
RD> until then your only solution is to draw the text yourself on possibly a
RD> wxScrolledWindow using it's DC.

Will this have an edit functionality (like the Tk text widget)?
--
Piet van Oostrum <[hidden email]>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: [hidden email]


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Colored text in a wxTextCtrl

Robin Dunn
> >>>>> "Robin Dunn" <[hidden email]> (RD) writes:
>
> RD> The wxTextCtrl is not able to do this.  It's just not that smart.  I'm
> RD> working on a class that will let you do things like this fairly easily,
but
> RD> until then your only solution is to draw the text yourself on possibly
a
> RD> wxScrolledWindow using it's DC.
>
> Will this have an edit functionality (like the Tk text widget)?

If you are referring to the the thing I am working on, yes.  It's a
StyledTextEditor window that will let you have a high level of control over
how it's text is displayed.  You define styles and then ranges of text that
have that style, (whether that is done by a language sensitive syntax parser
or some other mechanisim such as what you want to do is determined by a
derived class or a container class...)  I hope to be able to encorporate some
features of Dirk's pyDE into it as well.

I've been working on it in between bug fixes, doing releases, adding new
wxWindows stuff, working on conference presentations, etc. so it's been going
a little slow, but I hope to finish within the next few weeks.

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!




_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Colored text in a wxTextCtrl

Piet van Oostrum
>>>>> "Robin Dunn" <[hidden email]> (RD) writes:

RD> If you are referring to the the thing I am working on, yes. It's a
RD> StyledTextEditor window that will let you have a high level of
RD> control over how it's text is displayed. You define styles and
RD> then ranges of text that have that style, (whether that is done by
RD> a language sensitive syntax parser or some other mechanisim such
RD> as what you want to do is determined by a derived class or a
RD> container class...) I hope to be able to encorporate some features
RD> of Dirk's pyDE into it as well.

Yes, I was referring to your new thing. This sounds very good!!

RD> I've been working on it in between bug fixes, doing releases,
RD> adding new wxWindows stuff, working on conference presentations,
RD> etc. so it's been going a little slow, but I hope to finish within
RD> the next few weeks.

I am looking forward to it.
--
Piet van Oostrum <[hidden email]>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: [hidden email]


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Colored text in a wxTextCtrl

Piet van Oostrum
In reply to this post by Robin Dunn
>>>>> "Robin Dunn" <[hidden email]> (RD) writes:

RD> If you are referring to the the thing I am working on, yes. It's a
RD> StyledTextEditor window that will let you have a high level of control
RD> over how it's text is displayed. You define styles and then ranges of
RD> text that have that style, (whether that is done by a language
RD> sensitive syntax parser or some other mechanisim such as what you want
RD> to do is determined by a derived class or a container class...) I hope
RD> to be able to encorporate some features of Dirk's pyDE into it as well.

One other question: Will it have the ability to include other controls in
it, between the text?
--
Piet van Oostrum <[hidden email]>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: [hidden email]


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users