'KeyEvent.getState() == 1' is not tracked anymore (key "v")

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

'KeyEvent.getState() == 1' is not tracked anymore (key "v")

Post by looo »

Today I encountered that some macros are not working anymore because pivys event handling has changed. To test:

Code: Select all

from pivy import coin

def test(event_callback):
    event = event_callback.getEvent()
    print(event.getState())

view = Gui.ActiveDocument.ActiveView
view.addEventCallbackPivy(coin.SoKeyboardEvent.getClassTypeId(), test)
OS: Ubuntu 16.04.2 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.10064 (Git)
Build type: None
Branch: master
Hash: d7ed8c4383f394f64dd9314eefa00efae02fb32f
Python version: 2.7.12
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: 'KeyEvent.getState() == 1' is not tracked anymore (key "v")

Post by microelly2 »

Thank you for this tipp.
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: 'KeyEvent.getState() == 1' is not tracked anymore (key "v")

Post by wmayer »

I doubt that in pivy something has changed. It's just a Python wrapper for Coin3d and doesn't implement an own logic for event handling. And in Coin3d nothing has changed either.

The point is that the callback function only is notified about press events if the used key is not part of a short cut. You can test this with many other short cuts like 0, 1, 2, 3 ..., 6 or O, P, ... So, the fact that V doesn't work any more just means that it is also used as part of short cut now.

The actual problem is that when a callback function is registered to the viewer it doesn't get these events as first and thus has no chance to handle them. And this makes it difficult because the macro coder cannot rely on an unreserved short cut to be still unreserved in the future.
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: 'KeyEvent.getState() == 1' is not tracked anymore (key "v")

Post by looo »

The actual problem is that when a callback function is registered to the viewer it doesn't get these events as first and thus has no chance to handle them. And this makes it difficult because the macro coder cannot rely on an unreserved short cut to be still unreserved in the future.
Exactly this is the problem. To solve it I went from key "v" to key "i".
Maybe we can choose some keys which do not get used by the system and are reserved for 3rd-party /moduls? Currently I am using i, l, g.
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: 'KeyEvent.getState() == 1' is not tracked anymore (key "v")

Post by wmayer »

Maybe we can choose some keys which do not get used by the system and are reserved for 3rd-party /moduls? Currently I am using i, l, g.
That would be difficult. A better way is to change the priority queue so that a viewer with a callback function will get the events as very first and tells the system which events it handled. But I just don't know if this is (easily) doable.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: 'KeyEvent.getState() == 1' is not tracked anymore (key "v")

Post by triplus »

Hi @looo.

Such discussions emerge occasionally:

https://forum.freecadweb.org/viewtopic.php?f=8&t=20516
https://forum.freecadweb.org/viewtopic.php?f=10&t=17378
looo wrote:Maybe we can choose some keys which do not get used by the system and are reserved for 3rd-party /moduls? Currently I am using i, l, g.
It makes some sense but it won't resolve the main problem. As that problem is not resolvable anyway in a scenario where you have 100 workbenches and all would like to use sane shortcut combinations for commands. I was already thinking about this in the past:

https://forum.freecadweb.org/viewtopic.php?f=22&t=15638

And hopefully i will have enough time soon to finish the project. Workbench using ShortCuts for its commands therefore shouldn't break shortcuts anymore in a way all involved shortcuts stop working. And in general ShortCuts won't give priority to one shortcut at the expense of other ones. Instead it provides choice. And hopefully it will free up some keyboard shortcut combinations for scenarios where more direct approach needs to be used and the solution requires "Qt Shortcut" to work and to make sense. For that part sensible shortcut management as you suggested should still make sense in the future. But hopefully that will be more manageable compared to now. Where you don't have anything to manage as the reservoir is beyond full already and it has been like that for a while. ;)
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: 'KeyEvent.getState() == 1' is not tracked anymore (key "v")

Post by looo »

