Warning message in IDE when running app

New to Gambas? Post your questions here. No question is too silly or too simple.
Diverod
Posts: 28
Joined: Friday 12th November 2021 1:31am
Location: North Central Florida

Warning message in IDE when running app

Post by Diverod »

Just finishing up my 1st small utility and noticed that I get a warning in the IDE that says:
"gb.qt5: warning: calling the event loop during a keyboard event handler is ignored"

I get this if I use Ctrl+c or Ctrl+s, which I use as a shortcut in the utility to call a Copy or Save event of an image. Everything appears to work fine but it left me wondering if I shouldn't be using those particular keys or maybe Gambas gives this warning because Gambas itself uses these keys within the IDE. The Ctrl+u that I use doesn't give any warning.

I'm now on Gambas 3.16.3 and Ubuntu 20.04.3. Thanks for any insight.
User avatar
cogier
Site Admin
Posts: 1117
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Warning message in IDE when running app

Post by cogier »

The error is a QT error, not a Gambas error. I suspect that you have a Form_MouseDown(), or similar, routine that catches all the keyboard activity. With Ctrl-S and Ctrl-C these will be caught by the system as well, so there may be a conflict there. You can ignore the error if all else is well. For more help, please post your program, so we can test it out for you.
Diverod
Posts: 28
Joined: Friday 12th November 2021 1:31am
Location: North Central Florida

Re: Warning message in IDE when running app

Post by Diverod »

Okay, but don’t laugh too much at my code as I’m still trying to understand a lot of this. Everything seems to work but if I could understand the warning better it would be beneficial.

This utility was made for a specific purpose. I copy a keyword and paste it into a “maps” search-box, on the web. I then save an image of maps results (at a specific size) to a specific folder with the file name consisting of the keyword, date and the number of the client position in the listing(added manually).

I’m trying to switch from Windows to Ubuntu and I need this and one other utility before I can totally leave Windows behind. I’m retired and do a little SEO side-work and this changes a 1 hour job into about 7 minutes for me.

Thank you for taking the time to look at this.
Attachments
ScreenCap.tar.gz
(63.55 KiB) Downloaded 184 times
User avatar
cogier
Site Admin
Posts: 1117
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Warning message in IDE when running app

Post by cogier »

Well, I can't stop the message appearing. Maybe someone else will have an idea about this.

The way you have gone about your screen capture is very novel. I have written a screen capture program, ScreenShot that is on the Gambas Farm if you are interested. Your code looks pretty good to me. I had a good look and have come up with a few ideas, code attached.

The first point is the 'dark art' of the Gambas expanding forms. It takes a bit of grasping. I have removed a lot of the code in the Form_Resize() routine by changing various Properties on the Form and also changed some panels into HBoxes and VBoxes and deleted the ScrollView. There is no quick way to explain all this, again I have put up a program on the Gambas Farm called ExpandingForms that will hopefully help. The code changes I have made are higlighted.

In the Project Properties, if you click on the 'image' you can select a picture that will appear on the desktop when you create an executable with a desktop shortcut.

I hope some of this helps.

ImageImage
ScreenCap-0.1.tar.gz
(43.36 KiB) Downloaded 192 times
Diverod
Posts: 28
Joined: Friday 12th November 2021 1:31am
Location: North Central Florida

Re: Warning message in IDE when running app

Post by Diverod »

Thanks so much for investing your time on this.
I have downloaded your attachment and will study the modifications. I wanted to use the HBoxes and VBoxes but I don't really understand them well at this point so I fell back on a more comfortable similarity from VB.net. I will definitely look at ExpandingForms in the Gambas Farm as I struggled with this too.
User avatar
BruceSteers
Posts: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Warning message in IDE when running app

Post by BruceSteers »

I believe your error is because you use the "Wait" command in the Capture function.

Wait() in Gambas triggers a function like VB's DoEvents() to check the event loop for pending events, qt does not like it inside a keyboard event handler.

Because the Capture() command is run from the Form_KeyPress() event you are "in the keyboard event handler" the event loop is then triggered using the Wait command.

Try the Sleep command instead of Wait.


Or run Capture() separate from the event handler using a timer.

attached your project with my RunFree.class added to it and the keyboard event commands now like this...

RunFree(Me, "Capture", [False])


I tested this method with your app and it works,, running that way the keyboard event handler is freed.
If at first you don't succeed , try doing something differently.
BruceS
Diverod
Posts: 28
Joined: Friday 12th November 2021 1:31am
Location: North Central Florida

Re: Warning message in IDE when running app

Post by Diverod »

Thanks Bruce for investing your time also. That's an excellent explanation for me. I would've never figured that out.
I've downloaded your attachment and I'll see if I can understand your RunFree.class, it sounds far better than running in a timer. This is very, very helpful.
User avatar
BruceSteers
Posts: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Warning message in IDE when running app

Post by BruceSteers »

Diverod wrote: Wednesday 1st December 2021 8:33pm Thanks Bruce for investing your time also. That's an excellent explanation for me. I would've never figured that out.
I've downloaded your attachment and I'll see if I can understand your RunFree.class, it sounds far better than running in a timer. This is very, very helpful.
you are welcome, the RunFree class does run the function through a timer, by doing so it runs as a separate process to the function calling it,
Using the RunFree() command in the keyboard event handler just sets up the command and starts the timer then continues whilst the timer event actually calls your function.

