本文整理汇总了Python中PyQt5.QtWidgets.QApplication.clipboard方法的典型用法代码示例。如果您正苦于以下问题:Python QApplication.clipboard方法的具体用法?Python QApplication.clipboard怎么用?Python QApplication.clipboard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QApplication
的用法示例。
在下文中一共展示了QApplication.clipboard方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: saveScreenshot
# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import clipboard [as 别名]
def saveScreenshot(self, clipboard=False, fileName='screenshot.png', picType='png'):
fullWindow = QRect(0, 0, self.width() - 1, self.height() - 1)
selected = QRect(self.selected_area)
if selected.left() < 0:
selected.setLeft(0)
if selected.right() >= self.width():
selected.setRight(self.width() - 1)
if selected.top() < 0:
selected.setTop(0)
if selected.bottom() >= self.height():
selected.setBottom(self.height() - 1)
source = (fullWindow & selected)
source.setTopLeft(QPoint(source.topLeft().x() * self.scale, source.topLeft().y() * self.scale))
source.setBottomRight(QPoint(source.bottomRight().x() * self.scale, source.bottomRight().y() * self.scale))
image = self.screenPixel.copy(source)
if clipboard:
QGuiApplication.clipboard().setImage(QImage(image), QClipboard.Clipboard)
else:
image.save(fileName, picType, 10)
self.target_img = image
self.screen_shot_grabed.emit(QImage(image))
示例2: changeAction
# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import clipboard [as 别名]
def changeAction(self, nextAction):
QApplication.clipboard().setText('Test in changeAction function')
if nextAction == ACTION_UNDO:
self.undoOperation()
elif nextAction == ACTION_SAVE:
self.saveOperation()
elif nextAction == ACTION_CANCEL:
self.close()
elif nextAction == ACTION_SURE:
self.saveToClipboard()
else:
self.action = nextAction
self.setFocus()
示例3: ssh_copy_to_clipboard_action
# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import clipboard [as 别名]
def ssh_copy_to_clipboard_action(self):
msg = QMessageBox()
msg.setStandardButtons(QMessageBox.Ok)
msg.setParent(self, QtCore.Qt.Sheet)
index = self.sshComboBox.currentIndex()
if index > 1:
ssh_key_filename = self.sshComboBox.itemData(index)
ssh_key_path = os.path.expanduser(f"~/.ssh/{ssh_key_filename}.pub")
if os.path.isfile(ssh_key_path):
pub_key = open(ssh_key_path).read().strip()
clipboard = QApplication.clipboard()
clipboard.setText(pub_key)
msg.setText("Public Key Copied to Clipboard")
msg.setInformativeText(
"The selected public SSH key was copied to the clipboard. "
"Use it to set up remote repo permissions."
)
else:
msg.setText("Couldn't find public key.")
else:
msg.setText("Select a public key from the dropdown first.")
msg.exec_()
示例4: paste_text
# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import clipboard [as 别名]
def paste_text(self):
sources = QApplication.clipboard().text().splitlines()
invalidSources = ""
for source in sources:
if len(source) > 0: # Ignore empty newlines
if not os.path.exists(source):
invalidSources = invalidSources + "\n" + source
else:
new_source, created = SourceFileModel.get_or_create(dir=source, profile=self.profile())
if created:
self.sourceFilesWidget.addItem(source)
new_source.save()
if len(invalidSources) != 0: # Check if any invalid paths
msg = QMessageBox()
msg.setText("Some of your sources are invalid:" + invalidSources)
msg.exec()
示例5: ssh_copy_to_clipboard_action
# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import clipboard [as 别名]
def ssh_copy_to_clipboard_action(self):
msg = QMessageBox()
msg.setStandardButtons(QMessageBox.Ok)
msg.setParent(self, QtCore.Qt.Sheet)
index = self.sshComboBox.currentIndex()
if index > 1:
ssh_key_filename = self.sshComboBox.itemData(index)
ssh_key_path = os.path.expanduser(f'~/.ssh/{ssh_key_filename}.pub')
if os.path.isfile(ssh_key_path):
pub_key = open(ssh_key_path).read().strip()
clipboard = QApplication.clipboard()
clipboard.setText(pub_key)
msg.setText(self.tr("Public Key Copied to Clipboard"))
msg.setInformativeText(self.tr(
"The selected public SSH key was copied to the clipboard. "
"Use it to set up remote repo permissions."))
else:
msg.setText(self.tr("Couldn't find public key."))
else:
msg.setText(self.tr("Select a public key from the dropdown first."))
msg.exec_()
示例6: onCopyNet
# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import clipboard [as 别名]
def onCopyNet(self):
self.updateLock.acquire()
curRow = self.networkTable.currentRow()
curCol = self.networkTable.currentColumn()
if curRow == -1 or curCol == -1:
self.updateLock.release()
return
if curCol != 11:
curText = self.networkTable.item(curRow, curCol).text()
else:
curNet = self.networkTable.item(curRow, 2).data(Qt.UserRole+1)
curText = 'Last Recorded GPS Coordinates:\n' + str(curNet.gps)
curText += 'Strongest Signal Coordinates:\n'
curText += 'Strongest Signal: ' + str(curNet.strongestsignal) + '\n'
curText += str(curNet.strongestgps)
clipboard = QApplication.clipboard()
clipboard.setText(curText)
self.updateLock.release()
示例7: createTable
# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import clipboard [as 别名]
def createTable(self):
# Set up location table
self.locationTable = QTableWidget(self)
self.locationTable.setColumnCount(8)
self.locationTable.setGeometry(10, 10, self.geometry().width()/2-20, self.geometry().height()/2)
self.locationTable.setShowGrid(True)
self.locationTable.setHorizontalHeaderLabels(['macAddr','SSID', 'Strength', 'Timestamp','GPS', 'Latitude', 'Longitude', 'Altitude'])
self.locationTable.resizeColumnsToContents()
self.locationTable.setRowCount(0)
self.locationTable.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
self.ntRightClickMenu = QMenu(self)
newAct = QAction('Copy', self)
newAct.setStatusTip('Copy data to clipboard')
newAct.triggered.connect(self.onCopy)
self.ntRightClickMenu.addAction(newAct)
self.locationTable.setContextMenuPolicy(Qt.CustomContextMenu)
self.locationTable.customContextMenuRequested.connect(self.showNTContextMenu)
示例8: onCopy
# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import clipboard [as 别名]
def onCopy(self):
self.updateLock.acquire()
curRow = self.locationTable.currentRow()
curCol = self.locationTable.currentColumn()
if curRow == -1 or curCol == -1:
self.updateLock.release()
return
curText = self.locationTable.item(curRow, curCol).text()
clipboard = QApplication.clipboard()
clipboard.setText(curText)
self.updateLock.release()
示例9: send_string_clipboard
# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import clipboard [as 别名]
def send_string_clipboard(self, string: str, paste_command: model.SendMode):
"""
This method is called from the IoMediator for Phrase expansion using one of the clipboard method.
:param string: The to-be pasted string
:param paste_command: Optional paste command. If None, the mouse selection is used. Otherwise, it contains a
keyboard combination string, like '<ctrl>+v', or '<shift>+<insert>' that is sent to the target application,
causing a paste operation to happen.
"""
logger.debug("Sending string via clipboard: " + string)
if common.USING_QT:
if paste_command is None:
self.__enqueue(self.app.exec_in_main, self._send_string_selection, string)
else:
self.__enqueue(self.app.exec_in_main, self._send_string_clipboard, string, paste_command)
else:
if paste_command is None:
self.__enqueue(self._send_string_selection, string)
else:
self.__enqueue(self._send_string_clipboard, string, paste_command)
logger.debug("Sending via clipboard enqueued.")
示例10: get_selection
# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import clipboard [as 别名]
def get_selection(self):
"""
Read text from the X selection
Usage: C{clipboard.get_selection()}
@return: text contents of the mouse selection
@rtype: C{str}
@raise Exception: if no text was found in the selection
"""
Gdk.threads_enter()
text = self.selection.wait_for_text()
Gdk.threads_leave()
if text is not None:
return text
else:
raise Exception("No text found in X selection")
示例11: filterKeyPressInHostsTableView
# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import clipboard [as 别名]
def filterKeyPressInHostsTableView(self, key, receiver):
if not receiver.selectionModel().selectedRows():
return True
index = receiver.selectionModel().selectedRows()[0].row()
if key == Qt.Key_Down:
new_index = index + 1
receiver.selectRow(new_index)
receiver.clicked.emit(receiver.selectionModel().selectedRows()[0])
elif key == Qt.Key_Up:
new_index = index - 1
receiver.selectRow(new_index)
receiver.clicked.emit(receiver.selectionModel().selectedRows()[0])
elif QApplication.keyboardModifiers() == Qt.ControlModifier and key == Qt.Key_C:
selected = receiver.selectionModel().currentIndex()
clipboard = QApplication.clipboard()
clipboard.setText(selected.data().toString())
return True
示例12: __init__
# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import clipboard [as 别名]
def __init__(self, sender, parent=None):
super().__init__(parent)
self.editor = sender
self.form = parent
self.timer = QTimer()
self.timer.setInterval(TRANS_INTERVAL)
self.timer.start()
# 信号连接到槽
self.timer.timeout.connect(self.onTimerOut)
self.lastTran = ''
self.lastTranWord = ''
self.clipboard = QApplication.clipboard()
self.storeTimer = QTimer()
self.storeTimer.setInterval(STORE_INTERVAL)
self.storeTimer.start()
self.timer.timeout.connect(self.restoreTimeOut)
# 定义槽
示例13: __init__
# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import clipboard [as 别名]
def __init__(self):
self.app = QApplication(sys.argv)
self.mainWindow = QMainWindow()
self.ui = Ui_MainWindow()
self.ui.setupUi(self.mainWindow)
self.Dialog = QtWidgets.QDialog()
self.ui2 = Ui_Form()
self.ui2.setupUi(self.Dialog)
self.ui.textEdit.setReadOnly(True)
self.clipboard = QApplication.clipboard()
self.clipboard.selectionChanged.connect(self.fanyi)
self.mainWindow.setWindowTitle("划词翻译")
self.mainWindow.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.ui2.lineEdit.editingFinished.connect(self.callInput)
self.Dialog.moveEvent = self.mainMove
self.wordutil = wordutil()
self.time = time.time()
self.ui.textEdit.mouseDoubleClickEvent = self.inputText
示例14: fanyi
# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import clipboard [as 别名]
def fanyi(self):
if time.time() - self.time < 0.1:
print("停一下")
return
self.time = time.time()
if self.ui.textEdit.hasFocus():
return
text = self.clipboard.text(self.clipboard.Selection)
if len(text) > 20:
return
self.mainWindow.move(*self._position())
texttmp = ""
for c in text:
if c.isupper():
texttmp += " " + c
else:
texttmp += c
text = texttmp
text = text.strip(' ')
if text != '':
text = self.wordutil.execfind(text)
self.ui.textEdit.clear()
self.ui.textEdit.insertHtml(text)
示例15: set_clipboard
# 需要导入模块: from PyQt5.QtWidgets import QApplication [as 别名]
# 或者: from PyQt5.QtWidgets.QApplication import clipboard [as 别名]
def set_clipboard(data: str, selection: bool = False) -> None:
"""Set the clipboard to some given data."""
global fake_clipboard
if selection and not supports_selection():
raise SelectionUnsupportedError
if log_clipboard:
what = 'primary selection' if selection else 'clipboard'
log.misc.debug("Setting fake {}: {}".format(what, json.dumps(data)))
fake_clipboard = data
else:
mode = QClipboard.Selection if selection else QClipboard.Clipboard
QApplication.clipboard().setText(data, mode=mode)