Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Pyperclip could not find a copy/paste mechanism for your system. #234

Closed
smartkid2024 opened this issue Feb 6, 2024 · 5 comments · Fixed by #235
Closed

Error: Pyperclip could not find a copy/paste mechanism for your system. #234

smartkid2024 opened this issue Feb 6, 2024 · 5 comments · Fixed by #235
Assignees
Labels
bug Something isn't working

Comments

@smartkid2024
Copy link

Hi, when I ssh to a server then I want to try to run the script that include a text editor I get that error.
it's my script:

from TermTk import TTkUiLoader, TTk, TTkWindow
class MyTextEditor(TTkWindow):

    def __init__(self, root):
        self.root = root

        ## UI ##
        TTkUiLoader.loadDict({
        "version": "2.0.0",
            "tui": {
                "class": "TTkWindow",
                "params": {
                    "Name": "MainLicense",
                    "Position": [0, 0],
                    "Size": [59, 22],
                    "Min Width": 0,
                    "Min Height": 0,
                    "Max Width": 65536,
                    "Max Height": 65536,
                    "Visible": True,
                    "Enabled": True,
                    "ToolTip": "",
                    "Padding": [0, 0, 0, 0],
                    "Layout": "TTkLayout",
                    "Border": True,
                    "Title": "Check License",
                    "Window Flags": 134217728,
                },
                "layout": {
                    "class": "TTkLayout",
                    "params": {"Geometry": (0, 0, 59, 22)},
                    "children": [
                        {
                "class": "TTkContainer",
                "params": {
                    "Name": "ExitForm",
                    "Position": [1, 3],
                    "Size": [57, 18],
                    "Min Width": 0,
                    "Min Height": 0,
                    "Max Width": 65536,
                    "Max Height": 65536,
                    "Visible": True,
                    "Enabled": True,
                    "ToolTip": "",
                    "Padding": [0, 0, 0, 0],
                    "Layout": "TTkLayout",
                },
                "layout": {
                    "class": "TTkLayout",
                    "params": {"Geometry": (0, 0, 57, 18)},
                    "children": [
                        {
                            "class": "TTkButton",
                            "params": {
                                "Name": "ExitBtn",
                                "Position": [18, 15],
                                "Size": [20, 3],
                                "Min Width": 6,
                                "Min Height": 3,
                                "Max Width": 65536,
                                "Max Height": 65533,
                                "Visible": True,
                                "Enabled": True,
                                "ToolTip": "",
                                "Text": "Exit",
                                "Border": True,
                                "Checkable": False,
                                "Checked": False,
                            },
                            "row": 0,
                            "col": 0,
                            "rowspan": 1,
                            "colspan": 1,
                        },
                        {
                            "class": "TTkFrame",
                            "params": {
                                "Name": "TTkFrame",
                                "Position": [2, 2],
                                "Size": [52, 13],
                                "Min Width": 0,
                                "Min Height": 0,
                                "Max Width": 65536,
                                "Max Height": 65536,
                                "Visible": True,
                                "Enabled": True,
                                "ToolTip": "",
                                "Padding": [1, 1, 1, 1],
                                "Layout": "TTkLayout",
                                "Border": True,
                                "Title": "",
                            },
                            "layout": {
                                "class": "TTkLayout",
                                "params": {"Geometry": (0, 0, 50, 11)},
                                "children": [
                                    {
                                        "class": "TTkTextEdit",
                                        "params": {
                                            "Name": "InfoTextEdit",
                                            "Position": [2, 1],
                                            "Size": [46, 9],
                                            "Min Width": 0,
                                            "Min Height": 0,
                                            "Max Width": 65536,
                                            "Max Height": 65536,
                                            "Visible": True,
                                            "Enabled": True,
                                            "ToolTip": "",
                                            "Line Number": True,
                                            "Line Number Starting": -1,
                                            "Read Only": False,
                                            "Multi Line": True,
                                        },
                                        "row": 0,
                                        "col": 0,
                                        "rowspan": 1,
                                        "colspan": 1,
                                    }
                                ],
                            },
                            "row": 0,
                            "col": 0,
                            "rowspan": 1,
                            "colspan": 1,
                        },
                        {
                            "class": "TTkLabel",
                            "params": {
                                "Name": "TTkLabel",
                                "Position": [3, 1],
                                "Size": [27, 1],
                                "Min Width": 25,
                                "Min Height": 1,
                                "Max Width": 65536,
                                "Max Height": 65536,
                                "Visible": True,
                                "Enabled": True,
                                "ToolTip": "",
                                "Text": "ℹ️  Copy This Information:",
                                "Color": "\x1b[0m",
                                "Alignment": 0,
                            },
                            "row": 0,
                            "col": 0,
                            "rowspan": 1,
                            "colspan": 1,
                        },
                    ],
                },
                "row": 0,
                "col": 0,
                "rowspan": 1,
                "colspan": 1,
            }
                ],
            },
        },
            "connections": [],
        }
            , self)

        info="""
Many Informations
xvdfgsdfs
sdfsdf

sdf
s
df

sdf
s
df
sdfsfdsdfsferwrwerwerwer"""
        self.getWidgetByName('InfoTextEdit').setText(info)


