Re: [PyQt] Searching for a very small scprit using CLIPBOARD

2009-05-03 Thread projetmbc

Giovanni Bajo a écrit :

On lun, 2009-04-27 at 18:42 +0200, projetmbc wrote:
  
Thanks a lot, your solution works fine.  :-)  Here is the complete 
minimal code :



#!/usr/bin/env python
#coding=utf-8
import sys
from PyQt4 import QtGui, QtCore
app = QtGui.QApplication(sys.argv)
clipboard = app.clipboard()
clipboard.setText('The text that must be copied...')
event = QtCore.QEvent(QtCore.QEvent.Clipboard)
app.sendEvent(clipboard, event)





It doesn't work for me on Linux. Should it?
  
For the moment I do not test it on Linux. It seems that Linux 
distribution does not have necessarly a clipboard utility.


I will try it on Linux and if I find a solution I'll put it here.

Christophe.

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Searching for a very small scprit using CLIPBOARD

2009-04-27 Thread projetmbc
Thanks a lot, your solution works fine.  :-)  Here is the complete 
minimal code :



#!/usr/bin/env python
#coding=utf-8
import sys
from PyQt4 import QtGui, QtCore
app = QtGui.QApplication(sys.argv)
clipboard = app.clipboard()
clipboard.setText('The text that must be copied...')
event = QtCore.QEvent(QtCore.QEvent.Clipboard)
app.sendEvent(clipboard, event)


Aron Bierbaum a écrit :

We ran into a similar situation where we wanted to ensure that a
QPixmap that is copied into the clipboard stays after the application
exits. Although as far as I know this should happen automatically when
your Qt application exists, we had to do this use the following code
manually before exiting our application.


   # Send an event to the clipboard so that it copies the data over to the
   # clipboard instead of keeping a pointer to the data internally. This should
   # happen automatically on exit, but it appears that the mime type convertion
   # methods for Qt - windows formats get unregistered before this event gets
   # processed. This caused a bug where we couldn't paste data after closing
   # because there was not a conversion method. The magic function on
Windows that
   # needs to be called to do this copy is OleFlushClipboard.
   from PyQt4 import QtGui, QtCore
   clipboard = QtGui.QApplication.clipboard()
   event = QtCore.QEvent(QtCore.QEvent.Clipboard)
   QtGui.QApplication.sendEvent(clipboard, event)

The basic concept behind this is that by default copying something
into the clipboard only copies a reference/pointer to the source
application. Then when another application wants to paste the data
from the clipboard it requests the data from the source application.
Calling OleFlushClipboard [1] causes Windows to copy the real data
into the clipboard instead of the reference. While this does cause a
delay when copying images, it should not have any noticeable impact
with strings.


___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Searching for a very small scprit using CLIPBOARD

2009-04-27 Thread Giovanni Bajo
On lun, 2009-04-27 at 18:42 +0200, projetmbc wrote:
 Thanks a lot, your solution works fine.  :-)  Here is the complete 
 minimal code :
 
 
 #!/usr/bin/env python
 #coding=utf-8
 import sys
 from PyQt4 import QtGui, QtCore
 app = QtGui.QApplication(sys.argv)
 clipboard = app.clipboard()
 clipboard.setText('The text that must be copied...')
 event = QtCore.QEvent(QtCore.QEvent.Clipboard)
 app.sendEvent(clipboard, event)
 
 

It doesn't work for me on Linux. Should it?
-- 
Giovanni Bajo
Develer S.r.l.
http://www.develer.com


___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Searching for a very small scprit using CLIPBOARD

2009-04-27 Thread Roberto Alsina
On Monday 27 April 2009 19:22:04 Giovanni Bajo wrote:
 On lun, 2009-04-27 at 18:42 +0200, projetmbc wrote:
  Thanks a lot, your solution works fine.  :-)  Here is the complete
  minimal code :
 
  
  #!/usr/bin/env python
  #coding=utf-8
  import sys
  from PyQt4 import QtGui, QtCore
  app = QtGui.QApplication(sys.argv)
  clipboard = app.clipboard()
  clipboard.setText('The text that must be copied...')
  event = QtCore.QEvent(QtCore.QEvent.Clipboard)
  app.sendEvent(clipboard, event)
  

 It doesn't work for me on Linux. Should it?

