-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(clipboard): use protocols instead of abstract base class
- Loading branch information
Showing
21 changed files
with
598 additions
and
531 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
from normcap.clipboard.main import ClipboardHandlers, copy, copy_with_handler | ||
from normcap.clipboard.main import ( | ||
Handler, | ||
copy, | ||
copy_with_handler, | ||
get_available_handlers, | ||
) | ||
|
||
__all__ = [ | ||
"Handler", | ||
"copy", | ||
"copy_with_handler", | ||
"ClipboardHandlers", | ||
"get_available_handlers", | ||
] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,44 @@ | ||
import logging | ||
from typing import Any, cast | ||
|
||
from normcap.clipboard import system_info | ||
|
||
try: | ||
from PySide6 import QtGui | ||
|
||
except ImportError: | ||
QtGui = cast(Any, None) | ||
|
||
from .base import ClipboardHandlerBase | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
install_instructions = ( | ||
"Please install the Python package PySide6 with your preferred package manager." | ||
) | ||
|
||
|
||
def copy(text: str) -> None: | ||
"""Use QtWidgets.QApplication.clipboard to copy text to system clipboard.""" | ||
app = QtGui.QGuiApplication.instance() or QtGui.QGuiApplication() | ||
|
||
cb = app.clipboard() # type: ignore # Type hint wrong in PySide6? | ||
cb.setText(text) | ||
app.processEvents() | ||
|
||
class QtCopyHandler(ClipboardHandlerBase): | ||
@staticmethod | ||
def _copy(text: str) -> None: | ||
"""Use QtWidgets.QApplication.clipboard to copy text to system clipboard.""" | ||
app = QtGui.QGuiApplication.instance() or QtGui.QGuiApplication() | ||
|
||
cb = app.clipboard() # type: ignore # Type hint wrong in PySide6? | ||
cb.setText(text) | ||
app.processEvents() | ||
def is_compatible() -> bool: | ||
if not QtGui: | ||
logger.debug("%s is not compatible on systems w/o PySide6", __name__) | ||
return False | ||
|
||
def is_compatible(self) -> bool: | ||
if not QtGui: | ||
logger.debug("%s is not compatible on systems w/o PySide6", self.name) | ||
return False | ||
if system_info.os_has_wayland_display_manager(): | ||
logger.debug("%s is not compatible with Wayland", __name__) | ||
return False | ||
|
||
if self._os_has_wayland_display_manager(): | ||
logger.debug("%s is not compatible with Wayland", self.name) | ||
return False | ||
logger.debug("%s is compatible", __name__) | ||
return True | ||
|
||
logger.debug("%s is compatible", self.name) | ||
return True | ||
|
||
def is_installed(self) -> bool: | ||
logger.debug("%s requires no dependencies", self.name) | ||
return True | ||
def is_installed() -> bool: | ||
logger.debug("%s requires no dependencies", __name__) | ||
return True |
Oops, something went wrong.