A few doubts about wxPython and wxPython.stc

Hello!

Before diving into wxPython and [wxStyledTextCtrl or wxTextCtrl],
I wanted to clarify a few doubts:

1. In the documentation for wxPython.stc from
        http://www.pyframe.com/wxdocs/stc/index.html
   I did not find documentation of any way to completely over-ride the
   key assignments of the wxStyledTextCtrl object. There is
   a CmdKeyAssign() function provided, but the configurability is
   severley limited as far as I can see. To be clearer, the syntax is:
        CmdKeyAssign(key, modifiers, command)
   and the command is from a selected list of commands which
   wxStyledTextCtrl provides, like wxSTC_CMD_BACKTAB etc. But to emulate
   something like the vi editor (which I would eventually like to do),
   I would like to process all the key-presses via a custom function and
   issue the wxSTC_CMD_XXX commands from within that function
   programmatically. Simply assigning keys to other commands is not
   enough because the vi editor maintains state information. The 'i' key
   means different things at different times to give an example.

   To summarize:
       Is there a way to have the command argument in the function above
       be a python function instead of wxSTC_CMD_XXX?

   I had a very brief look at QT's QMultiLineEdit widget and in that,
   the way to do was simple. Just inherit from QMultiLineEdit and then
   over-ride the keyPressEvent() member. I would love it if STC provided
   a similar mechanism...

   If STC is unable to do this, does wxTextCtrl have any facility like
   this? Again I didn't find any mention of it in the wxWindows
   documentation...

2. STC seems to provide some default Lexers for syntax coloring. Is it
   possible to define completely new syntax coloring schemes, even at
   runtime?

Thanks,
Srinath

Srinath Avadhanula:

   I did not find documentation of any way to completely over-ride the
   key assignments of the wxStyledTextCtrl object.

   CmdKeyClearAll removes all key assignments.

       Is there a way to have the command argument in the function above
       be a python function instead of wxSTC_CMD_XXX?

   No. Intercept the EVT_KEY_DOWN events and provide your own processing.

2. STC seems to provide some default Lexers for syntax coloring. Is it
   possible to define completely new syntax coloring schemes, even at
   runtime?

   Yes, set the lexer to wxSTC_LEX_CONTAINER and handle EVT_STC_STYLENEEDED.

   Neil

[replying to my own email as always... :frowning: ]

   I did not find documentation of any way to completely over-ride the
   key assignments of the wxStyledTextCtrl object. There is
   a CmdKeyAssign() function provided, but the configurability is

I found out that this is pretty simple (and nice!). I could over-ride
the key assignments completely by doing something like:

class MyTextCtrl(wxStyledTextCtrl):
    def __init__(self, *_args, **_kwds):
        wxStyledTextCtrl.__init__(self, *_args, **_kwds)

        EVT_CHAR(self, onChar)

    def onChar(self, keyEvent):
        print keyEvent.KeyCode(),

        keyEvent.Skip()

Thanks,
Srinath

···

On Wed, 15 Oct 2003, Srinath Avadhanula wrote:

[replying to my own email as always... :frowning: ]

   I did not find documentation of any way to completely over-ride the
   key assignments of the wxStyledTextCtrl object. There is
   a CmdKeyAssign() function provided, but the configurability is

I found out that this is pretty simple (and nice!). I could over-ride
the key assignments completely by doing something like:

class MyTextCtrl(wxStyledTextCtrl):
    def __init__(self, *_args, **_kwds):
        wxStyledTextCtrl.__init__(self, *_args, **_kwds)

        EVT_CHAR(self, onChar)

    def onChar(self, keyEvent):
        print keyEvent.KeyCode(),

        keyEvent.Skip()

Thanks,
Srinath

···

On Wed, 15 Oct 2003, Srinath Avadhanula wrote: