DirectEntry Not Accepting Ctrl-v

I’ve seen posts here that seem to imply that DirectEntry should accept a paste via Ctrl-V by default. However, I am not able to get that to work. Have I misunderstood the information that I’ve seen, or is there something like a parameter that enables/disables Ctrl-V behavior?

What operating system are you on? From what I heard, Panda has special handling for Ctrl+V on Windows, but not on other platforms. There seem to be plans to change this in the future, though. You can read more about this here.

As mentioned in the issue discussion I linked to, there is the following config variable:

paste-emit-keystrokes

which you could set to true, but that already seems to be the default and likely won’t have any effect if you’re not on Windows.

Sorry, I normally post system information. I’m on Ubuntu 18.04 64-bit, but want my app to work on all major OSes. The Panda3D version is 1.10.5.

Thanks for the information on the config variable, I wasn’t aware of it. However, it doesn’t seem to matter what I set it to, Ctrl-v still doesn’t work. I must have something else wrong unless this functionality has been broken in recent releases.

I’ve tried setting the variable to False and True using the following before doing anything else in my app.

ctrlv = ConfigVariableBool('paste-emit-keystrokes', True)
print(ctrlv.getValue())
# prints True

This setting is not supported on Linux, it was only added to make it possible to disable the Windows behaviour. If you want, you can file a feature request on GitHub for making it work on Linux.

However, I’m personally a little iffy on having Panda automatically bind to Ctrl+V at all, which is not universally accepted as the paste shortcut, especially on Linux (where clicking middle-mouse or pressing shift+insert is historically the way to paste things). Maybe we should instead be allowing the user to bind Ctrl+V and give them access to the system clipboard.

It may also be possible to use a Python clipboard library and catch Ctrl+V yourself.

That’s a good point. I spend so much time in desktop environments that support it, I forget that it’s not universal.

I think that’s the path I’ll go down. There is some information here on setting up keybindings and I’ve seen pyperclip mentioned before, so I plan to give that a try.

Thanks @Epihaius and @rdb

In case it’s useful for anyone in the future, I’ll close the loop on this with some example code. The following minimal-ish example works when using pyperclip on Ubuntu 18.04.

from direct.showbase.DirectObject import DirectObject
import sys
from direct.showbase.ShowBase import ShowBase
from direct.gui.DirectGui import DirectFrame, DirectEntry
from panda3d.core import ConfigVariableBool
import pyperclip

class Test(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        # Set up the listener that will help trap ctrl-v keypresses and use them to paste from the clipboard
        self._listener = DirectObject()
        self._listener.accept("control-v", self.paste)

        # Text entry
        self.entry = DirectEntry(text="", scale=.05, initialText="",
                             numLines=1, focus=1, width=30)
        self.entry.reparentTo(aspect2d)
        self.entry.set_pos((-0.9, 0, 0.15))

    def paste(self):
        self.entry.enterText(pyperclip.paste())

def main(argv):
    # Only works in Windows
    ConfigVariableBool('paste-emit-keystrokes', False)

    app = Test()
    app.run()

if __name__ == "__main__":
    main(sys.argv[1:])

Sorry to be late on the party, you can also use Tk, which is integrated in Panda3D so you don’t need any external dependencies, to communicate with the system clipboard, and it’s multiplatform :slight_smile:

Here is the code I’m using : https://github.com/cosmonium/cosmonium/blob/develop/cosmonium/ui/clipboard.py

Sadly, there is a big caveat, the current distribution tool does not properly embed TCL/Tk libraries in the binary for macOS and Linux platform so it’s unusable if you intend to distribute your app using it (see https://github.com/panda3d/panda3d/issues/780)

1 Like