Fabio Manganiello
c3337ccc6c
All checks were successful
continuous-integration/drone/push Build is passing
Added an `add_dependencies` plugin to the Sphinx build process that parses the manifest files of the scanned backends and plugins and automatically generates the documentation for the required dependencies and triggered events. This means that those dependencies are no longer required to be listed in the docstring of the class itself. Also in this commit: - Black/LINT for some integrations that hadn't been touched in a long time. - Deleted some leftovers from previous refactors (deprecated `backend.mqtt`, `backend.zwave.mqtt`, `backend.http.request.rss`). - Deleted deprecated `inotify` backend - replaced by `file.monitor` (see #289).
64 lines
1.6 KiB
Python
64 lines
1.6 KiB
Python
from time import time
|
|
from typing import Optional
|
|
|
|
from platypush.context import get_bus
|
|
from platypush.message.event.clipboard import ClipboardEvent
|
|
from platypush.plugins import RunnablePlugin, action
|
|
|
|
|
|
class ClipboardPlugin(RunnablePlugin):
|
|
"""
|
|
Plugin to programmatically copy strings to your system clipboard,
|
|
monitor and get the current clipboard content.
|
|
"""
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self._last_text: Optional[str] = None
|
|
|
|
@action
|
|
def copy(self, text):
|
|
"""
|
|
Copies a text to the OS clipboard
|
|
|
|
:param text: Text to copy
|
|
:type text: str
|
|
"""
|
|
import pyclip
|
|
|
|
pyclip.copy(text)
|
|
|
|
@action
|
|
def paste(self):
|
|
"""
|
|
Get the current content of the clipboard
|
|
"""
|
|
import pyclip
|
|
|
|
return pyclip.paste(text=True)
|
|
|
|
def main(self):
|
|
import pyclip
|
|
|
|
last_error_time = 0
|
|
|
|
while not self.should_stop():
|
|
try:
|
|
text = pyclip.paste(text=True)
|
|
if text and text != self._last_text:
|
|
get_bus().post(ClipboardEvent(text=text))
|
|
self._last_text = text
|
|
except Exception as e:
|
|
if time() - last_error_time > 60:
|
|
last_error_time = time()
|
|
self.logger.error(
|
|
'Could not access the clipboard: %s: %s', type(e), e
|
|
)
|
|
finally:
|
|
self._should_stop.wait(0.1)
|
|
|
|
self.logger.info('Stopped clipboard monitor backend')
|
|
|
|
|
|
# vim:sw=4:ts=4:et:
|