Remember that in Linux, unless you have something like klipper, when the app 
setting the clipboard exits, the clipboard empties.


___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Searching for a very small scprit using CLIPBOARD

2009-04-27 Thread Aron Bierbaum
I have not tested on Linux, but it would not surprise me if it was not
supported in the same way.

-Aron

On Mon, Apr 27, 2009 at 5:22 PM, Giovanni Bajo ra...@develer.com wrote:
 On lun, 2009-04-27 at 18:42 +0200, projetmbc wrote:
 Thanks a lot, your solution works fine.  :-)  Here is the complete
 minimal code :

 
 #!/usr/bin/env python
 #coding=utf-8
 import sys
 from PyQt4 import QtGui, QtCore
 app = QtGui.QApplication(sys.argv)
 clipboard = app.clipboard()
 clipboard.setText('The text that must be copied...')
 event = QtCore.QEvent(QtCore.QEvent.Clipboard)
 app.sendEvent(clipboard, event)
 


 It doesn't work for me on Linux. Should it?
 --
 Giovanni Bajo
 Develer S.r.l.
 http://www.develer.com




___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Searching for a very small scprit using CLIPBOARD

2009-04-26 Thread projetmbc

sys.exit(app.exec_()) doesn't work. If the clipboard is empty when the program exits, I 
will do without PyQt so as to have a universal clipboard.


Thanks a lot because now I knows how to use clipboard in a real program..
Christophe.


Demetrius Cassidy a écrit :

The clipboard will empty when your program exits. Afaik this is normal
behavior with Qt and clipboard access. 


I know if I use wxWindows the text in the clipboard stays even if I close my
app, however I am not sure if it's possible to do this in Qt.

And use sys.exit(app.exec_()) instead.


projetmbc wrote:
  
I've tried the following code but the application never stops because of 
app.exec_(), and when I close the application, the clipboard is empty.


=
#!/usr/bin/env python
#coding=utf-8
import sys
from PyQt4 import QtGui
app = QtGui.QApplication(sys.argv)
clipboard = app.clipboard()
clipboard.setText('texte')
app.exec_()
=


___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Searching for a very small scprit using CLIPBOARD

2009-04-26 Thread Aron Bierbaum
We ran into a similar situation where we wanted to ensure that a
QPixmap that is copied into the clipboard stays after the application
exits. Although as far as I know this should happen automatically when
your Qt application exists, we had to do this use the following code
manually before exiting our application.


   # Send an event to the clipboard so that it copies the data over to the
   # clipboard instead of keeping a pointer to the data internally. This should
   # happen automatically on exit, but it appears that the mime type convertion
   # methods for Qt - windows formats get unregistered before this event gets
   # processed. This caused a bug where we couldn't paste data after closing
   # because there was not a conversion method. The magic function on
Windows that
   # needs to be called to do this copy is OleFlushClipboard.
   from PyQt4 import QtGui, QtCore
   clipboard = QtGui.QApplication.clipboard()
   event = QtCore.QEvent(QtCore.QEvent.Clipboard)
   QtGui.QApplication.sendEvent(clipboard, event)

The basic concept behind this is that by default copying something
into the clipboard only copies a reference/pointer to the source
application. Then when another application wants to paste the data
from the clipboard it requests the data from the source application.
Calling OleFlushClipboard [1] causes Windows to copy the real data
into the clipboard instead of the reference. While this does cause a
delay when copying images, it should not have any noticeable impact
with strings.

-Aron

[1] http://msdn.microsoft.com/en-us/library/ms679707(VS.85).aspx

On Sun, Apr 26, 2009 at 2:34 AM, projetmbc projet...@club-internet.fr wrote:
 sys.exit(app.exec_()) doesn't work. If the clipboard is empty when the
 program exits, I will do without PyQt so as to have a universal clipboard.


 Thanks a lot because now I knows how to use clipboard in a real program..
 Christophe.


 Demetrius Cassidy a écrit :

 The clipboard will empty when your program exits. Afaik this is normal
 behavior with Qt and clipboard access.
 I know if I use wxWindows the text in the clipboard stays even if I close
 my
 app, however I am not sure if it's possible to do this in Qt.

 And use sys.exit(app.exec_()) instead.


 projetmbc wrote:


 I've tried the following code but the application never stops because of
 app.exec_(), and when I close the application, the clipboard is empty.

 =
 #!/usr/bin/env python
 #coding=utf-8
 import sys
 from PyQt4 import QtGui
 app = QtGui.QApplication(sys.argv)
 clipboard = app.clipboard()
 clipboard.setText('texte')
 app.exec_()
 =

 ___
 PyQt mailing list    p...@riverbankcomputing.com
 http://www.riverbankcomputing.com/mailman/listinfo/pyqt


