Skip to content

Instantly share code, notes, and snippets.

@techbliss
Created December 1, 2016 14:34
Show Gist options
  • Save techbliss/5b472278c43ce4de20093f1402cd824f to your computer and use it in GitHub Desktop.
Save techbliss/5b472278c43ce4de20093f1402cd824f to your computer and use it in GitHub Desktop.
from PyQt5 import QtCore, QtGui, Qsci, QtWidgets, Qt
from PyQt5.QtCore import QObject, pyqtSlot, pyqtSignal, QEvent
from PyQt5.QtWidgets import QApplication, QMessageBox, QToolTip
from PyQt5.QtGui import QFont, QFontMetrics, QColor, QTextCursor, QMouseEvent, QCursor, QPixmap
import sys, os
sys.path.append(os.getcwd())
print os.getcwd()
class MyClipboard(QObject):
@pyqtSlot()
def changedSlot(self):
self.cursor = QtGui.QCursor()
self.pos = self.cursor.pos()
print self.cursor.pos()
if(QApplication.clipboard().mimeData().hasText()):
#Cursor = QApplication.clipboard(pos)
#X = pos.columnNumber();
#Y = pos.blockNumber();
#print ("Cursor = (%d, %d)" % (X, Y))
msgbox = QtWidgets.QMessageBox()
msgbox.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
#bobob = QTextCursor(self.pos)
#print bobob
#bobob.select(QTextCursor.WordUnderCursor)
#bobob.setTextCursor(bobob)
textto = QApplication.clipboard().text()
msgbox.setText(textto)
msgbox.setTextInteractionFlags(QtCore.Qt.NoTextInteraction) # (QtCore.Qt.TextSelectableByMouse)
msgbox.setWindowTitle("Crawling results")
msgbox.move(self.pos)
pixmap = QtGui.QPixmap('tt.png')
xres = pixmap.physicalDpiX()
pixmap = pixmap.scaledToHeight(xres, QtCore.Qt.SmoothTransformation)
msgbox.setIconPixmap(QPixmap(pixmap))
msgbox.exec_()
#QMessageBox.information(None, "mouse is at ")
#QMessageBox.information(None, "Text has been copied somewhere!",
# QApplication.clipboard().text())
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
listener = MyClipboard()
app.setQuitOnLastWindowClosed(False)
QApplication.clipboard().dataChanged.connect(listener.changedSlot)
MyClipboard()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment