GTK3 keyboard errors

Post

Posted
Rating:
#1 (In Topic #1436)
Regular
rj71 is in the usergroup ‘Regular’
Hi All,

I asked this as a follow up question in my previous post but I figured I should start a new topic to get more eyes on it. I have a personal app where 100% of the user (me) input will be with a linux friendly remote I found on Amazon. Very similar to amazon's firestick remote. The remote control will be handled with keypress events. The code below I am trying to get some panels to slide in and out of view. It works great if I have it in a button. If I put that code in a keypress event I get "gb.gtk3: warning: calling the event loop during a keyboard event handler is ignored". The panels do move but I lose the sliding effect. I understand it is probably the Wait 0.1 that I have in there but if I remove the wait, then I lose my "animated" panel slide. Any suggestions on how to handle this? The remote control is essential for this project, if i can't use it then there is no point continuing because using a mouse would be silly for this.

Maybe there is something more I need to do with a keypress event?





Code (gambas)

  1. dypan1.Y = dypan1.Y - 1
  2. Wait 0.1
  3. dypan1.Y = dypan1.Y - 2
  4. Wait 0.1
  5. dypan1.Y = dypan1.Y - 3
  6. Wait 0.1
  7. dypan1.Y = dypan1.Y - 4
  8. Wait 0.1
  9. dypan1.Y = dypan1.Y - 5
  10. Wait 0.1
  11. dypan1.Y = dypan1.Y - 6
  12. Wait 0.1
  13. dypan1.Y = dypan1.Y - 7
  14. Wait 0.1
  15. dypan1.Y = dypan1.Y - 8
  16. Wait 0.1
  17. dypan1.Y = dypan1.Y - 9
  18. Wait 0.1
  19. dypan1.Y = dypan1.Y - 10
  20. Wait 0.1
  21. dypan1.Y = dypan1.Y - 11
  22. Wait 0.1
  23. dypan1.Y = dypan1.Y - 12
  24. Wait 0.1
  25. dypan1.Y = dypan1.Y - 13
  26. Wait 0.1
  27. dypan1.Y = dypan1.Y - 14
  28. Wait 0.1
  29. dypan1.Y = dypan1.Y - 15
  30. Wait 0.1
  31.  
  32.  
Online now: No Back to the top

Post

Posted
Rating:
#2
Regular
rj71 is in the usergroup ‘Regular’
 I am working an example project that I'll zip and post in a bit.
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
rj71 is in the usergroup ‘Regular’
 Here's a simple experiment I've been playing with.

Attachment
Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’
It's because you use Wait.

Wait will allow the event loop to run and you should not do that inside a key event.

Solutions…

Make a Timer and have the key event start the timer.

Code (gambas)

  1. Private $hTimer As Timer
  2.  
  3. Public Sub _New()
  4.  
  5.   $hTimer = New Timer As "MyTimer"
  6.   $hTimer.Delay = 0
  7.  
  8.  
  9. Public Sub Object_Keypress()
  10.  
  11.   If Key.Code = Key.Up Then   ' your proper key
  12.     If Not $hTimer.Enabled Then $hTimer.Start  ' start the timer
  13.  
  14.  
  15. Public Sub MyTimer_Timer()
  16.  
  17.   $hTimer.Stop  ' stop the timer
  18.  
  19.   ' use Wait as much as you like now as we are not in the key event any more.
  20.  
  21.  
  22.  


Or…

Maybe try using Sleep instead of Wait

Sleep will pause the program like Wait But not let the event loop run.  (but then your panel movement code might not work)

You will be wise to make a switch that cannot be enabled while already enabled, or keyboard repeat might make your code behave badly.
Online now: No Back to the top

Post

Posted
Rating:
#5
Regular
rj71 is in the usergroup ‘Regular’

BruceSteers said

It's because you use Wait.

Wait will allow the event loop to run and you should not do that inside a key event.

Solutions…

Make a Timer and have the key event start the timer.

Code (gambas)

  1. Private $hTimer As Timer
  2.  
  3. Public Sub _New()
  4.  
  5.   $hTimer = New Timer As "MyTimer"
  6.   $hTimer.Delay = 0
  7.  
  8.  
  9. Public Sub Object_Keypress()
  10.  
  11.   If Key.Code = Key.Up Then   ' your proper key
  12.     If Not $hTimer.Enabled Then $hTimer.Start  ' start the timer
  13.  
  14.  
  15. Public Sub MyTimer_Timer()
  16.  
  17.   $hTimer.Stop  ' stop the timer
  18.  
  19.   ' use Wait as much as you like now as we are not in the key event any more.
  20.  
  21.  
  22.  


Or…

Maybe try using Sleep instead of Wait

Sleep will pause the program like Wait But not let the event loop run.  (but then your panel movement code might not work)

You will be wise to make a switch that cannot be enabled while already enabled, or keyboard repeat might make your code behave badly.

Thanks Bruce. I figure it was the Wait but wasn't sure how to handle that. The sleep deosn't work either…you're right, the panel slide won't work with that either. The timer idea does seem to work though and I'll continue down that path, thanks for that. Yeah, I'll implement some enable/disable routines…that experiment project was just a crude example.
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Guru
cogier is in the usergroup ‘Guru’
I have got arrow keys working, as Bruce suggested, using a Timer. There is no need to stop and start the Timer as using Timer1.Trigger does the job. I have condensed your code considerably. Have a look here regarding the use of Quit to end programs.

Attachment
Online now: Yes Back to the top

Post

Posted
Rating:
#7
Regular
rj71 is in the usergroup ‘Regular’

cogier said

I have got arrow keys working, as Bruce suggested, using a Timer. There is no need to stop and start the Timer as using Timer1.Trigger does the job. I have condensed your code considerably. Have a look here regarding the use of Quit to end programs.

slidingpanelsexperiment-CO-0.0.2.tar.gz

Thanks cogier! I knew there had to be a way to condense that y axis move code I just haven't had time to experiment with it.
Online now: No Back to the top
1 guest and 0 members have just viewed this.