Ask Your Question
0

Disable Keyboard Shortcuts using Python UNO API

asked 2018-01-02 21:06:51 +0200

winsats gravatar image

Does anyone know how to disable the Keyboard shortcuts (for copy, save etc..) using Python UNO APIs. My need is to programmatically disable or enable these shortcuts without restarting the Libreoffice application.

edit retag flag offensive close merge delete

Comments

How is this related to your other question at https://ask.libreoffice.org/en/questi... Perhaps you want to use that code along with https://ask.libreoffice.org/en/questi....

Jim K gravatar imageJim K ( 2018-01-03 04:57:33 +0200 )edit

With regard to the other question relation, disabling the menu item doesn’t seem to automatically disable the keyboard shortcut associated with it. For example, the user can still copy the text using Cmd-C even if the copy menu item is disabled.

My need is to programmatically enable or disable the user from copy/exporting/saving the document.

winsats gravatar imagewinsats ( 2018-01-03 06:44:36 +0200 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2018-01-03 20:51:17 +0200

Jim K gravatar image

updated 2018-01-03 21:01:09 +0200

For example, to disable saving by Ctrl+S:

xPropertyValue = PropertyValue()
xPropertyValue.Name = "nodepath"
xPropertyValue.Value = (
    "/org.openoffice.Office.Accelerators/PrimaryKeys/Global")
xAccess = self.uno_objs.configProvider.createInstanceWithArguments(
    "com.sun.star.configuration.ConfigurationUpdateAccess",
    (xPropertyValue,))
accelerator = xAccess.getByName('S_MOD1')
accelerator.setPropertyValue('Command', "disabled")
xAccess.commitChanges()

To enable again:

accelerator.setPropertyValue('Command', ".uno:Save")
xAccess.commitChanges()

View %appdata%\LibreOffice\4\user\registrymodifications.xcu to see the changes that are made. Changes take effect immediately when committed.

To show available properties and methods, print(dir(xAccess)) may be helpful.

I feel compelled to ask whether you really want to disable basic functions such as saving. It could be irritating for anyone who uses whatever you are making.

edit flag offensive delete link more

Comments

My assumption is that OP wants this as an attempt to create something like DRM preventing user from copying data. And that's absolutely futile attempt, if I am right. Also interesting how well would it work when one switches between "protected" documents and unprotected ones, and how well would it behave on app crashes (when no cleanup code could bring settings back to normal state).

Mike Kaganski gravatar imageMike Kaganski ( 2018-01-03 21:05:10 +0200 )edit

Thanks Jim, I will check and update.

@Mike, you are right. Please let me know if there is a better solution to prevent the user from copying the document. Other than a case of user taking pictures of the screen, I am under the assumption that all other methods of copying can be controlled. I may be wrong, but I would like to try and achieve this goal.

winsats gravatar imagewinsats ( 2018-01-04 21:43:19 +0200 )edit

@JIm key shortcut Cmd-S for Save seem to be disabled when "Save menu item" is disabled, I didn't need to add the new code. But the copy (Cmd-C) is enabled even when the menu item is disabled. Is this a bug in LibreOffice? I also tried your new code but was still able to copy the data to clipboard. Also, any idea on how remove the save prompt when you close application without saving the document? Appreciate your responses, thanks!

winsats gravatar imagewinsats ( 2018-01-05 01:13:45 +0200 )edit

As far as the save prompt, you could set the file to open read-only as described at https://ask.libreoffice.org/en/questi.... Beyond that, I do not like the direction this is going. Perhaps you should be using pictures of the screen instead.

Even then, someone could take a picture to copy it. DRM files are evil. Those that I have purchased in the past no longer work, so I have been forced to circumvent the protection to get them to work.

Jim K gravatar imageJim K ( 2018-01-05 15:14:44 +0200 )edit

I agree.. Thanks for your replies. Appreciate it very much!

winsats gravatar imagewinsats ( 2018-01-05 19:27:09 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-01-02 21:06:51 +0200

Seen: 105 times

Last updated: Jan 03 '18