root=TTk()

root.layout().addWidget(MyTextEditor(root))

root.mainloop()

It works correctly on the local machine
but when I ssh from another machine to this machine and run the script. if I select text it crashes and shows this error:

Traceback (most recent call last):
  File "/mnt/My/Projects/server/.exclude/Test/gui/ttk/test9.py", line 190, in <module>
    root.mainloop()
  File "/mnt/My/Projects/server/venv/lib/python3.10/site-packages/TermTk/TTkCore/ttk.py", line 178, in mainloop
    self._mainLoop()
  File "/mnt/My/Projects/server/venv/lib/python3.10/site-packages/TermTk/TTkCore/ttk.py", line 188, in _mainLoop
    TTkInput.start()
  File "/mnt/My/Projects/server/venv/lib/python3.10/site-packages/TermTk/TTkCore/TTkTerm/input_thread.py", line 102, in start
    TTkInput.inputEvent.emit(kevt, mevt)
  File "/mnt/My/Projects/server/venv/lib/python3.10/site-packages/TermTk/TTkCore/signal.py", line 143, in emit
    slot(*args[sl], **kwargs)
  File "/mnt/My/Projects/server/venv/lib/python3.10/site-packages/TermTk/TTkCore/ttk.py", line 202, in _processInput
    self._mouse_event(mevt)
  File "/mnt/My/Projects/server/venv/lib/python3.10/site-packages/TermTk/TTkCore/ttk.py", line 232, in _mouse_event
    focusWidget.mouseEvent(nmevt)
  File "/mnt/My/Projects/server/venv/lib/python3.10/site-packages/TermTk/TTkWidgets/container.py", line 300, in mouseEvent
    if self.mouseReleaseEvent(evt):
  File "/mnt/My/Projects/server/venv/lib/python3.10/site-packages/TermTk/TTkWidgets/texedit.py", line 415, in mouseReleaseEvent
    self.copy()
  File "/mnt/My/Projects/server/venv/lib/python3.10/site-packages/TermTk/TTkWidgets/texedit.py", line 307, in copy
    self._clipboard.setText(txt)
  File "/mnt/My/Projects/server/venv/lib/python3.10/site-packages/TermTk/TTkGui/clipboard.py", line 51, in setText
    self._setText(str(text))
  File "/mnt/My/Projects/server/venv/lib/python3.10/site-packages/pyperclip/__init__.py", line 659, in lazy_load_stub_copy
    return copy(text)
  File "/mnt/My/Projects/server/venv/lib/python3.10/site-packages/pyperclip/__init__.py", line 336, in __call__
    raise PyperclipException(EXCEPT_MSG)
pyperclip.PyperclipException: 
    Pyperclip could not find a copy/paste mechanism for your system.
    For more information, please visit https://pyperclip.readthedocs.io/en/latest/index.html#not-implemented-error 
@smartkid2024
Copy link
Author

It happens for all text or line editors if I try to select something in the text input field or text edit. it crashed. How can I disable copy-paste and prevent this exception?

@smartkid2024
Copy link
Author

Also, it happened for ttkDesigner if I tried to run it from ssh but it's unimportant. how can I disable copy-paste for line editing or text editing?

@smartkid2024
Copy link
Author

Also, printing text on output after quitting ttk will help me. I want to show text to the user that the user should copy and it runs over ssh

@ceccopierangiolieugenio
Copy link
Owner

ceccopierangiolieugenio commented Feb 6, 2024

yes
I noticed itwhen I tried it over ssh
I need to handle that exception
you can try to export X

ssh -X <HOST>

In my quick test it seems to works
I am sure putty has a similar option that can be enabled but I don't know if it is properly handled in Windows
image

@ceccopierangiolieugenio ceccopierangiolieugenio added the bug Something isn't working label Feb 6, 2024
@ceccopierangiolieugenio ceccopierangiolieugenio linked a pull request Feb 6, 2024 that will close this issue
ceccopierangiolieugenio added a commit that referenced this issue Feb 6, 2024
…lip-could-not-find-a-copypaste-mechanism-for-your-system

FIX: #234 : Handled pyperclip exception
@ceccopierangiolieugenio
Copy link
Owner

Also, printing text on output after quitting ttk will help me. I want to show text to the user that the user should copy and it runs over ssh

This could be achieved with a print after the main loop:
But there is an issue I have to investigate that sometimes the terminal is not clear when exiting so any printout will get corrupted #236

from TermTk import TTk, TTkWindow, TTkButton

root = TTk()

TTkButton(parent=root, pos=(0,0), size=(40,5), text="Quit", border=True).clicked.connect(root.quit)

win = TTkWindow(parent=root, pos=(0,5), size=(30,10))
win.closed.connect(root.quit)

root.mainloop()

print("Test\nTest\nTest\nTest\nTest\n")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants