How to get chars that are actually displayed in wx.TextCtrl?
I am trying to underline some specific words in single line wx.textctrl. I'm doing it by calculating position of a word in the control using GetTextExtent and drawing lines using wx.ClintDC.
My problem begins when text in TextCtrl is longer then size of the control, for example if user inputs ~100 chars he can see only 20 last characters if the control is not long enough.
My question is: how can I get a string which is actually displayed in the single line control? or how can I calcu开发者_运维问答late the width of the text which is not displayed (on the left side) in pixels?
Single line text control has no scroll bar. The GetInsertionPoint returns position of caret in text, but it's impossible to translate it to the actual distance in pixels from the left border of control.
I don't want to use TE_RICH or TE_RICH2 styles not StyledTextCtrl class because they don't support right-to-left text.
I think you have to use one of the TE_RICH style to underline text in a wx.TextCtrl. Have you tried the StyledText controls? They use scintilla which might give you more control.
There's also the ExpandoTextCtrl, which will expand as the user types.
Also if you set the locale, you should get the right-to-left behavior automagically: http://wiki.wxpython.org/Internationalization#Switching_between_Left_to_Right_and_Right_to_Left_Languages
I don't really see a method to just grab the part of the string that is visible. You'll have to calculate it using the font's width and probably using the Selection methods of the text control. You may want to cross-post to the wxPython mailing list too. They would probably have ideas too.
Ok, the solution I've found is:
from win32api import SendMessage
result = SendMessage(self.GetHandle(), EM_POSFROMCHAR, 0, 0)
result is client coordinates of the first character in the control. The value is negative if the specified character is not displayed in the edit control's client area.
精彩评论