Skip to content

ENH use pyperclip for read and to_clipboard #3848

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

Merged
merged 2 commits into from
Jun 13, 2013

Conversation

hayd
Copy link
Contributor

@hayd hayd commented Jun 11, 2013

Use pyperclip to manage copy and pasting.

Fixes #3837, also cc #3845.

@hayd
Copy link
Contributor Author

hayd commented Jun 11, 2013

I've not yet tested myself on windows or linux (which should work with various things (not) installed).

Anyone mind having a try?

@jreback
Copy link
Contributor

jreback commented Jun 11, 2013

I did this from an x-window (linux), pasted to excel (where it is text)
did text-to-data
copied to clipboard
and repasted to ipython

pretty neat!

and a nice warning came up that I didn't have xclip installed

so maybe have some installation instructions in a warning

I don't think there are any dependencies on windows, not sure about mac

so +1 on this

In [1]: DataFrame(randn(10,2),columns=list('AB')).to_clipboard()
/usr/bin/xclip

In [2]: pd.read_clipboard()
Out[2]: 
   Unnamed: 0         A         B
0           0 -0.782434 -1.592745
1           1 -0.679130  0.622381
2           2  0.407085 -1.429126
3           3 -1.210504 -0.012332
4           4 -0.665061  1.356827
5           5 -0.704815  0.274563
6           6 -1.406038  0.384197
7           7  0.637377 -0.397826
8           8 -1.627270  0.569159
9           9  1.120310 -0.324689

In [3]: x = pd.read_clipboard()

In [4]: x
Out[4]: 
   Unnamed: 0         A         B
0           0 -0.782434 -1.592745
1           1 -0.679130  0.622381
2           2  0.407085 -1.429126
3           3 -1.210504 -0.012332
4           4 -0.665061  1.356827
5           5 -0.704815  0.274563
6           6 -1.406038  0.384197
7           7  0.637377 -0.397826
8           8 -1.627270  0.569159
9           9  1.120310 -0.324689

In [5]: x.dtypes
Out[5]: 
Unnamed: 0      int64
A             float64
B             float64
dtype: object

@jreback
Copy link
Contributor

jreback commented Jun 11, 2013

and this is better than the old one...doesn't require gtk or tk (which if your linux is a server) doesn't normally install....xclip is good!

@hayd
Copy link
Contributor Author

hayd commented Jun 11, 2013

Hmmm but installation method for xclip may differ on different linuxes (can of worms?), tbh I think their message is pretty good. Works on mac, pretty sure it will work on Windows...

A good find of yours! Tagged for 0.11.1.

Also, I should update the docs before merging (I think the docstrings are now incorrect on the requirements, and something in RELEASE).

@nipunbatra
Copy link
Contributor

Just curious are there some non trivial use cases for reading and writing clipboard?

@hayd
Copy link
Contributor Author

hayd commented Jun 11, 2013

@nipunreddevil How could copying and pasting be non-trivial...? :)

@hayd
Copy link
Contributor Author

hayd commented Jun 11, 2013

@jreback Do I need to add the license somewhere else?

@jreback
Copy link
Contributor

jreback commented Jun 11, 2013

umm...i think in the file is enough, you could copy it and put in a file in pandas/LICENSES though....I guess

@cpcloud
Copy link
Member

cpcloud commented Jun 11, 2013

@hayd just to play devils advocate >:) tmux copy-pasting to/from clipboard just doesn't work with xclip.

@hayd
Copy link
Contributor Author

hayd commented Jun 11, 2013

@cpcloud That's not devil's advocate! If it doesn't work it's a problem... any workaround? preferring xsel?

Am I right in saying Windows no longer has any dependencies (It no longer needs python win32 extensions)?

@cpcloud
Copy link
Member

cpcloud commented Jun 11, 2013

yep xsel is the sol'n

@jreback
Copy link
Contributor

jreback commented Jun 11, 2013

@cpcloud it falls back on xsel, but that requires gtk/qt4 as well

@cpcloud
Copy link
Member

cpcloud commented Jun 11, 2013

oh well that is annoying (that xsel requires those libs). i haven't tried xclip + tmux in a server env mostly since i can just ssh in when i need to and do everything that way

@hayd
Copy link
Contributor Author

hayd commented Jun 11, 2013

@jreback So is this already dealt with in pyperclip? Or there is a bug regression with tmux? I'm lost.

I've put the license in and added docstring to generic.to_clipboard. Not sure if I have written dependencies correct for Windows (None?) and Linux.

@cpcloud
Copy link
Member

cpcloud commented Jun 11, 2013

no i was just commenting on the semi-non-trivial-ness of pasting with tmux...

@jreback
Copy link
Contributor

jreback commented Jun 11, 2013

this looks good

deps look fine too

@jreback jreback mentioned this pull request Jun 12, 2013
@jreback
Copy link
Contributor

jreback commented Jun 13, 2013

mergable?

@hayd
Copy link
Contributor Author

hayd commented Jun 13, 2013

There's a silly typo, xlit, will add in those (two) characters and merge now...

@jreback
Copy link
Contributor

jreback commented Jun 13, 2013

and merge #3845 too thanks

hayd added a commit that referenced this pull request Jun 13, 2013
ENH use pyperclip for read and to_clipboard
@hayd hayd merged commit 863478c into pandas-dev:master Jun 13, 2013
@ghost
Copy link

ghost commented Jun 19, 2013

related #3368

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

Successfully merging this pull request may close these issues.

to_clipboard() required xsel to be installed in Linux
4 participants