wx.textctrl scrolling event?

Hi all,

I'm trying to build a app that contains two multiline textctrl
(richtextctrl's ok too) next to each other, with one serving as user input
and the other output (think it as some sort of translation tool).

A requirement for this app is that when the user scrolls up/down in the
"input" textctrl, the other textctrl should follow and scroll to the same
position as input, thus I need to somehow "capture" the scrolling of the
input and that's where I run into problem: I'm unable to find out what
events are triggered when the scrolling happens.

EVT_SCROLL clearly won't work, and I've read somewhere here that
EVT_SCROLLWIN works only because a happy accident - in my case I can't even
use EVT_SCROLLWIN as a substitute, for that it only captures movement on
thumb and click on scroll bar but unable to handle scrolls triggered by
keyboard (pgup, pgdown, up, down etc).

There're just too many possible ways(mouse-wheel, keyboard, scroll via
scrollbar etc) to scroll the textctrl to utilize some dodgy key-down
workarounds I can think of, so em, any suggestions?

much appreciated,

F

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/wx-textctrl-scrolling-event-tp4509810p4509810.html
Sent from the wxPython-users mailing list archive at Nabble.com.

Hi,
I fear, there isn't a simple way of doing this out of the box using TextCtrl.

You probably found my older post for this
http://wxpython-users.1045709.n5.nabble.com/problem-getting-the-HitTest-position-after-scrolling-td2370732.html
http://wxpython-users.1045709.n5.nabble.com/scrollwin-event-of-a-wx-TextCtrl-on-linux-Kubuntu-td2372230.html

where the recommendations imply, one would be happier using another widget.

Anyway, you can try to inspect the supported events and many other
properties ot the UI using wxPython Widget Inspection Tool (WIT)
http://wiki.wxpython.org/Widget%20Inspection%20Tool
you just add the following lines in your code
import wx.lib.inspection
wx.lib.inspection.InspectionTool().Show()

and locate the needed widget (i.e. TextCtrl), then you can see and see
the events generated with some actions in your app (in the "Events"
part of WIT).

Now I see multiple scrolling events (which may or may not help you -
possibly some of them could be newer additions (?)) - using Python
2.7.2 on win32, wxPython 2.9.1.1 (msw-unicode) - win 7.
some of the ones shown via dir(wx) are:
'EVT_SCROLL', 'EVT_SCROLLBAR', 'EVT_SCROLLWIN',
'EVT_SCROLLWIN_BOTTOM', 'EVT_SCROLLWIN_LINEDOWN',
'EVT_SCROLLWIN_LINEUP', 'EVT_SCROLLWIN_PAGEDOWN',
'EVT_SCROLLWIN_PAGEUP', 'EVT_SCROLLWIN_THUMBRELEASE',
'EVT_SCROLLWIN_THUMBTRACK', 'EVT_SCROLLWIN_TOP', 'EVT_SCROLL_BOTTOM',
'EVT_SCROLL_CHANGED', 'EVT_SCROLL_ENDSCROLL', 'EVT_SCROLL_LINEDOWN',
'EVT_SCROLL_LINEUP', 'EVT_SCROLL_PAGEDOWN', 'EVT_SCROLL_PAGEUP',
'EVT_SCROLL_THUMBRELEASE', 'EVT_SCROLL_THUMBTRACK', 'EVT_SCROLL_TOP',

The char events for line: up, down, page: up/down (and possibly
continuous left/right causing scrolling) as well as selecting the text
with the mouse involving scrolling would probably have to be handled
separately anyway.
cf. some key events like WXK_UP, WXK_DOWN, WXK_PAGEUP, WXK_PAGEDOWN,
but possibly many other can result in scrolling (writing or deleting
multiple lines of text...)
http://www.wxpython.org/docs/api/wx.KeyEvent-class.html

One can maybe use simple continuous position checks with a timer. It
might work well enough, with some delay.

I'd really like to learn some straightforward way for such tasks too.

regards,
vbr

···

2011/6/21 fzix <fzho@nieir.com.au>:

Hi all,

I'm trying to build a app that contains two multiline textctrl
(richtextctrl's ok too) next to each other, with one serving as user input
and the other output (think it as some sort of translation tool).

A requirement for this app is that when the user scrolls up/down in the
"input" textctrl, the other textctrl should follow and scroll to the same
position as input, thus I need to somehow "capture" the scrolling of the
input and that's where I run into problem: I'm unable to find out what
events are triggered when the scrolling happens.

EVT_SCROLL clearly won't work, and I've read somewhere here that
EVT_SCROLLWIN works only because a happy accident - in my case I can't even
use EVT_SCROLLWIN as a substitute, for that it only captures movement on
thumb and click on scroll bar but unable to handle scrolls triggered by
keyboard (pgup, pgdown, up, down etc).

There're just too many possible ways(mouse-wheel, keyboard, scroll via
scrollbar etc) to scroll the textctrl to utilize some dodgy key-down
workarounds I can think of, so em, any suggestions?

much appreciated,

F

Thank you very much...It's indeed your 2nd post I came across before when I
was performing a frenetic search :), and both posts are interesting read to
say at least.

In my trail & error I've noticed the following things:

- the CallAfter method indeed "lags" ("reversed-lags" actually) in the
evt_mousewheel + textctrl.HitTest() case;

- This however only happens in TextCtrl - RichTextCtrl's immune to this
problem;

- GetScrollPos() in conjuration with RichTextCtrl.Scroll() performs sync
pretty well, but for obvious reasons the GetScrollPos() only works on a
windows machine...;

- the documentation of richtext.richtextctrl.HitTestXY()'s funny in which it
says HitTextRC();

- richtext.HitTestXY() refuses to work and I think it wont work in any cases
since:
       - document says it takes a single wxPoint as argument but that's
incorrect
       - what it really do is pass args tho to
_richtext.RichTextCtrl_HitTestXY(*args, **kwargs)
       - in this SWIG following define's used:
            char * kwnames[] = {
    (char *) "self",(char *) "pt",(char *) "OUTPUT",(char *) "OUTPUT", NULL
  };
         and after parse, should any of them absence a SWIG_fail's thrown;
       - the 2nd and 3rd arguments (two OUTPUT) is then tested against type
wxTextCoord...:stuck_out_tongue:
       - see richtext_wrapper.cpp L21585-L21637 for more details;

- I dont know if there're more straightforward methods but I end up doing
this and it so far works with no mousewheel glitch and runs in both linux &
windows:

(with CallAfter)
point = rtbInput.HitTest((0,0))
pointus = rtbInput.CalcUnscrolledPosition(pt)
ppu = rtbInput.GetScrollPixelsPerUnit()
rtbOutput.Scroll(0,(pointus[1]-point[1]) / ppu[1])

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/wx-textctrl-scrolling-event-tp4510951p4512784.html
Sent from the wxPython-users mailing list archive at Nabble.com.