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.
This commit is contained in:
Fabio Manganiello 2022-06-04 12:32:02 +02:00
parent 7e31ac6ed8
commit 5971ec32c8
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
7 changed files with 40 additions and 62 deletions

View file

@ -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

View file

@ -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

View file

@ -1,5 +0,0 @@
``clipboard``
===============================
.. automodule:: platypush.backend.clipboard
:members:

View file

@ -1,40 +0,0 @@
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:

View file

@ -1,8 +0,0 @@
manifest:
events:
platypush.message.event.clipboard.ClipboardEvent: on clipboard update.
install:
pip:
- pyperclip
package: platypush.backend.clipboard
type: backend

View file

@ -1,15 +1,28 @@
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
self._should_stop.wait(0.1)
self.logger.info('Stopped clipboard monitor backend')
# vim:sw=4:ts=4:et:

View file

@ -1,5 +1,6 @@
manifest:
events: {}
events:
platypush.message.event.clipboard.ClipboardEvent: on clipboard update.
install:
pip:
- pyperclip