Unused QT key events

More
04 Apr 2020 18:28 #162692 by persei8
Unused QT key events was created by persei8
If I type a key that has not been added to the QT key events handler, (eg. L) I get the following error 18 times:

[QTvcp.QTVCP.LIB.KEYBINDINGS][INFO] no function name conversion for QT Event: 'Key_L (keybindings.py:243)

Plus a bunch of errors for pressing the Shift and then releasing the Shift.
Since these errors are added to the machine log, it fills up very quickly with repetitive errors. This happens even if just typing Shift or Ctrl or Alt. Basically, for any key press that has not been specifically added with KEYBIND.add_call in the handler file.

Please Log in or Create an account to join the conversation.

More
04 Apr 2020 18:37 #162694 by cmorley
Replied by cmorley on topic Unused QT key events
In the handler file look for:
        # ok if we got here then try keybindings
        try:
            return KEYBIND.call(self,event,is_pressed,shift,cntrl)
        except NameError as e:
            self.add_alarm('Exception in KEYBINDING: {}'.format (e))
        except Exception as e:
            LOG.error('Exception in KEYBINDING:', exc_info=e)
            print 'Error in, or no function for: %s in handler file for-%s'%(KEYBIND.convert(event),key)
            return False

change to:
        # ok if we got here then try keybindings
        try:
            return KEYBIND.call(self,event,is_pressed,shift,cntrl)
        except NameError as e:
            pass
        except Exception as e:
            print 'Error in, or no function for: %s in handler file for-%s'%(KEYBIND.convert(event),key)
            return False

Now it will only print exceptions to the terminal.
If you don't even want that remove the print statement too.

Should do it.

Please Log in or Create an account to join the conversation.

More
04 Apr 2020 22:27 #162711 by persei8
Replied by persei8 on topic Unused QT key events
This prevents the errors being written to the machine log but since it's not the source of the error message, it is still written to the system log and to the console. The print statement under except Exception as e: does not occur. The source is line 243 of qtvcp/lib/keybindings,py I don't mind it being logged once, but 18 times for a single key press seems excessive. (it's now only 10 times)

Please Log in or Create an account to join the conversation.

More
05 Apr 2020 11:17 #162758 by cmorley
Replied by cmorley on topic Unused QT key events
i'm looking into this with success.
I think I got it to only print twice (one press one release - probably don't need release)
But I also forgot to ask if you have debugging on when loading your screen.
DISPLAY = qtvcp -d qtdragon

remove the -d will print less debugging to logs.

The reason I ask is i'd rather set it up to noe print keycode errors in 'clean' mode but print them in debug mode.
I think it mostly already works this way - but I'll clean up the message stragglers

Please Log in or Create an account to join the conversation.

More
05 Apr 2020 11:33 - 05 Apr 2020 11:33 #162759 by cmorley
Replied by cmorley on topic Unused QT key events
This is what i got in my handler file.
note the event.accept() on the last line and the if is_pressed:
This stops the multiple printings of the same error.
Just need to test more to make sure it doesn't block events to other widgets.
        # ok if we got here then try keybindings
        try:
            b = KEYBIND.call(self,event,is_pressed,shift,cntrl)
            event.accept()
            return True
        except NameError as e:
            if is_pressed:
                LOG.debug('Exception in KEYBINDING: {}'.format (e))
        except Exception as e:
            if is_pressed:
                LOG.debug('Exception in KEYBINDING:', exc_info=e)
                print 'Error in, or no function for: %s in handler file for-%s'%(KEYBIND.convert(event),key)
        event.accept()
        return True
Last edit: 05 Apr 2020 11:33 by cmorley.

Please Log in or Create an account to join the conversation.

More
05 Apr 2020 14:20 #162771 by persei8
Replied by persei8 on topic Unused QT key events
Thanks Chris. Works great. BTW, I do not have the -d switch on. I modified the code according to your post with 2 minor changes. You have b = KEYBIND etc. but b is never referenced - maybe a testing artifact? I added a line so that the error would print to the status bar of the GUI. Now it prints once to the machine log on press and twice to the system log, on press and release. Here is my handler code:
try:
KEYBIND.call(self,event,is_pressed,shift,cntrl)
event.accept()
return True
except NameError as e:
if is_pressed:
LOG.debug('Exception in KEYBINDING: {}'.format (e))
self.add_status('Exception in KEYBINDING: {}'.format (e))
except Exception as e:
if is_pressed:
LOG.debug('Exception in KEYBINDING:', exc_info=e)
print 'Error in, or no function for: %s in handler file for-%s'%(KEYBIND.convert(event),key)
event.accept()
return True

I found no instances (in qtdragon) where typing on a widget was blocked.
Stay safe.
Jim

Please Log in or Create an account to join the conversation.

More
05 Apr 2020 14:23 #162772 by persei8
Replied by persei8 on topic Unused QT key events
I guess pasting into the reply box isn't the best way to show code as no indents are shown. However, they are the same as your example.

Please Log in or Create an account to join the conversation.

More
05 Apr 2020 14:40 #162777 by cmorley
Replied by cmorley on topic Unused QT key events
Thanks for the feedback ( and the push to fix it )
Yes the code is hard to read. :)
yes b is not referenced and is probably from a long time ago.

i have changed the code to this for the future to hide the details.
It's not in master yet.
        # ok if we got here then try keybindings function calls
        # KEYBINDING will call functions from handler file as
        # registered by KEYBIND.add_call(KEY,FUNCTION) above
        return KEYBIND.manage_function_calls(self,event,is_pressed,key,shift,cntrl)

Your code will continue to work fine and if you wish to output to the status bar you'll need to keep it.

Please Log in or Create an account to join the conversation.

Moderators: cmorley
Time to create page: 0.119 seconds
Powered by Kunena Forum