I've got a wx.ScrolledWindow that I'm using to display images in. I have a mouse and keyboard event set so that when the user holds the space bar and drags their mouse, the ScrolledWindow should move with the mouse movement, displaying different parts of the image. I can get the ScrolledWindow to scroll up and left, but not right or down. This is an odd bug that I can't figure out. Does anyone have any ideas?
The following code should increase or decrease the Scrollbar by 1. I do this by finding the initial location of the Scrollbar (init_pos_x and init_pos_y) and then updating the position, using the Scroll(x, y) method.
I get the initial coordinates by using (I think this may be the problem):
init_pos_x, init_pos_y = self.scroll.GetViewStart()
previous_x and previous_y are the previous location of the user's mouse. x and y are the new location of the user's mouse.
if self.previous_y < y: # Scroll up (user drags down)
self.scroll.Scroll(init_pos_x, init_pos_y - 1)
elif self.previous_y > y: # Scroll down (user drags up)
self.scroll.Scroll(init_pos_x, init_pos_y + 1)
elif self.previous_x < x: # Scroll left (user drags right)
self.scroll.Scroll(init_pos_x - 1, init_pos_y)
elif self.previous_x > x: # Scroll right (user drags left)
self.scroll.Scroll(init_pos_x + 1, init_pos_y)
To reiterate, this is only working for scrolling up and scrolling left. Is there any reason this method would not work for scrolling down and scrolling right?
EDIT: The conditions are executing for scrolling down and scrolling right, but it's just not doing anything.
Thank you