having troubles with RichTextCtrl events ...

hello,

When using RichTextCtrl, there seems to be 2 different event types,
the general ones e.g.
    EVT_TEXT
and an equivalent RichText one
    EVT_RICHTEXT_CHARACTER

They both seemed to be fired, but the RichText equivalent gives many more properties back.
So I guess it's best to use the RichText equivalent.
Is that true ?

Now I need to detect if the cursor is moving to another style,
so I would guess I should use either one of the following:
    rt.EVT_RICHTEXT_STYLE_CHANGED
    rt.EVT_RICHTEXT_SELECTION_CHANGED
but none of these seems to work.
Now I can find a workaround for this specific use:
catch all the following events and I have about 95% of the cases
    wx.EVT_LEFT_DOWN
    wx.EVT_KEY_DOWN
    rt.EVT_RICHTEXT_CHARACTER
But I don't think this is real solution :wink:

thanks,
Stef Mientki

===== are these all the events specific for RichTextCtrl ??? =======
EVT_RICHTEXT_LEFT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, 1)
EVT_RICHTEXT_RIGHT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, 1)
EVT_RICHTEXT_MIDDLE_CLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, 1)
EVT_RICHTEXT_LEFT_DCLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, 1)
EVT_RICHTEXT_RETURN = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_RETURN, 1)
EVT_RICHTEXT_CHARACTER = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_CHARACTER, 1)
EVT_RICHTEXT_DELETE = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_DELETE, 1)

EVT_RICHTEXT_STYLESHEET_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING, 1)
EVT_RICHTEXT_STYLESHEET_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED, 1)
EVT_RICHTEXT_STYLESHEET_REPLACING = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING, 1)
EVT_RICHTEXT_STYLESHEET_REPLACED = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACED, 1)

EVT_RICHTEXT_CONTENT_INSERTED = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED, 1)
EVT_RICHTEXT_CONTENT_DELETED = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED, 1)
EVT_RICHTEXT_STYLE_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED, 1)
EVT_RICHTEXT_SELECTION_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_SELECTION_CHANGED, 1)

Stef Mientki wrote:

hello,

When using RichTextCtrl, there seems to be 2 different event types,
the general ones e.g.
   EVT_TEXT
and an equivalent RichText one
   EVT_RICHTEXT_CHARACTER

They both seemed to be fired, but the RichText equivalent gives many more properties back.
So I guess it's best to use the RichText equivalent.
Is that true ?

Essentially. The intent is that the RTC can be dropped in and used in place of a multi-line wx.TextCtrl without needing major changes to the code. So things like the events, styles, methods, attribute classes, etc. share or reimplement as much as possible. Obviously if you need more than what EVT_TEXT can give you then you should be using the RICHTEXT events.

Now I need to detect if the cursor is moving to another style,
so I would guess I should use either one of the following:
   rt.EVT_RICHTEXT_STYLE_CHANGED

This is for when the style of a block of text is changed to some new style, not when the caret moves to some text with a new style.

   rt.EVT_RICHTEXT_SELECTION_CHANGED

It looks like this one may not even be used at all yet, unless I'm not seeing something...

but none of these seems to work.
Now I can find a workaround for this specific use:
catch all the following events and I have about 95% of the cases
   wx.EVT_LEFT_DOWN
   wx.EVT_KEY_DOWN
   rt.EVT_RICHTEXT_CHARACTER
But I don't think this is real solution :wink:

Maybe a little simpler would be to do it from a EVT_IDLE or a EVT_TIMER handler. In the handler you can check if the current caret position changed since the last time you checked, and if it has you can get the style at that position, and the if that has changed you can change the values of your widgets.

BTW, have you looked at the UI for the Style Editor in Editra? It's not quite the same thing since it is for a StyledTextCtrl, but you could probably get some UI and Usability ideas from it.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!