Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import subprocess, sys
- from PyQt5 import QtWidgets, QtCore
- from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QLabel, QHBoxLayout
- from PyQt5.QtCore import Qt
- from pynput import mouse
- clean = f'''#!/bin/bash
- echo -n "" | xclip -i -selection primary
- '''
- subprocess.run(['bash', '-c', clean])
- get_clipboard = f'''#!/bin/bash
- xclip -o -selection primary
- '''
- class MouseEventThread(QtCore.QThread):
- mouse_event_signal = QtCore.pyqtSignal(str)
- def __init__(self, parent=None):
- super().__init__(parent)
- def on_click(self, x, y, button, pressed):
- if button == mouse.Button.left and not pressed:
- # Получаем текст из буфера обмена
- current_text = subprocess.run(['bash', '-c', get_clipboard], stdout=subprocess.PIPE, text=True).stdout.strip()
- self.mouse_event_signal.emit(current_text) # Отправляем сигнал с текстом
- def run(self):
- with mouse.Listener(on_click=self.on_click) as listener:
- listener.join()
- class MyWindow(QtWidgets.QWidget):
- def __init__(self, parent=None):
- super().__init__(parent)
- self.previous_text = ""
- self.mouse_event_thread = MouseEventThread()
- self.mouse_event_thread.mouse_event_signal.connect(self.handle_mouse_event)
- self.mouse_event_thread.start()
- self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
- self.setGeometry(1800, 1010, 45, 20)
- layout = QVBoxLayout()
- # Создаем горизонтальный макет для кнопок
- button_layout = QHBoxLayout()
- cut_button = QPushButton('Вырезать')
- cut_button.clicked.connect(self.cut_text)
- button_layout.addWidget(cut_button)
- copy_button = QPushButton('Копировать')
- copy_button.clicked.connect(self.copy_text)
- button_layout.addWidget(copy_button)
- paste_button = QPushButton('Вставить')
- paste_button.clicked.connect(self.paste_text)
- button_layout.addWidget(paste_button)
- # Добавляем горизонтальный макет с кнопками в основной вертикальный макет
- layout.addLayout(button_layout)
- self.setLayout(layout)
- def handle_mouse_event(self, current_text):
- if current_text and current_text != self.previous_text:
- self.previous_text = current_text
- self.show()
- subprocess.run(['bash', '-c', clean])
- else:
- self.hide()
- def cut_text(self):
- self.hide()
- script = f'''#!/bin/bash
- xte "keydown Control_R" "key x" "keyup Control_R" '''
- subprocess.run(['bash', '-c', script])
- def copy_text(self):
- self.hide()
- script = '''#!/bin/bash
- xte "keydown Control_R" "key c" "keyup Control_R" '''
- subprocess.run(['bash', '-c', script])
- def paste_text(self):
- self.hide()
- script = '''#!/bin/bash
- xte "keydown Control_R" "key v" "keyup Control_R" '''
- subprocess.run(['bash', '-c', script])
- app = QtWidgets.QApplication(sys.argv)
- window = MyWindow() # Запуск потока
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement