Dup Ver Goto 📝

ClipboardView

To
59 lines, 167 words, 1549 chars Page 'ClipboardView' does not exist.

This is a trivial application to display what's in the clipboard. See also a much lighter weight version that uses tkinter instead.

#!/usr/bin/env python

import sys
from subprocess import run

from PySide6.QtGui import QGuiApplication
from PySide6.QtWidgets import QWidget, QApplication, QTextEdit
app = QApplication()

# get clipboard contents
# pp is a wrapper for e.g. xset or pbpaste that chooses based on the underlying OS
# or cb = sys.stdin.read() if you want to display text piped in
cb = run("pp",capture_output=True).stdout.decode()
if cb == "":
  cb = "-- NO CLIPBOARD CONTENTS OR NOT TEXT --"


class A(QWidget):
  def __init__(self):
    super().__init__()
    self.textarea = QTextEdit(self)

    # get screen size
    screen = QGuiApplication.primaryScreen()
    geometry = screen.geometry()
    sheight = geometry.height()
    swidth = geometry.width()
    smargin = 50
    height = int(sheight*.7)
    width = int(swidth*.7)
    self.resize(width,height)
    left = int((swidth-width)/2)
    top = int((sheight-height)/2)
    self.move(left,top)

    self.textarea.setFontFamily("Hack Nerd Font Mono")
    self.textarea.setFontPointSize(14)
    self.textarea.setReadOnly(True)
    self.textarea.resize(width,height)

  def setText(self,txt):
    self.textarea.setText(txt)
    self.update()

  def keyPressEvent(self,e):
    text = e.text().lower()
    if text == "q":
      app.quit()
    else:
      return super().keyPressEvent(e)

a = A()
a.setText(cb)
a.show()
app.exec()