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

Add cross-platform clipboard support on Tableview #115

Open
israel-dryer opened this issue Jan 3, 2022 · 6 comments
Open

Add cross-platform clipboard support on Tableview #115

israel-dryer opened this issue Jan 3, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@israel-dryer
Copy link
Owner

Add option to copy selection to clipboard.

A code example (maybe there are other better ways), I don't know what it's like on Windows and Mac. But on Linux you need to use pyperclip to keep the data on the clipboard after closing the program. And on linux you also need to do this 'update()' twice and need the
return 'break'

example:

import pyperclip

def tvw_item_ckick(self, event=None):
    self.tvw.selection()
    str_all_columns = ''
    for n in self.tvw.selection():
        str_columns = '\t'.join(self.tvw.item(n, 'values'))
        str_all_columns += f'''{str_columns}\n'''

    self.clipboard_clear()
    self.update()

    try:
        pyperclip.copy(str_all_columns)
    except TclError as e:
        raise e
    
    self.update()
    return 'break'

self.tvw.bind('<Control-c>', self.tvw_item_ckick)
self.tvw.bind('<Control-C>', self.tvw_item_ckick)

Originally posted by @antrrax in #114 (comment)

@israel-dryer israel-dryer added the enhancement New feature or request label Jan 3, 2022
@israel-dryer
Copy link
Owner Author

Adding for reference: https://bugs.python.org/issue40452

@antrrax
Copy link
Contributor

antrrax commented Jan 7, 2022

Besides the option to copy the selection to the clipboard. An option to copy the selection with the header would be interesting, it would be the same code above, but the variable 'str_all_columns' would start with the value of the headers.
str_all_columns = f'''{[col._headertext for col in self._tablecols]}\n'''

@israel-dryer
Copy link
Owner Author

@antrrax this should be expanded to all widgets if possible. Preferably without adding dependencies, but if not possible, then we can look at using the pyperclip solution referenced. It looks like the root of this may be the tkinter bug referenced above.

@PySimpleGUI, were you able to find a solution for this for PSG?

@israel-dryer
Copy link
Owner Author

https://wiki.archlinux.org/title/Clipboard

Interesting read. The behavior on Linux actually makes sense with respect to this protocol as the data is not actual copied until pasted, which is why it probably gets lost in tkinter.

@israel-dryer
Copy link
Owner Author

israel-dryer commented Jan 26, 2022

@antrrax, pyperclip relies on xclip and xsel which would have to be installed on Linux in many cases unless you are using a full featured distro such as Ubuntu or Linux Cinnamon, etc... I'm assuming that pyperclip handles these missing packages in some way? Perhaps an error message? I'll put this on the development list as something to review.

@antrrax
Copy link
Contributor

antrrax commented Jan 26, 2022

On Ubuntu/mint need to install xclip and xsel. But as it is something that is used frequently, it is already in my system post installation script, so I forget that it doesn't come with the vanilla system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants