473,406 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

X windows and Python?

I'd like to program my Python script to put a string into the X
windows cut buffer. Can anyone suggest the simplest way to do that?
Maybe I can do it by putting up a Tkinter text widget, sticking the
string into it, and selecting it (I'm checking the docs) but uggh.
I'd prefer not to have to put anything on the screen. I just want to
put the string into the cut buffer so I can paste it into another
program.

Thanks for any suggestions.
Aug 15 '06 #1
9 3924
Paul Rubin <http://ph****@NOSPAM.invalidwrites:
I'd like to program my Python script to put a string into the X
windows cut buffer.
Hmm, looks like I can use w.clipboard_append with an arbitrary tkinter
widget, maybe without having to actually display anything. I'll try
that.
Aug 15 '06 #2
Paul Rubin wrote: I'd like to program my Python script to put a
string into the X windows cut buffer. Can anyone suggest the
simplest way to do that? Maybe I can do it by putting up a Tkinter
text widget, sticking the string into it, and selecting it (I'm
checking the docs) but uggh. I'd prefer not to have to put anything
on the screen. I just want to put the string into the cut buffer so
I can paste it into another program. Maybe this does what you need:
http://python-xlib.sourceforge.net/ David

Aug 15 '06 #3
Paul Rubin <http://ph****@NOSPAM.invalidwrites:
Hmm, looks like I can use w.clipboard_append with an arbitrary tkinter
widget, maybe without having to actually display anything. I'll try
that.
Nope, that's some kind of internal Tk clipboard. Any other ideas, how
to communicate with the X window manager?
Aug 15 '06 #4
The usual follow-up to "fix" Google's "formatting". Maybe this does
what you need:
http://python-xlib.sourceforge.net/

Aug 15 '06 #5
>>>>"Paul" == Paul Rubin <"http://phr.cx"@NOSPAM.invalidwrites:

PaulI'd like to program my Python script to put a string into the X
Paulwindows cut buffer. Can anyone suggest the simplest way to do
Paulthat?

Maybe there's some useful functionality exposed through the Python Xlib
module:

http://python-xlib.sourceforge.net/

Skip
Aug 15 '06 #6
On 2006-08-15, Paul Rubin <httpwrote:
I'd like to program my Python script to put a string into the
X windows cut buffer. Can anyone suggest the simplest way to
do that?
There isn't a simple way to do that.

The basic problem is that there's not really such a thing as
"_the_ X windows cut buffer". The selection mechanism under X
is rather complicated.

The way (well, _one_ way) it's supposed to work is you make an
Xlib call to claim ownership of "the selection". Then when
somebody wants to get the contents of the selection you get an
event to which you respond by sending the current contents of
the selection.

However, if your app exits before somebody requests the
contents of the selection, then you have to use one of the
fallback mechanisms. In addition to the "selection", there are
a set of cut buffer buffers that you can put things into. The
first of those cut buffers is where apps _usually_ look if
there is no current selection owner.

In order to work properly, you have cover both bases:

1) You need to request ownership of the selection and then
respond to a selection notify event if you get one.

2) You need to write the selection contents into cut buffer 0.

I think it might be sufficient to do the following:

0) Open a connection to the server and create a window.

1) Write the selected string into cut buffer 0.

2) Call XSetSelectionOwner to make yourself the owner of the
selction.

3) Call XSetSelectionOnwer to give up ownership of the
selection (or just close the connection to the server).

At that point, the selection won't have an owner, and most
applications will look in cut buffer 0. But if somebody tries
to get the selection contents between steps 2 and 3, then
things break unless you handle the request.

--
Grant Edwards grante Yow! Is this "BOOZE"?
at
visi.com
Aug 15 '06 #7
On 2006-08-15, Grant Edwards <gr****@visi.comwrote:
>I'd like to program my Python script to put a string into the
X windows cut buffer. Can anyone suggest the simplest way to
do that?

There isn't a simple way to do that.
I forgot to mention, there are actually three different
selections (plus the cut buffers).

Here's a nice explanation of just the selection part of the
mess:

http://www.msu.edu/~huntharo/xwin/do.../selection.pdf

If you want something quick and dirty, you can just use
os.popen() to call xsel:

http://www.niksula.hut.fi/~vherva/xsel/

xsel doesn't do the "cut buffer" thing. It obtains ownership of
the selection, and then forks off a copy of itself to service
requests for the selection contents. I would probably have
just copied the selection to cut buffer 0 and exited, but this
way works fine.

--
Grant Edwards grante Yow! I will SHAVE and
at buy JELL-O and bring my
visi.com MARRIAGE MANUAL!!
Aug 15 '06 #8
"David Boddie" <da***@boddie.org.ukwrites:
The usual follow-up to "fix" Google's "formatting". Maybe this does
what you need:

http://python-xlib.sourceforge.net/
Thanks, wow, a complete xlib implementation in Python, so I'd get to
do low-level X programming and implement the stuff Grant Edwards
described. I hope I can avoid that. What I'm doing right now is
writing the stuff out to a file and loading it into OpenOffice, then
selecting the contents there and copying it the cut buffer. Blecccch.
Aug 15 '06 #9
Grant Edwards <gr****@visi.comwrites:
The way (well, _one_ way) it's supposed to work is you make an
Xlib call to claim ownership of "the selection". ...
Thanks, this explanation was very interesting. It would be great if
tkinter had some calls to do this stuff, which I guess means the
underlying Tk needs them (I dunno if it has them). Anyway, for what I
was doing, it wasn't that urgent, and I'm using an awful workaround.
Aug 16 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Olli Piepponen | last post by:
Hi, I'm having a little problem catching keystrokes under Windows. I did a little research and found that with mscvrt.getch() one can cath a single key that is pressed. However this doesn't work...
4
by: Zach Shutters | last post by:
I am new to python and working my way through the van Rossum tutorial. I am cursios though about if you can program windows with python? I know I shouldn't worry about this right now but I am...
14
by: BOOGIEMAN | last post by:
Well that's it, how do I make Windows Application with Python ??? Is there simple way that works 100% ? How can I rework visual design done in VS 2003 to use it for my python program ?
35
by: Michael Kearns | last post by:
I've been using python to write a simple 'launcher' for one of our Java applications for quite a while now. I recently updated it to use python 2.4, and all seemed well. Today, one of my...
17
by: Paul Rubin | last post by:
Dumb question from a Windows ignoramus: I find myself needing to write a Python app (call it myapp.py) that uses tkinter, which as it happens has to be used under (ugh) Windows. That's Windows...
16
by: Paul Rubin | last post by:
As what must be penance for something or other, I'm needing to release a Python app for use under Windows XP. Please be gentle with me since I'm a Un*x weenie and the only thing I've had much...
4
by: davidstummer | last post by:
I was wondering if anyone could point me to an example. Currently i have a c++ program which calls and c++ dll (i created both). The dll uses SendMessage to pass messages back to the calling .exe,...
48
by: meyer | last post by:
Hi everyone, which compiler will Python 2.5 on Windows (Intel) be built with? I notice that Python 2.4 apparently has been built with the VS2003 toolkit compiler, and I read a post from Scott...
6
by: JW | last post by:
I have a lousy little Python extension, generated with the generous help of Pyrex. In Linux, things are simple. I compile the extension, link it against some C stuff, and *poof*! everything...
34
by: Ben Sizer | last post by:
I've installed several different versions of Python across several different versions of MS Windows, and not a single time was the Python directory or the Scripts subdirectory added to the PATH...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.