___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] Searching for a very small scprit using CLIPBOARD

2009-04-25 Thread projetmbc

Hello,
here is an example for using the clipboard of Tkinter :

from Tkinter import *
root = Tk()
root.clipboard_clear()
root.clipboard_append('A text in the clipboard...')
root.withdraw()


I would like to do the same with PyQt. Is it possible ?

Christophe.

PS : if someone knows a Python script which is an universal ClipBoard 
(ie which works on Unix and Windows), it would be better. The purpose is 
just to send text.


___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Searching for a very small scprit using CLIPBOARD

2009-04-25 Thread Demetrius Cassidy

from PyQt4.QtGui import QApplication

clipboard = QApplication.clipboard()
clipboard.setText('mytext')

see http://doc.trolltech.com/4.5/qapplication.html


projetmbc wrote:
 
 Hello,
 here is an example for using the clipboard of Tkinter :
 
 from Tkinter import *
 root = Tk()
 root.clipboard_clear()
 root.clipboard_append('A text in the clipboard...')
 root.withdraw()
 
 
 I would like to do the same with PyQt. Is it possible ?
 
 Christophe.
 
 PS : if someone knows a Python script which is an universal ClipBoard 
 (ie which works on Unix and Windows), it would be better. The purpose is 
 just to send text.
 
 ___
 PyQt mailing listPyQt@riverbankcomputing.com
 http://www.riverbankcomputing.com/mailman/listinfo/pyqt
 
 

-- 
View this message in context: 
http://www.nabble.com/Searching-for-a-very-small-scprit-using-CLIPBOARD-tp23236437p23237601.html
Sent from the PyQt mailing list archive at Nabble.com.

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Searching for a very small scprit using CLIPBOARD

2009-04-25 Thread projetmbc

I've already try that but I have the following message :
QWidget: Must construct a QApplication before a QPaintDevice

Christophe.


Demetrius Cassidy a écrit :

from PyQt4.QtGui import QApplication

clipboard = QApplication.clipboard()
clipboard.setText('mytext')

see http://doc.trolltech.com/4.5/qapplication.html
  


___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Searching for a very small scprit using CLIPBOARD

2009-04-25 Thread Darren Dale
Have you tried constructing a QApplication first?

On Sat, Apr 25, 2009 at 8:24 PM, projetmbc projet...@club-internet.frwrote:

 I've already try that but I have the following message :
 QWidget: Must construct a QApplication before a QPaintDevice

 Christophe.


 Demetrius Cassidy a écrit :

 from PyQt4.QtGui import QApplication

 clipboard = QApplication.clipboard()
 clipboard.setText('mytext')

 see http://doc.trolltech.com/4.5/qapplication.html



 ___
 PyQt mailing listPyQt@riverbankcomputing.com
 http://www.riverbankcomputing.com/mailman/listinfo/pyqt

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] Searching for a very small scprit using CLIPBOARD

2009-04-25 Thread projetmbc
I've tried the following code but the application never stops because of 
app.exec_(), and when I close the application, the clipboard is empty.


=
#!/usr/bin/env python
#coding=utf-8
import sys
from PyQt4 import QtGui
app = QtGui.QApplication(sys.argv)
clipboard = app.clipboard()
clipboard.setText('texte')
app.exec_()
=


Darren Dale a écrit :

Have you tried constructing a QApplication first?

On Sat, Apr 25, 2009 at 8:24 PM, projetmbc projet...@club-internet.fr 
mailto:projet...@club-internet.fr wrote:


I've already try that but I have the following message :
QWidget: Must construct a QApplication before a QPaintDevice

Christophe.


Demetrius Cassidy a écrit :

from PyQt4.QtGui import QApplication

clipboard = QApplication.clipboard()
clipboard.setText('mytext')

see http://doc.trolltech.com/4.5/qapplication.html
 



___
PyQt mailing listPyQt@riverbankcomputing.com
mailto:PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt





___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt