treectrl scroll

Hi Robin,

Thanks for the help… I was working on implementing that …

How can I make the tree control window scroll up and down?

I am trying to something like this on the timer

def OnDragTimerTimer(self, event):
pt=self.treeCtrl1.ScreenToClient(wx.GetMousePosition())
(sizeX,SizeY)=self.treeCtrl1.GetSize()
(x,y)=pt
if ((y<0) and (y > -10)):
print “scroll up”
if ((y>SizeY) and (y<(SizeY+10))):
print “scroll down”

Thanks

···

Thomas Thomas

phone +64 7 855 8478
fax +64 7 855 8871

Thomas Thomas wrote:

Hi Robin,
Thanks for the help.. I was working on implementing that ..
How can I make the tree control window scroll up and down?
I am trying to something like this on the timer
def OnDragTimerTimer(self, event):
        pt=self.treeCtrl1.ScreenToClient(wx.GetMousePosition())
        (sizeX,SizeY)=self.treeCtrl1.GetSize()
        (x,y)=pt
        if ((y<0) and (y > -10)):
            print "scroll up"
        if ((y>SizeY) and (y<(SizeY+10))):
            print "scroll down"

See wx.Window.ScrollLines

···

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

I still don't think I understand events, or how to use them, though I can usually get them working, it's still a mystery to me. Here are some of the questions I am wondering about (in case any of them might have a quick answer here):

For "X.Bind(wx.EVT, obj)" ...

Which window should I use as X for the base of the Bind? I started out using the window that generated the event, and always specifying "obj", and then realized I could just make the main Frame catch most events, without even specifying an object in the bind. Yet that doesn't seem to always work, and on occasion (for an EditableListCtrl) I have had to do the Bind with the button itself:

    editList.GetDelButton().Bind(wx.EVT_BUTTON, self.onButton, id=editList.GetDelButton.GetId())

What I thought I was doing when I specified "obj" in the Bind parameters, was map the event from this object to the handler in the given class. Yet this doesn't always seem to work, and also doesn't explain why I need the base window (i.e. X in X.Bind).

So I'm confused...

Thanks for any clarification on this,
Lee

P.S. As mentioned previously, I do appreciate the inAction book! Just one (more) request, I would root for expansion of the discussion in this area if possible...

Hi Lee,

Have a look at this thread:
http://article.gmane.org/gmane.comp.python.wxpython/31581

Basically you can do both
obj.Bind(EVT, handler)
and
self.Bind(EVT, handler, obj)

events always travel up the gui hierarchy, so if the event is fired by a button
inside a panel which itself is inside a frame, you can bind to the frame's event
handler, or to those of the panel or button directly.

   editList.GetDelButton().Bind(wx.EVT_BUTTON, self.onButton,
id=editList.GetDelButton.GetId())

The last argument is redundant in that case as you also bind directly to its
event handler.

Regards, Christian

   editList.GetDelButton().Bind(wx.EVT_BUTTON, self.onButton,

id=editList.GetDelButton.GetId())

The last argument is redundant in that case as you also bind directly to its
event handler.

Thanks! I thought I actually tried that, but indeed it works, I must have misremembered (deremembered?), and maybe that's how I got off track...

Lee

Robin Dunn <robin <at> alldunn.com> writes:

Thomas Thomas wrote:
> Hi Robin,
>
> Thanks for the help.. I was working on implementing that ..
> How can I make the tree control window scroll up and down?
>
> I am trying to something like this on the timer
> def OnDragTimerTimer(self, event):
> pt=self.treeCtrl1.ScreenToClient(wx.GetMousePosition())
> (sizeX,SizeY)=self.treeCtrl1.GetSize()
> (x,y)=pt
> if ((y<0) and (y > -10)):
> print "scroll up"
> if ((y>SizeY) and (y<(SizeY+10))):
> print "scroll down"

See wx.Window.ScrollLines

ScrollLines doesn't scroll and always return False here, when called like
self.ScrollLines(lines), where self is a TreeCtrl, even though the scrollbar is
neither at the top nor the bottom end.

What am I missing?

Regards, Christian

Christian Kristukat wrote:

Robin Dunn <robin <at> alldunn.com> writes:

Thomas Thomas wrote:

Hi Robin,
Thanks for the help.. I was working on implementing that ..
How can I make the tree control window scroll up and down?
I am trying to something like this on the timer
def OnDragTimerTimer(self, event):
        pt=self.treeCtrl1.ScreenToClient(wx.GetMousePosition())
        (sizeX,SizeY)=self.treeCtrl1.GetSize()
        (x,y)=pt
        if ((y<0) and (y > -10)):
            print "scroll up"
        if ((y>SizeY) and (y<(SizeY+10))):
            print "scroll down"

See wx.Window.ScrollLines

