ANSI Colour Codes

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

ANSI Colour Codes

Chris Norman
Hi all,
I've come to the stage in my MUD client's development that I've been
putting off for a while, where I need to handle colour.

As it stands, I've got the colour codes removed from the output while
the trigger engine does it's thing, then the whole line is passed onto
the GUI where's it's printed. I'm thinking I should override wx.EditCtrl
to implement something which uses write to modify the colours.

Is this over kill? Is there already such a control out there? Also, I've
been looking through the docs, and I'm not entirely sure on how to
change the colour of the text (using wx.TE_RICH as my style). Do I need
to create wx.Font objects each time? Or how does it work?

Cheers,

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: ANSI Colour Codes

Robin Dunn
Chris Norman wrote:

> Hi all,
> I've come to the stage in my MUD client's development that I've been
> putting off for a while, where I need to handle colour.
>
> As it stands, I've got the colour codes removed from the output while
> the trigger engine does it's thing, then the whole line is passed onto
> the GUI where's it's printed. I'm thinking I should override wx.EditCtrl
> to implement something which uses write to modify the colours.
>
> Is this over kill? Is there already such a control out there? Also, I've
> been looking through the docs, and I'm not entirely sure on how to
> change the colour of the text (using wx.TE_RICH as my style). Do I need
> to create wx.Font objects each time? Or how does it work?

For wx.TextCtrl you can use wx.TextAttr and SetStyle(), see the sample
in the demo.

Do you need to have all the text be editable or do you just need to
display it?  If the latter then the above does sound like overkill and
you may be better off if you create a custom class that draws the text
in its paint event.  It will be more work up front but in the end it
will likely be more flexible and more maintainable.

--
Robin Dunn
Software Craftsman
http://wxPython.org

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: ANSI Colour Codes

Chris Norman
Hi,
On 11/02/2015 05:13, Robin Dunn wrote:

> Chris Norman wrote:
>> Hi all,
>> I've come to the stage in my MUD client's development that I've been
>> putting off for a while, where I need to handle colour.
>>
>> As it stands, I've got the colour codes removed from the output while
>> the trigger engine does it's thing, then the whole line is passed onto
>> the GUI where's it's printed. I'm thinking I should override wx.EditCtrl
>> to implement something which uses write to modify the colours.
>>
>> Is this over kill? Is there already such a control out there? Also, I've
>> been looking through the docs, and I'm not entirely sure on how to
>> change the colour of the text (using wx.TE_RICH as my style). Do I need
>> to create wx.Font objects each time? Or how does it work?
>
> For wx.TextCtrl you can use wx.TextAttr and SetStyle(), see the sample
> in the demo.
>
> Do you need to have all the text be editable or do you just need to
> display it?  If the latter then the above does sound like overkill and
> you may be better off if you create a custom class that draws the text
> in its paint event.  It will be more work up front but in the end it
> will likely be more flexible and more maintainable.

In the interests of accessibility I think I want to keep it in an edit
field yes, so I'll work with the wx.TextAttr thing. Looking into that,
is there any way to see if a colour searched for with
wx.TheColourDatabase.Find is valid or not? If I enter:
wx.TheColourDatabase.Find('asdf'), it returns a colour with RGB at -1.
Do I just check for -1 in the RGB values? Or is there a traceback or
return value I can rely upon? I was hoping for a function which returned
a colour or None (or a traceback).

Cheers,


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: ANSI Colour Codes

Robin Dunn
Chris Norman wrote:

> Hi,
> On 11/02/2015 05:13, Robin Dunn wrote:
>> Chris Norman wrote:
>>> Hi all,
>>> I've come to the stage in my MUD client's development that I've been
>>> putting off for a while, where I need to handle colour.
>>>
>>> As it stands, I've got the colour codes removed from the output while
>>> the trigger engine does it's thing, then the whole line is passed onto
>>> the GUI where's it's printed. I'm thinking I should override wx.EditCtrl
>>> to implement something which uses write to modify the colours.
>>>
>>> Is this over kill? Is there already such a control out there? Also, I've
>>> been looking through the docs, and I'm not entirely sure on how to
>>> change the colour of the text (using wx.TE_RICH as my style). Do I need
>>> to create wx.Font objects each time? Or how does it work?
>>
>> For wx.TextCtrl you can use wx.TextAttr and SetStyle(), see the sample
>> in the demo.
>>
>> Do you need to have all the text be editable or do you just need to
>> display it? If the latter then the above does sound like overkill and
>> you may be better off if you create a custom class that draws the text
>> in its paint event. It will be more work up front but in the end it
>> will likely be more flexible and more maintainable.
>
> In the interests of accessibility I think I want to keep it in an edit
> field yes, so I'll work with the wx.TextAttr thing. Looking into that,
> is there any way to see if a colour searched for with
> wx.TheColourDatabase.Find is valid or not? If I enter:
> wx.TheColourDatabase.Find('asdf'), it returns a colour with RGB at -1.
> Do I just check for -1 in the RGB values? Or is there a traceback or
> return value I can rely upon? I was hoping for a function which returned
> a colour or None (or a traceback).


The colour with -1 components is "invalid" and is how functions like
this indicate an error when returning C++ objects.  You can call the
colour's Ok() method to see if it is a valid colour or not.


--
Robin Dunn
Software Craftsman
http://wxPython.org

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: ANSI Colour Codes

Chris Norman
That's great, thank you for the tip.

Take care,


On 07/03/2015 01:27, Robin Dunn wrote:

> Chris Norman wrote:
>> Hi,
>> On 11/02/2015 05:13, Robin Dunn wrote:
>>> Chris Norman wrote:
>>>> Hi all,
>>>> I've come to the stage in my MUD client's development that I've been
>>>> putting off for a while, where I need to handle colour.
>>>>
>>>> As it stands, I've got the colour codes removed from the output while
>>>> the trigger engine does it's thing, then the whole line is passed onto
>>>> the GUI where's it's printed. I'm thinking I should override
>>>> wx.EditCtrl
>>>> to implement something which uses write to modify the colours.
>>>>
>>>> Is this over kill? Is there already such a control out there? Also,
>>>> I've
>>>> been looking through the docs, and I'm not entirely sure on how to
>>>> change the colour of the text (using wx.TE_RICH as my style). Do I
>>>> need
>>>> to create wx.Font objects each time? Or how does it work?
>>>
>>> For wx.TextCtrl you can use wx.TextAttr and SetStyle(), see the sample
>>> in the demo.
>>>
>>> Do you need to have all the text be editable or do you just need to
>>> display it? If the latter then the above does sound like overkill and
>>> you may be better off if you create a custom class that draws the text
>>> in its paint event. It will be more work up front but in the end it
>>> will likely be more flexible and more maintainable.
>>
>> In the interests of accessibility I think I want to keep it in an edit
>> field yes, so I'll work with the wx.TextAttr thing. Looking into that,
>> is there any way to see if a colour searched for with
>> wx.TheColourDatabase.Find is valid or not? If I enter:
>> wx.TheColourDatabase.Find('asdf'), it returns a colour with RGB at -1.
>> Do I just check for -1 in the RGB values? Or is there a traceback or
>> return value I can rely upon? I was hoping for a function which returned
>> a colour or None (or a traceback).
>
>
> The colour with -1 components is "invalid" and is how functions like
> this indicate an error when returning C++ objects.  You can call the
> colour's Ok() method to see if it is a valid colour or not.
>
>

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.