The purpose: For the specific OCR post-processing application, I am displaying part of the text that should be copy/pasted to another application. It should be as much minimalistic and user friendy as possible (no complex moves by mouse, intuitive). The wxPython application was created for the prototype purpose, and the wx.sct.StyledTextCtrl
is used to display the text (referred as ctrl
further in the text).
The user wants: The mouse-selected text must be automatically added to the clipboard. (The ctrl.Copy()
inside the onUpdateUI
handler -- no problem here.) However, the long lines are often used (as text paragraphs to be word-wrapped later), and the user wants the easier selection of one or more paraghaphs. She would like to select a paragraph whenever it is touched -- when dragging the mouse. In other words, she wants to be released from the need to focus on precise start and end selection positions. That means, the starting line selection should be extended to the HOME of the line, and the ending line selection should be extended to the END.
Mouse single click should just place caret for editing. (That works in the prototype solution below.)
Mouse double-click should behave as usual -- select the word. (That does not work in the solution below.)
Mouse tripple-click select the whole line. (That does not work, either.)
Current simple/prototype solution: The EVT_STC_UPDATEUI
event is handled by the onUpdateUI
method:
self.Bind(wx.stc.EVT_STC_UPDATEUI, self.onUpdateUI)
The implementation seemingly works, but only in limited scenarios:
def onUpdateUI(self, evt):
ctrl = self.textCtrl
p1, p2 = ctrl.GetSelection()
if p1 != p2: # do not select if user just wants to edit
ctrl.SetInsertionPoint(p1)
ctrl.Home()
ctrl.SetInsertionPoint(p2)
ctrl.LineEndExtend()
ctrl.Copy() # selected text to clipboard
Firstly, it works only when the mouse cursor is dragged from top down. When dragged from bottom up, only the last touched line (the topmost one) is selected.
Secondly, when the extremely long word-wrapped line (that is a long paragraph, that fills more space than window) does not start at the screen, the ctrl.SetInsertionPoint(p1)
and later the ctrl.LineEndExtend()
causes flickering, and the window is scrolled so that the bottom of the paragraph is displayed on the bottom of the window. Moreover, it is not possible to scroll the window with the selected text, as the onUpdateUI
does the calculation again, and ends in the window just flickers and remains all the time in the same position.
Thirdly, the ctrl.Copy()
(often with large text selected) is called very frequently, and it can cause clipboard error like on the image below:
The question: Is the EVT_STC_UPDATEUI
handler the right place to implement the selection-related code?
Are there any other StyledTextCtrl
methods to extend the selection without moving the caret (other than .SetInsertionPoint
, .Home
, and .LineEndExtend
)? Say, would it be better to search the nearest \n
character and/or the start/end positions of the whole text to get positions to be used for the selection (after the mouse button is released)?
The user would also like (later) to recognize specific texts to be visually emphasized, and moved to the clipboard as the rich text. Think in terms like:
Diagnosis: The patient ... sdflksfs lsdl ksdf neuropathy sdlkfj sldk sdlfk sl
So, possibly the RichTextCtrl
is to be used later it the StyledTextCtrl
would be less suitable for the purpose. If you see that the RichTextCtrl
is the must, then I would like to have the above described solution for the RichTextCtrl
from the start (not to waste time with the StyledTextCtrl
).
Any suggestions on how to combine usual work with the mouse and selection with automatic update of the clipboard, possibly make the current content of the clipboard visible in the window (like some light background color, or so) are highly welcome.
(I am still learning the StyledTextCtrl
, there probably is a better approach that I am not aware of.)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745117661a4612226.html
评论列表(0条)