triplus wrote:It makes some sense but it won't resolve the main problem. As that problem is not resolvable anyway in a scenario where you have 100 workbenches and all would like to use sane shortcut combinations for commands. I was already thinking about this in the past:
keys are only used at a specific task, and only active within this specific workbench. I always thought there are some system-shortcut and some workbench specific. While the system-shortcuts are available in all workbenches, workbench-specific are disabled after changing the current workbench. Where is the problem?
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: 'KeyEvent.getState() == 1' is not tracked anymore (key "v")

Post by triplus »

looo wrote:Where is the problem?
As for the short story:
keys are only used at a specific task, and only active within this specific workbench. I always thought there are some system-shortcut and some workbench specific. While the system-shortcuts are available in all workbenches, workbench-specific are disabled after changing the current workbench.
It doesn't work like that.

And this is the change that has break your macro:

https://github.com/FreeCAD/FreeCAD/comm ... f506db505a

Sooner or later it will happen with the key i you now use instead. Or if we reverse the situation. Your macro (when run) likely breaks the view related shortcuts that are now available in the FreeCAD by default. ShortCuts won't resolve all the problems involved. But what ShortCuts will resolve is you will be able to have 100 workbenches and in each workbench there could be a command for creating a line specific to that workbench. In all workbenches key combination S, L (key S being used to invoke ShortCuts) could be used to create the workbench specific line. And all the other workbench commands can have sensible keys set. Compared to now where a lot of commands doesn't have keyboard shortcut set. Due to the lack of possible and sensible key combinations available.

P.S. ShortCuts module actually already works like that. Just developers can't add predefined shortcuts for their workbenche commands yet. The user must do that manually in the GUI for now. And i need to think about some other small details regarding the behaviour a bit more (whenever the time allows).
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: 'KeyEvent.getState() == 1' is not tracked anymore (key "v")

Post by looo »

It doesn't work like that.
Sooner or later it will happen with the key i you now use instead.
Don't take the "i" ! :D

So in your opinion shortcuts should be always available? And all keys should be assigned to shortcuts?
I wonder if this would really makes sense. Maybe you can have a short look at my use case. This is a situation where a key is very useful (at least for me).
Doing this with a double key combination would double the work.

The key pressed is displayed in the output-panel.
key-usage_1.gif
key-usage_1.gif (439.37 KiB) Viewed 2159 times
While I understand the reason why some of the keys may used by the system,(eg v) I don't like the idea to have every key assigned to a shortcut. I think this is really not necessary. And having 100 workbenches available at the same time is also not necessary.
If your described system will get into master I would at least vote to disable all not useful shortcuts at a task. For example in the task I have posted, all other commands are disabled anyway, so also the key-press events referring to these commands should be disabled, and shouldn't be active.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: 'KeyEvent.getState() == 1' is not tracked anymore (key "v")

Post by triplus »

looo wrote:Don't take the "i" ! :D
I won't. Somebody else will or already has done that.
So in your opinion shortcuts should be always available? And all keys should be assigned to shortcuts?
Most of the commands you see on the toolbars should use ShortCuts or similar solution in the future yes. And each command on the toolbar should have sensible key combination set. If you look in the tooltips ATM a lot of commands don't have any keyboard shortcut set.
I wonder if this would really makes sense. Maybe you can have a short look at my use case. This is a situation where a key is very useful (at least for me).
Doing this with a double key combination would double the work.
This is one aspect i need to think about more. But lets say i don't end up with the solution i am satisfied with. The end result will still be more keyboard combination made available for such use case compared to the current situation.
While I understand the reason why some of the keys may used by the system,(eg v) I don't like the idea to have every key assigned to a shortcut. I think this is really not necessary. And having 100 workbenches available at the same time is also not necessary.
Currently all the keys do need to be assigned and still a lot of commands can't have sensible keyboard shortcut combination set. The end user needs to use only 2 workbenches (commands) (out of lets say possible 100) for the involved shortcuts to stop working.
If your described system will get into master I would at least vote to disable all not useful shortcuts at a task. For example in the task I have posted, all other commands are disabled anyway, so also the key-press events referring to these commands should be disabled, and shouldn't be active.
When that happens the number of pre-set shortcuts for commands will hopefully start to grow exponentially! ;)
Post Reply