Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
1.1.2
-
None
-
In [2]: import platform
In [4]: platform.platform()
Out[4]: 'Linux-3.7.0-7-generic-x86_64-with-LinuxMint-14-nadia'
Description
PySide fails to execute simple clipboard operations in interactive mode and the applications you paste to freeze or crash:
In [1]: from PySide import QtGui
In [2]: app = QtGui.QApplication("")
In [3]: clipboard = app.clipboard()
In [4]: clipboard.setText("Other app breaks when pasting")
The former code works well with pyqt4. The following works well on windows but also freezes apps on linux:
# -*- coding: utf-8 -*- """ Created on Wed Aug 21 18:30:08 2013 @author: zah """ from PySide import QtCore, QtGui import sys def start_app(): app = QtCore.QCoreApplication.instance() if app is None: app = QtGui.QApplication([]) return app def exec_app(app): try: from IPython.lib.guisupport import start_event_loop_qt4 start_event_loop_qt4(app) except ImportError: app.exec_() def run_in_qt (f, *args, **kwargs): def _f(*args, **kwargs): app = start_app() def _exe(): f(*args, **kwargs) app.quit() QtCore.QTimer.singleShot(1, _exe) exec_app(app) return _f @run_in_qt def set_clipboard(content, mime = 'text/plain'): mymime = QtCore.QMimeData() mymime.setData(mime, QtCore.QByteArray(content.encode('utf-8'))) app = start_app() clipboard = app.clipboard() clipboard.setMimeData(mymime) event = QtCore.QEvent(QtCore.QEvent.Clipboard) QtGui.QApplication.sendEvent(clipboard, event)
A simpler version works with pyqt4 on both windows and linux that does not require starting the event loop.
#This works from PyQt4 import QtCore, QtGui #This doesn't #from PySide import QtCore, QtGui def start_app(): app = QtCore.QCoreApplication.instance() if app is None: print "app" app = QtGui.QApplication([]) return app #@run_in_qt def set_clipboard(content, mime = 'text/plain'): mymime = QtCore.QMimeData() mymime.setData(mime, QtCore.QByteArray(content.encode('utf-8'))) app = start_app() clipboard = app.clipboard() clipboard.setMimeData(mymime)
PySide should behave at least as good as pyqt4, it should never freeze other apps and the docs should explain how to properly interact with the clipboard.