viewing text with CodeEditor

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

viewing text with CodeEditor

Brennan Williams
I'm using

Item('textstring',editor=CodeEditor())

as it gives a fixed width font which makes it easier to read.

 Is it possible to add search capability?

I tried

Item('textstring',editor=CodeEditor(search='top'))

but that had no effect.

I saw something in a previous set of posts from last Feb (Fred, Gael,
Bryce) where Fred was looking to colour code keywords in the editor
and Gael & Bryce suggested SourceEditor. Can't get SourceEditor to work
though as it needs a parent, just trying to work out what that is by
looking for
PythonEditor in pyface.

I suppose my ultimate aim is to have a searchable, colour coded
(according to some external setup file that defines my keywords) editor.

Can anyone give me a push in the right direction?

Thanks

Brennan


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: viewing text with CodeEditor

bryce hendrix-2
Brennan Williams wrote:

> I'm using
>
> Item('textstring',editor=CodeEditor())
>
> as it gives a fixed width font which makes it easier to read.
>
>  Is it possible to add search capability?
>
> I tried
>
> Item('textstring',editor=CodeEditor(search='top'))
>
> but that had no effect.
>
> I saw something in a previous set of posts from last Feb (Fred, Gael,
> Bryce) where Fred was looking to colour code keywords in the editor
> and Gael & Bryce suggested SourceEditor. Can't get SourceEditor to work
> though as it needs a parent, just trying to work out what that is by
> looking for
> PythonEditor in pyface.
>
>  

If I remember right, we did a bit of a refactor last summer and replaced
the CodeEditor with the SourceEditor internally. Its not going to do
exactly what you want out of the box however- you need to do the search
yourself, then set the trait that 'selected_line' points to:

class SearchableCode(HasTraits):
    selected_line = Int()
    code = Str()

    view = View(Item('code',
editor=CodeEditor(selected_line=selected_line)))

    def do_search(self, search_str):
        # find the line that the search_str appears on
        found_line = ...
        self.selected_line = found_line

Or something like that.

Bryce
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: viewing text with CodeEditor

Brennan Williams
bryce hendrix wrote:

> Brennan Williams wrote:
>  
>> I'm using
>>
>> Item('textstring',editor=CodeEditor())
>>
>> as it gives a fixed width font which makes it easier to read.
>>
>>  Is it possible to add search capability?
>>
>> I tried
>>
>> Item('textstring',editor=CodeEditor(search='top'))
>>
>> but that had no effect.
>>
>> I saw something in a previous set of posts from last Feb (Fred, Gael,
>> Bryce) where Fred was looking to colour code keywords in the editor
>> and Gael & Bryce suggested SourceEditor. Can't get SourceEditor to work
>> though as it needs a parent, just trying to work out what that is by
>> looking for
>> PythonEditor in pyface.
>>
>>  
>>    
>
> If I remember right, we did a bit of a refactor last summer and replaced
> the CodeEditor with the SourceEditor internally. Its not going to do
> exactly what you want out of the box however- you need to do the search
> yourself, then set the trait that 'selected_line' points to:
>
> class SearchableCode(HasTraits):
>     selected_line = Int()
>     code = Str()
>
>     view = View(Item('code',
> editor=CodeEditor(selected_line=selected_line)))
>
>     def do_search(self, search_str):
>         # find the line that the search_str appears on
>         found_line = ...
>         self.selected_line = found_line
>
> Or something like that.
>
>  
Thanks, I'll try that out and see how I go.

On a further note I recall Fred asking about colour coding keywords. I
know a lot of external 3rd party editors provide this functionality and
I think
Gael said something in his replies to Fred about Scintilla which I
currently know nothing about apart from having heard the name. I did
notice that
there was some auto-formatting based on the contents of my file, for
example, I have some lines that start with an @ and they were displayed
in a different font to the rest of the file. Text inside single quotes
came out italised etc etc.

So is it possible to define your own set of keywords/language to be
highlighted or displayed in a different font/colour etc?

Brennan

> Bryce
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 8.5.432 / Virus Database: 271.1.1/2660 - Release Date: 01/31/10 19:35:00
>
>  


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev