lawsie / guizero

A Python 3 library to allow learners to quickly and easily create GUIs.
https://lawsie.github.io/guizero
BSD 3-Clause "New" or "Revised" License
406 stars 81 forks source link

Waffle mouse enter #461

Closed lawsie closed 1 year ago

lawsie commented 1 year ago

Change the waffle canvas so that it doesn't get destroyed when the bg colour is changed, but instead gets cleared. This stops two mouse enter events from firing - the original one, plus another one being instantly generated when the new canvas is created, because the mouse 'enters' the new canvas.

451

martinohanlon commented 1 year ago

I had 5 mins so I thought I would have a look at this. I move the code to size the waffle so it is sized each time the canvas is created.

https://github.com/lawsie/guizero/pull/461/commits/c73626dc26d042cb779a8705d62ac13b05588671

Pretty sure this resolves the issue. This test program raises 2 events in dev and only 1 in this branch.

from guizero import App, Waffle

def enter(e):
    waffle.bg = "red"
    print("enter", e)

def leave(e):
    waffle.bg = "white"
    print("leave", e)

app = App()

waffle = Waffle(app)
waffle.when_mouse_enters = enter
waffle.when_mouse_leaves = leave

app.display()

All tests pass and example programs run as you might expect.

@lawsie could you test?

lawsie commented 1 year ago

I’ll have a look when I next get a bit of spare time, no problem :)

On Fri, 16 Dec 2022 at 16:35, martinohanlon @.***> wrote:

I had 5 mins so I thought I would have a look at this. I move the code to size the waffle so it is sized each time the canvas is created.

c73626d https://github.com/lawsie/guizero/commit/c73626dc26d042cb779a8705d62ac13b05588671

Pretty sure this resolves the issue. This test program raises 2 events in dev and only 1 in this branch.

from guizero import App, Waffle def enter(e): waffle.bg = "red" print("enter", e) def leave(e): waffle.bg = "white" print("leave", e) app = App() waffle = Waffle(app)waffle.when_mouse_enters = enterwaffle.when_mouse_leaves = leave app.display()

All tests pass and example programs run as you might expect.

@lawsie https://github.com/lawsie could you test?

— Reply to this email directly, view it on GitHub https://github.com/lawsie/guizero/pull/461#issuecomment-1355188770, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHRRUNOYRHF4OKONJODVSDWNSK47ANCNFSM6AAAAAASKOVCDY . You are receiving this because you were mentioned.Message ID: @.***>

--

Laura Sach

Senior Learning Manager (Post-16)

Raspberry Pi Foundation

UK registered charity 1129409

raspberrypi.org http://www.raspberrypi.org/ | codeclub.org http://www.codeclub.org | coderdojo.com http://www.coderdojo.com

@codeboom https://twitter.com/codeboom

martinohanlon commented 1 year ago

I am really confident this works. I am going to push into dev. Consious there are a few changes which have been hanging around so I thought i would do a release imminently.