It's a simple class, i created it in response to having issues that i was told "you shouldn't do that inside an event handler" so I came up with a work around :)
,It's just this..
' Gambas class file

' RunFree.class written by Bruce Steers (with some help from Tobias Boege)

' Syntax..
' RunFree(Parent As Object, Method As String, ArgArray As Variant[])

' Parent is the class containing the Method (Function/Sub)
' Method is the Function/Sub name
' ArgArray is Variant Array[]
' Eg.
' RunFree(Me, "LengthyMethod",["Some Text", 22, True])


Export

Static Private $Timer As Timer

Static Private $Parent As Object
Static Private $Method As String
Static Private $ArgArray As Variant[]

Static Public Sub _init()
  
  $Timer = New Timer As "Timer"
  $Timer.Delay = 0

End


Static Public Sub _call(Parent As Object, Method As String, Optional ArgArray As Variant[])

  $Parent = Parent
  $Method = Method
  $ArgArray = ArgArray
  $Timer.Start

End

Static Public Sub Timer_Timer()

$Timer.Stop
Object.Call($Parent, $Method, $ArgArray)

End

To be fair though for the purpose of your app it would be easier to use the Sleep command. or even better handle the reason you are using Wait properly. Ie, try to find a way to detect what you are waiting for so it will not need adjusting for slower cpu's it will self adjust :)

All the best
If at first you don't succeed , try doing something differently.
BruceS
Diverod
Posts: 28
Joined: Friday 12th November 2021 1:31am
Location: North Central Florida

Re: Warning message in IDE when running app

Post by Diverod »

BruceSteers wrote: Thursday 2nd December 2021 12:42am
Diverod wrote: Wednesday 1st December 2021 8:33pm Thanks Bruce for investing your time also. That's an excellent explanation for me. I would've never figured that out.
I've downloaded your attachment and I'll see if I can understand your RunFree.class, it sounds far better than running in a timer. This is very, very helpful.
you are welcome, the RunFree class does run the function through a timer, by doing so it runs as a separate process to the function calling it,
Using the RunFree() command in the keyboard event handler just sets up the command and starts the timer then continues whilst the timer event actually calls your function.

It's a simple class, i created it in response to having issues that i was told "you shouldn't do that inside an event handler" so I came up with a work around :)
,It's just this..
' Gambas class file

' RunFree.class written by Bruce Steers (with some help from Tobias Boege)

' Syntax..
' RunFree(Parent As Object, Method As String, ArgArray As Variant[])

' Parent is the class containing the Method (Function/Sub)
' Method is the Function/Sub name
' ArgArray is Variant Array[]
' Eg.
' RunFree(Me, "LengthyMethod",["Some Text", 22, True])


Export

Static Private $Timer As Timer

Static Private $Parent As Object
Static Private $Method As String
Static Private $ArgArray As Variant[]

Static Public Sub _init()
  
  $Timer = New Timer As "Timer"
  $Timer.Delay = 0

End


Static Public Sub _call(Parent As Object, Method As String, Optional ArgArray As Variant[])

  $Parent = Parent
  $Method = Method
  $ArgArray = ArgArray
  $Timer.Start

End

Static Public Sub Timer_Timer()

$Timer.Stop
Object.Call($Parent, $Method, $ArgArray)

End

To be fair though for the purpose of your app it would be easier to use the Sleep command. or even better handle the reason you are using Wait properly. Ie, try to find a way to detect what you are waiting for so it will not need adjusting for slower cpu's it will self adjust :)

All the best
Ah, maybe the light bulb is getting brighter! I used Wait because I was getting an artifact from the main form in the image when I was running Ubuntu in Virtualbox. I'm no longer using Virtualbox but it's still set up on my dual-boot laptop so I should be able to go back and test it. Thanks Bruce.
Diverod
Posts: 28
Joined: Friday 12th November 2021 1:31am
Location: North Central Florida

Re: Warning message in IDE when running app

Post by Diverod »

Thanks to all the help here I have learned a great deal and still have a great amount to learn. I have a good memory, it just that it’s short. :o

Also, before I forget, I wanted to let cogier know that his Screenshot comes preinstalled as a utility in Ubuntu 20.04.3LTS.

Bruce, I haven’t gotten back to my Virtualbox machine to do more testing on the Wait command yet, but I will. Your RunFree.Class is really slick.

The last few days I’ve been chasing a problem with the Ctrl+Up / Down key code and the form displaced by -37 pixels in the Y direction after returning by the Capture() sub with Gambas 3.16.3. Strangely enough, I have a note saying the form jumped in the opposite direction with Gambas 3.14.3.

If I don’t use any Ctrl+Up / Down key the form returns to its proper position. Once you do use a key code the effect remains even if the keys are not used again to position the form.

If I use Ctrl+Up one time, moving the form up 1 pixel, it jumps up 37 pixels when it returns to the screen. If I then press Ctrl+Down key one time, the form jumps down 37 pixels(original position) + 1.

After days of trying many different things I was able to reduce and resolve the problem with 2 simple lines of code:
Me.Y += 1
Me.Y -= 1
It’s like the form knows where it’s supposed to be but no one has told it to go there if a key code is used. I truly do not understand what I’m missing on this one.

I’ve attached the updated project if you’d like to look at it. If you want to see the effect just comment out lines 286 & 287.
Attachments
ScreenCap0.1.3.tar.gz
(56.77 KiB) Downloaded 193 times
Post Reply