Verified Commit 5971ec32 authored by Fabio Manganiello's avatar Fabio Manganiello
Browse files

Removed `clipboard` backend.

The relevant clipboard monitoring logic has been moved to the
`clipboard` plugin. Thus, enabling the plugin should provide all the
feature, with no need for an additional backend.
parent 7e31ac6e
Pipeline #251 passed with stages
in 5 minutes and 27 seconds
......@@ -3,6 +3,11 @@
All notable changes to this project will be documented in this file.
Given the high speed of development in the first phase, changes are being reported only starting from v0.20.2.
## [Unreleased]
- Removed `clipboard` backend. Enabling the `clipboard` plugin will also enable
clipboard monitoring, with no need for an additional backend.
## [0.23.3] - 2022-06-01
### Added
......
......@@ -17,7 +17,6 @@ Backends
platypush/backend/button.flic.rst
platypush/backend/camera.pi.rst
platypush/backend/chat.telegram.rst
platypush/backend/clipboard.rst
platypush/backend/covid19.rst
platypush/backend/file.monitor.rst
platypush/backend/foursquare.rst
......
``clipboard``
===============================
.. automodule:: platypush.backend.clipboard
:members:
import time
from typing import Optional
import pyperclip
from platypush.backend import Backend
from platypush.message.event.clipboard import ClipboardEvent
class ClipboardBackend(Backend):
"""
This backend monitors for changes in the clipboard and generates even when the user copies a new text.
Requires:
- **pyperclip** (``pip install pyperclip``)
Triggers:
- :class:`platypush.message.event.clipboard.ClipboardEvent` on clipboard update.
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._last_text: Optional[str] = None
def run(self):
self.logger.info('Started clipboard monitor backend')
while not self.should_stop():
text = pyperclip.paste()
if text and text != self._last_text:
self.bus.post(ClipboardEvent(text=text))
self._last_text = text
time.sleep(0.1)
self.logger.info('Stopped clipboard monitor backend')
# vim:sw=4:ts=4:et:
manifest:
events:
platypush.message.event.clipboard.ClipboardEvent: on clipboard update.
install:
pip:
- pyperclip
package: platypush.backend.clipboard
type: backend
from platypush.plugins import Plugin, action
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(Plugin):
class ClipboardPlugin(RunnablePlugin):
"""
Plugin to programmatically copy strings to your system clipboard
and get the current clipboard content.
Plugin to programmatically copy strings to your system clipboard,
monitor and get the current clipboard content.
Requires:
* **pyperclip** (``pip install pyperclip``)
- **pyperclip** (``pip install pyperclip``)
Triggers:
- :class:`platypush.message.event.clipboard.ClipboardEvent` on clipboard update.
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._last_text: Optional[str] = None
@action
def copy(self, text):
"""
......@@ -19,8 +32,8 @@ class ClipboardPlugin(Plugin):
:type text: str
"""
import pyperclip
pyperclip.copy(text)
pyperclip.copy(text)
@action
def paste(self):
......@@ -28,8 +41,21 @@ class ClipboardPlugin(Plugin):
Get the current content of the clipboard
"""
import pyperclip
return pyperclip.paste()
def main(self):
import pyperclip
while not self.should_stop():
text = pyperclip.paste()
if text and text != self._last_text:
get_bus().post(ClipboardEvent(text=text))
self._last_text = text
# vim:sw=4:ts=4:et:
self._should_stop.wait(0.1)
self.logger.info('Stopped clipboard monitor backend')
# vim:sw=4:ts=4:et:
manifest:
events: {}
events:
platypush.message.event.clipboard.ClipboardEvent: on clipboard update.
install:
pip:
- pyperclip
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment