Issue with Canvas and ScrolledWindow

Hello,

I'm trying to put a Canvas inside a ScrolledWindow but I have a strange scroll movement when the Frame receives de Focus.

If you try the attached code and change the focus with another window, when the frame receive the focus makes an strange scroll movement automatically.

What are I doing bad?

Windows XP, wx 2.8.9.1 (msw-unicode)

Thanks

scrolltest2.py (1.42 KB)

···

--
*****************************************
Oswaldo Hernández
oswaldo (@) soft-com (.) es
*****************************************
PD:
Antes de imprimir este mensaje, asegúrese de que es necesario.
El medio ambiente está en nuestra mano.

Oswaldo Hernández wrote:

I'm trying to put a Canvas inside a ScrolledWindow but I have a strange scroll movement when the Frame receives de Focus.

You don't want to put a Canvas like this on a SColledWindow, you want it to Be a ScrolledWindow:'

class Canvas(wx.ScrolledWindow):
     def __init__(self, parent, id, *args, **kwds):
         wx.Window.__init__(self, parent, id, *args, **kwds)

see the ScrolledWindow demo in the main wxPython demo -- it's a simple canvas.

Also, depending on what you want your "Canvas" to do, you may want to use an existing higher level drawing tools, like FloatCanvas or OGL

-CHB

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Christopher Barker escribió:

Oswaldo Hernández wrote:

I'm trying to put a Canvas inside a ScrolledWindow but I have a strange scroll movement when the Frame receives de Focus.

You don't want to put a Canvas like this on a SColledWindow, you want it to Be a ScrolledWindow:'

class Canvas(wx.ScrolledWindow):
    def __init__(self, parent, id, *args, **kwds):
        wx.Window.__init__(self, parent, id, *args, **kwds)

see the ScrolledWindow demo in the main wxPython demo -- it's a simple canvas.

I have viewed the ScrolledWindow demo but i do not want a full ScrolledWindow canvas.
I'm tring to do a box inside the scroll window, with margins around, and use it as canvas.

···

--
*****************************************
Oswaldo Hernández
oswaldo (@) soft-com (.) es
*****************************************
PD:
Antes de imprimir este mensaje, asegúrese de que es necesario.
El medio ambiente está en nuestra mano.

Hi Oswaldo,

Christopher Barker escribió:

Oswaldo Hernández wrote:

I'm trying to put a Canvas inside a ScrolledWindow but I have a strange scroll movement when the Frame receives de Focus.

You don't want to put a Canvas like this on a SColledWindow, you want it to Be a ScrolledWindow:'

class Canvas(wx.ScrolledWindow):
    def __init__(self, parent, id, *args, **kwds):
        wx.Window.__init__(self, parent, id, *args, **kwds)

see the ScrolledWindow demo in the main wxPython demo -- it's a simple canvas.

I have viewed the ScrolledWindow demo but i do not want a full ScrolledWindow canvas.
I'm tring to do a box inside the scroll window, with margins around, and use it as canvas.

What about the ScrolledPanel widget? Does that work for your use case?

Mike

Oswaldo Hernández wrote:

Hello,

I'm trying to put a Canvas inside a ScrolledWindow but I have a strange scroll movement when the Frame receives de Focus.

If you try the attached code and change the focus with another window, when the frame receive the focus makes an strange scroll movement automatically.

The scroll comes from the fact that wx.ScrolledWindow has gained some code like what we've had in wx.lib.scrolledpanel for a long time. It is now trying to move the focused child into view when it gains the focus. You can probably work around this by intercepting the EVT_CHILD_FOCUS event and not allowing it to get to the scrolled window.

···

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

Robin Dunn escribió:

Oswaldo Hernández wrote:

Hello,

I'm trying to put a Canvas inside a ScrolledWindow but I have a strange scroll movement when the Frame receives de Focus.

If you try the attached code and change the focus with another window, when the frame receive the focus makes an strange scroll movement automatically.

The scroll comes from the fact that wx.ScrolledWindow has gained some code like what we've had in wx.lib.scrolledpanel for a long time. It is now trying to move the focused child into view when it gains the focus. You can probably work around this by intercepting the EVT_CHILD_FOCUS event and not allowing it to get to the scrolled window.

Works :slight_smile:

Thanks Robin.

···

--
*****************************************
Oswaldo Hernández
oswaldo (@) soft-com (.) es
*****************************************
PD:
Antes de imprimir este mensaje, asegúrese de que es necesario.
El medio ambiente está en nuestra mano.

Mike escribió:

Hi Oswaldo,

Christopher Barker escribió:

Oswaldo Hernández wrote:

I'm trying to put a Canvas inside a ScrolledWindow but I have a strange scroll movement when the Frame receives de Focus.

You don't want to put a Canvas like this on a SColledWindow, you want it to Be a ScrolledWindow:'

class Canvas(wx.ScrolledWindow):
    def __init__(self, parent, id, *args, **kwds):
        wx.Window.__init__(self, parent, id, *args, **kwds)

see the ScrolledWindow demo in the main wxPython demo -- it's a simple canvas.

I have viewed the ScrolledWindow demo but i do not want a full ScrolledWindow canvas.
I'm tring to do a box inside the scroll window, with margins around, and use it as canvas.

What about the ScrolledPanel widget? Does that work for your use case?

The same issue.
Robin gave the the solution with EVT_CHILD_FOCUS.

Thanks.

···

--
*****************************************
Oswaldo Hernández
oswaldo (@) soft-com (.) es
*****************************************
PD:
Antes de imprimir este mensaje, asegúrese de que es necesario.
El medio ambiente está en nuestra mano.