Open HritwikSinghal opened 3 years ago
see https://github.com/bugaevc/wl-clipboard/issues/40
see also https://github.com/asweigart/pyperclip/blob/master/src/pyperclip/__init__.py
flickering issue cant be solved since https://github.com/bugaevc/wl-clipboard/issues/90 , you can remove 'no selecction' by adding 'stderr=subprocess.DEVNULL' to 'subprocess.Popen' as done below.
class wl_clip:
def __init__(self):
self.clipboardText = ''
def check_wayland(self):
if os.environ.get("WAYLAND_DISPLAY"):
if _executable_exists("wl-copy"):
return True
print("No wayland clipboard found! Please install wl-clipboard.")
return False
def paste_wayland(self, primary=False):
args = ["wl-paste", "-n"]
if primary:
args.append('-p')
p = subprocess.Popen(args, close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
stdout, _stderr = p.communicate()
self.clipboardText = stdout.decode(ENCODING)
def waitForPaste(self):
"""This function call blocks until a non-empty text string exists on the
clipboard. It returns this text.
This function raises PyperclipTimeoutException if timeout was set to
a number of seconds that has elapsed without non-empty text being put on
the clipboard."""
while True:
# clipboardText = self.paste_wayland()
t1 = threading.Thread(target=self.paste_wayland)
t1.start()
t1.join()
if self.clipboardText != '':
print("HeLLo")
return self.clipboardText
time.sleep(0.1)
def get_url(self):
print('\nWaiting for url from clipboard....')
if wl_clip.check_wayland(wl_clip()):
print("TTTT")
wayland_clip = wl_clip()
url = wayland_clip.waitForPaste()
else:
url = pyperclip.waitForPaste()
# url = 'https://www.jiosaavn.com/song/shayad-from-love-aaj-kal/GjIBdCt,UX8'
pyperclip.copy('')
if str(url).startswith('https://www.jiosaavn.com'):
print('got url: ', url)
self.set_url(url)
self.url_type = self.url.split('/')[3]
if
wl-clipboard
package is installed, below is the output in idle condition.