Skip to content

Support adding gestures to enable configuration profiles#8844

Merged
feerrenrut merged 5 commits into
nvaccess:masterfrom
BabbageCom:configProfileGestures
May 10, 2019
Merged

Support adding gestures to enable configuration profiles#8844
feerrenrut merged 5 commits into
nvaccess:masterfrom
BabbageCom:configProfileGestures

Conversation

@LeonarddeR

@LeonarddeR LeonarddeR commented Oct 15, 2018

Copy link
Copy Markdown
Collaborator

Link to issue number:

Closes #4209

Summary of the issue:

Configuration profile can either be activated using triggers or by manual activation in the configuration profiles dialogs. Activation with gestures is not yet supported.

Description of how this pull request fixes the issue:

This pr adds a new ConfigProfileActivationCommands class to GlobalCommands, which has a single instance, globalCommands.configProfileActivationCommands. This class is used as follows.

  1. When NVDA is started, a script is added to the class for every profile.
  2. Adding a profile also adds a script
  3. Removing a profile deletes it's script along with gestures that have ever been bound to it.
  4. Renaming a profile removes the old script, and then adds a new one. The assigned gestures are moved from the old to the new script.

Testing performed:

  1. Added a profile, assigned a gesture to it and then removed the script. The gesture no longer existed in the user gesture map
  2. Renamed a profile. The gestures were successfully changed to match the new script's name.

Known issues with pull request:

Config profiles are bound to file naming restrictions, whereas script names are bound to python variable naming rules. The latter rules are stricter. This is now taken care of by changing any thing that is not either an alphanumeric or an underscore to its base16 encoding. Doing so meets the naming requirements and avoids a name collision when having a "Test profile" and "Test_profile" profile.

Change log entry:

@Brian1Gaff

Brian1Gaff commented Oct 15, 2018 via email

Copy link
Copy Markdown

@LeonarddeR

Copy link
Copy Markdown
Collaborator Author

Apologies if this is not relevant, but what stops one from hijacking a gesture which is used elsewhere for an important nvda feature?

Could you give a real world use case scenario why someone should "hijack" such a gesture?

@feerrenrut

Copy link
Copy Markdown
Contributor

Could you give a real world use case scenario why someone should "hijack" such a gesture?

I expect the concern is around accidental name matching with existing gestures, thereby unintentionally "hijacking" the gesture.

@LeonarddeR

Copy link
Copy Markdown
Collaborator Author

I think there is no such risk, as this would only occur when the creation of a new profile causes the script name of the newly created profile to be equal to another script. since profile scripts have the "script_profile_" prefix, this is pretty unlikely.

Comment thread source/globalCommands.py Outdated
if not c.isalnum() and c != "_":
invalidChars.add(c)
for c in invalidChars:
name=name.replace(c,'_')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will increase the chances of a name collision. Consider two profile names chrome^ and chrome*. How are name collisions detected and handled?

I suggest looking to see if the name is already used and append an int ID.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given you need the name created to reproducible every time so you can find it again in the removeScriptForProfile function, you could just append a base16 encoding of the string (from the value prior to substitutions). If you want to reduce the length of this string, increase the size of the base encoding (up to the number of valid characters).

@LeonarddeR

Copy link
Copy Markdown
Collaborator Author

Would it be ok for you to just replace every invalid character with its baase16 counterpart? This replaces a space with 20 in script names. However, note that these script names are usually not exposed to the public, only saved in the gestures file, which is never advised to be touched by end users.

@feerrenrut

Copy link
Copy Markdown
Contributor

Would it be ok for you to just replace every invalid character with its baase16 counterpart?

This is fine, as long as there is no need to be able to go in the opposite direction. Eg from script name back to the original. I don't see why there would be such a need.

@LeonarddeR

Copy link
Copy Markdown
Collaborator Author

The original profile name is always saved on the script, so that should be fine, indeed.

@feerrenrut feerrenrut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you let me know if you are happy with this (it's all tested)? Then I will merge it.

@LeonarddeR

Copy link
Copy Markdown
Collaborator Author

I've had another look at the code and did another round of testing, and all seems to work well, so I'm happy with merging this. In my last commit, I only touched doc strings.

@feerrenrut feerrenrut merged commit 8d129b9 into nvaccess:master May 10, 2019
@nvaccessAuto nvaccessAuto added this to the 2019.2 milestone May 10, 2019
feerrenrut added a commit that referenced this pull request May 10, 2019
Comment thread source/globalCommands.py
if not c.isalnum() and c != "_":
invalidChars.add(c)
for c in invalidChars:
name=name.replace(c, b16encode(c))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that b16encode works for non-ascii values (I.e. any other unicode value).
Someone sent NV Access an email showing the following traceback from a very recent alpha snapshot:

ERROR - keyboardHandler.internal_keyDownEvent (14:59:07.003): 
internal_keyDownEvent 
Traceback (most recent call last): 
  File "keyboardHandler.pyc", line 178, in internal_keyDownEvent 
  File "inputCore.pyc", line 421, in executeGesture 
  File "baseObject.pyc", line 47, in __get__ 
  File "baseObject.pyc", line 147, in _getPropertyViaCache 
  File "inputCore.pyc", line 145, in _get_script 
  File "scriptHandler.pyc", line 68, in findScript 
  File "globalCommands.pyc", line 2525, in <module> 
  File "globalCommands.pyc", line 2427, in __new__ 
  File "globalCommands.pyc", line 2466, in addScriptForProfile 
  File "globalCommands.pyc", line 2438, in _getScriptNameForProfile 
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in position 12: ordinal not in range(128) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BabbageWork Pull requests filed on behalf of Babbage B.V.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a way to bind a keyboard shortcut with manual profile activation/deactivation

5 participants