From 5971ec32c8dceadadcafbc19f5264051307db7a1 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 4 Jun 2022 12:32:02 +0200 Subject: [PATCH] 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. --- CHANGELOG.md | 5 +++ docs/source/backends.rst | 1 - docs/source/platypush/backend/clipboard.rst | 5 --- platypush/backend/clipboard/__init__.py | 40 --------------------- platypush/backend/clipboard/manifest.yaml | 8 ----- platypush/plugins/clipboard/__init__.py | 40 +++++++++++++++++---- platypush/plugins/clipboard/manifest.yaml | 3 +- 7 files changed, 40 insertions(+), 62 deletions(-) delete mode 100644 docs/source/platypush/backend/clipboard.rst delete mode 100644 platypush/backend/clipboard/__init__.py delete mode 100644 platypush/backend/clipboard/manifest.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a69f3c9..f3862114 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/source/backends.rst b/docs/source/backends.rst index 9b617d75..aabb0af0 100644 --- a/docs/source/backends.rst +++ b/docs/source/backends.rst @@ -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 diff --git a/docs/source/platypush/backend/clipboard.rst b/docs/source/platypush/backend/clipboard.rst deleted file mode 100644 index f10dae51..00000000 --- a/docs/source/platypush/backend/clipboard.rst +++ /dev/null @@ -1,5 +0,0 @@ -``clipboard`` -=============================== - -.. automodule:: platypush.backend.clipboard - :members: diff --git a/platypush/backend/clipboard/__init__.py b/platypush/backend/clipboard/__init__.py deleted file mode 100644 index 3fdbe5b7..00000000 --- a/platypush/backend/clipboard/__init__.py +++ /dev/null @@ -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: diff --git a/platypush/backend/clipboard/manifest.yaml b/platypush/backend/clipboard/manifest.yaml deleted file mode 100644 index 03eeb516..00000000 --- a/platypush/backend/clipboard/manifest.yaml +++ /dev/null @@ -1,8 +0,0 @@ -manifest: - events: - platypush.message.event.clipboard.ClipboardEvent: on clipboard update. - install: - pip: - - pyperclip - package: platypush.backend.clipboard - type: backend diff --git a/platypush/plugins/clipboard/__init__.py b/platypush/plugins/clipboard/__init__.py index e9fa4578..a36db07f 100644 --- a/platypush/plugins/clipboard/__init__.py +++ b/platypush/plugins/clipboard/__init__.py @@ -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: - diff --git a/platypush/plugins/clipboard/manifest.yaml b/platypush/plugins/clipboard/manifest.yaml index 38c26866..3f81330e 100644 --- a/platypush/plugins/clipboard/manifest.yaml +++ b/platypush/plugins/clipboard/manifest.yaml @@ -1,5 +1,6 @@ manifest: - events: {} + events: + platypush.message.event.clipboard.ClipboardEvent: on clipboard update. install: pip: - pyperclip