Deleting an item from a scrolledPanel display doesn't always work.

1,469 views
Skip to first unread message

Mel Tearle

unread,
Jul 19, 2019, 5:58:35 PM7/19/19
to wxPython-users
I've a function that deletes a selected item from a scrolled panel.  As long as I move the mouse to select an item prior to clicking on it - the delete will work. The selected item pops off the display and if there are any additional items they'll move up to fill the vacancy.  However, if I don't move the mouse after a click and try to delete the new item that appears underneath the mouse pointer nothing happens.  I have to move the mouse, even if if it's only a few pixels in order for the click/delete to work. 

def addImageTile(self, evt, fname):
self.scrollCount += 1
tile = makeTile(fname, self.scrollPanel, self.scrollCount)
self.scrollList.append(tile.id)
tile.Bind(wx.EVT_RIGHT_DOWN,
lambda evt,
tmp=(tile.id,tile.GetLabel()):
self.delete(evt,tmp))
self.scrollSizer.Add(tile, 0, wx.ALL, .5)
self.setUpScroll()
self.bottom(evt)

def delete(self, evt, tmp):
p = self.scrollList.index(tmp[0])
self.scrollSizer.Hide(p)
self.scrollSizer.Remove(p)
self.scrollCount -= 1
del self.scrollList[p]
self.setUpScroll()
def setUpScroll(self):
self.scrollPanel.SetupScrolling(
scroll_x=False, scroll_y=True,
rate_x=0, rate_y=4,
scrollToTop=False, scrollIntoView=True)



Robin Dunn

unread,
Jul 19, 2019, 9:15:39 PM7/19/19
to wxPython-users

On Friday, July 19, 2019 at 2:58:35 PM UTC-7, Mel Tearle wrote:
I've a function that deletes a selected item from a scrolled panel.  As long as I move the mouse to select an item prior to clicking on it - the delete will work. The selected item pops off the display and if there are any additional items they'll move up to fill the vacancy.  However, if I don't move the mouse after a click and try to delete the new item that appears underneath the mouse pointer nothing happens.  I have to move the mouse, even if if it's only a few pixels in order for the click/delete to work. 


I've seen something like this before. I think Windows needs some mouse motion events in order to know that the mouse has entered the widget's bounds, and it won't send click events unless it knows that the cursor is inside the widget. When the widget moves under the pointer, instead of the other way around, it confuses that logic.

Calling self.WarpPointer with an offset of (1,1) from the current position might be enough to trigger the entered state. You can use wx.MouseState to get the current position in screen coordinates, and then self.ScreenToClient to convert that to window coordinates for the call to WarpPointer.

--
Robin
 

Mel Tearle

unread,
Jul 20, 2019, 1:31:41 AM7/20/19
to wxPython-users
Hi Robin,

Tried it but it didn’t work. I could see the pointer moving on its own
but it had no effect in letting me click until I actually moved the pointer.

ms = wx.GetMouseState()
print(ms.x, ms.y)
pos = self.ScreenToClient(ms.x, ms.y)
print(pos[0], pos[1])
self.WarpPointer(pos[0]-25, pos[1]+25)
self.WarpPointer(pos[0]-1, pos[1]-1)

Other than using WarpPointer is there any other way to simulate a mouse
pointer move?

Thanks for the help.

Mel
> --
> You received this message because you are subscribed to the Google Groups "wxPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/ed69c7fb-2dcf-4451-9a5e-4f27dd3f8ecf%40googlegroups.com.

Robin Dunn

unread,
Jul 20, 2019, 2:05:26 PM7/20/19
to wxPython-users


On Friday, July 19, 2019 at 10:31:41 PM UTC-7, Mel Tearle wrote:
Hi Robin,

Tried it but it didn’t work.  I could see the pointer moving on its own
but it had no effect in letting me click until I actually moved the pointer.

        ms = wx.GetMouseState()
        print(ms.x, ms.y)
        pos = self.ScreenToClient(ms.x, ms.y)
        print(pos[0], pos[1])
        self.WarpPointer(pos[0]-25, pos[1]+25)    
        self.WarpPointer(pos[0]-1, pos[1]-1)

Other than using WarpPointer is there any other way to simulate a mouse
pointer move?


Try wx.UIActionSimulator.MoveMouse. If that doesn't help then you should also try doing the move (either WarpPointer or MoveMouse) from a function invoked with CallAfter so the moved widgets have a chance to process their own event handlers associate with the move first.

BTW, wx.Point (and similar classes) support + and - operators, so you can do things like this to offset a wx.Point to a new wx.Point object:

>>> pos = wx.Point(12,34)
>>> pos + (1,1)
wx.Point(13, 35)

--
Robin

Mel Tearle

unread,
Jul 20, 2019, 5:20:33 PM7/20/19
to wxpytho...@googlegroups.com
Hi,
I guess I’ll have to live with it for now,
the last changes moved the pointer but didn’t trip the event.  I was thinking If there were a way to tell the mouse pointer that it’s left the old window and entered a new one, that might work.  Is it possible to do something like that?
Thank you once again.
Mel
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.

Robin Dunn

unread,
Jul 25, 2019, 11:19:58 PM7/25/19
to wxPython-users


On Saturday, July 20, 2019 at 2:20:33 PM UTC-7, Mel Tearle wrote:
  I was thinking If there were a way to tell the mouse pointer that it’s left the old window and entered a new one, that might work.  Is it possible to do something like that?

Not that I know of.

Reply all
Reply to author
Forward
0 new messages