jverzani / gWidgets2

Rewrite of gWidgets
35 stars 9 forks source link

delay closing of galert() when mouse pointer is hovering the widget #88

Closed landroni closed 8 years ago

landroni commented 8 years ago

This is a minor gripe, but would make for useful UI-practice.

Currently galert(..., delay = 5) message will close after 5 second delay, no matter what. Often for users this may not be sufficient time to process and understand the message. It would help if galert() could detect if user hovers the message widget with the mouse, and delay clearing up the message until the mouse is moved outside the widget area (i.e. mouse no longer hovers widget). This is intuitive once the user realizes that hovering the widget has this effect.

There is precedent for such a UI approach in Opera 12.x when hovering the galert-similar "Do you want to save password?" widget.

jverzani commented 8 years ago

I have the opposite behaviour, when the mouse motion is detected the window should close. This means you can set the delay to be longer, and have the user dismiss with the mouse.

Changing to your expectations isn't hard. Something like this would work I suppose:

set time with default of 5 detect mouse motion (motion-notify-event) and stop timer if so detect mouse leave (leave-notify-event) and restart timer or destroy window (one of the two)

What would be more natural?

landroni commented 8 years ago

For me most intuitive would be:

jverzani commented 8 years ago

Okay, this should be fixed iwth 8ac03a7 of gWidgets2RGtk2.

landroni commented 8 years ago

I tested latest GIT but I can't notice any change in behavior. With:

galert("Message", delay=5, parent=gwindow())

the message closes automatically even if the mouse is hovering the widget (or the OK button). Shouldn't it halt automatic closing until the mouse is detected to have been moved outside the widget area?

jverzani commented 8 years ago

Did you update gwidgets2rgtk2? That's is where the changes are.

landroni commented 8 years ago

Yes, both packages:

install_github("jverzani/gWidgets2RGtk2")
install_github("jverzani/gWidgets2")

I'm not sure what's wrong...

jverzani commented 8 years ago

Can you try the code that should be called to see if it works?

 library(RGtk2)
options(guiToolkit="RGtk2")
library(gWidgets2)
w <- gtkWindow(show=FALSE)
w$setDefaultSize(300, 150)
evb <- gtkEventBox()
evb$SetVisibleWindow(FALSE)
evb$AddEvents(GdkEventMask["all-events-mask"])
l <- gtkLabel(msg)
evb$add(l); w$add(evb)

motion_notify_cb <- function(...) {
    if(timer$started)
        timer$stop_timer()
    FALSE
}
gSignalConnect(evb, "motion-notify-event", f=motion_notify_cb)
leave_notify_cb <- function(...) {
    timer$set_interval(2*1000)
    timer$start_timer()
    FALSE
}
gSignalConnect(evb, "leave-notify-event", f=leave_notify_cb)

w$show()

f <- function(...) {
    timer$stop_timer()
    if(!is(w, "<invalid>"))
        w$destroy()
    FALSE
}

timer <- gtimer(delay*1000, FUN=f, one.shot=TRUE)
landroni commented 8 years ago

I tested the code and indeed it works as expected: leaving the mouse outside the window makes it auto-close as per the delay. Moving the mouse inside the window stops the counter, and the window doesn't close until mouse is moved outside.

jverzani commented 8 years ago

Hmm, odd that was nearly a copy and paste. I'll have a look

On Monday, December 14, 2015, landroni notifications@github.com wrote:

I tested the code and indeed it works as expected: leaving the mouse outside the window makes it auto-close as per the delay. Moving the mouse inside the window stops the counter, and the window doesn't close until mouse is moved outside.

— Reply to this email directly or view it on GitHub https://github.com/jverzani/gWidgets2/issues/88#issuecomment-164580622.

John Verzani Chair, Department of Mathematics College of Staten Island, CUNY verzani@math.csi.cuny.edu