ScrollLines doesn't scroll and always return False here, when called like
self.ScrollLines(lines), where self is a TreeCtrl, even though the scrollbar is
neither at the top nor the bottom end.

What am I missing?

Which platform?

There is also the wx.TreeCtrl.ScrollTo method which sets the first visible item in the tree to be the item you pass to it. That would require some work to know which are the next visible items, etc.

···

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

Robin Dunn <robin <at> alldunn.com> writes:

Christian Kristukat wrote:
> ScrollLines doesn't scroll and always return False here, when called
> like self.ScrollLines(lines), where self is a TreeCtrl, even though the
> scrollbar is neither at the top nor the bottom end.
>
> What am I missing?

Which platform?

There is also the wx.TreeCtrl.ScrollTo method which sets the first
visible item in the tree to be the item you pass to it. That would
require some work to know which are the next visible items, etc.

Platform is wxGTK. Meanwhile I found an old posting by you concerning that
subject
http://article.gmane.org/gmane.comp.python.wxpython/18549
and copied "method 7" described therein. This works very good on wxGTK but
on wxMSW the motion events stop to occur when leaving the tree ctrl, which
sounds reasonable as I bind to the treectrl`s event manager. Now I could not
figure out how to recieve motion events from anywhere. Can you give me a
hint?

Christian

Christian Kristukat wrote:

Robin Dunn <robin <at> alldunn.com> writes:

Christian Kristukat wrote:

ScrollLines doesn't scroll and always return False here, when called
like self.ScrollLines(lines), where self is a TreeCtrl, even though the
scrollbar is neither at the top nor the bottom end.

What am I missing?

Which platform?

There is also the wx.TreeCtrl.ScrollTo method which sets the first visible item in the tree to be the item you pass to it. That would require some work to know which are the next visible items, etc.

Platform is wxGTK. Meanwhile I found an old posting by you concerning that
subject
http://article.gmane.org/gmane.comp.python.wxpython/18549
and copied "method 7" described therein.

Wow. It's really weird that I have no recollection at all of writing that.

This works very good on wxGTK but
on wxMSW the motion events stop to occur when leaving the tree ctrl, which
sounds reasonable as I bind to the treectrl`s event manager. Now I could not
figure out how to recieve motion events from anywhere. Can you give me a
hint?

If you have the tree capture the mouse, then it will get mouse events even when the cursor leaves the bounds of the window. Don't forget to release the capture in the mouse up event.

BTW, when you get it all working if you would create a recipe page in the wiki about how to it I'm sure everybody would appreciate it.

···

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

Robin Dunn <robin <at> alldunn.com> writes:

Christian Kristukat wrote:
> Robin Dunn <robin <at> alldunn.com> writes:
>
>> Christian Kristukat wrote:
>>> ScrollLines doesn't scroll and always return False here, when called
>>> like self.ScrollLines(lines), where self is a TreeCtrl, even though the
>>> scrollbar is neither at the top nor the bottom end.
>>>
>>> What am I missing?
>> Which platform?
>>
>> There is also the wx.TreeCtrl.ScrollTo method which sets the first
>> visible item in the tree to be the item you pass to it. That would
>> require some work to know which are the next visible items, etc.
>
> Platform is wxGTK. Meanwhile I found an old posting by you concerning that
> subject
> http://article.gmane.org/gmane.comp.python.wxpython/18549
> and copied "method 7" described therein.

Wow. It's really weird that I have no recollection at all of writing that.

> This works very good on wxGTK but
> on wxMSW the motion events stop to occur when leaving the tree ctrl, which
> sounds reasonable as I bind to the treectrl`s event manager. Now I could not
> figure out how to recieve motion events from anywhere. Can you give me a
> hint?

If you have the tree capture the mouse, then it will get mouse events
even when the cursor leaves the bounds of the window. Don't forget to
release the capture in the mouse up event.

I just got everything working and encountered something surprising. On wxMSW,
when the treectrl doesn't have an image list associated with it, the motion
events are not reported when leaving the treectrl, thus automatic scrolling
will not work! I found that out by accident when I was wondering why my
treectrl doesn't show those nice shadowed tree items while dragging - this
is another point that does not work if it is a plain text tree.

BTW, when you get it all working if you would create a recipe page in
the wiki about how to it I'm sure everybody would appreciate it.

I'll do so.

Christian

Christian Kristukat wrote:

I just got everything working and encountered something surprising. On wxMSW,
when the treectrl doesn't have an image list associated with it, the motion
events are not reported when leaving the treectrl, thus automatic scrolling
will not work!

<sigh> Why doesn't that surprise me? Just yet another oddity of the MS treeview...

BTW, when you get it all working if you would create a recipe page in the wiki about how to it I'm sure everybody would appreciate it.

I'll do so.

Thanks.

···

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