Runs `translate` with the selection clipboard text
(self, src_lang: str | None, dest_lang: str | None)
| 531 | |
| 532 | @background_task |
| 533 | async def translate_selection(self, src_lang: str | None, dest_lang: str | None): |
| 534 | """Runs `translate` with the selection clipboard text""" |
| 535 | if display := Gdk.Display.get_default(): |
| 536 | clipboard = display.get_primary_clipboard() |
| 537 | try: |
| 538 | if text := await clipboard.read_text_async(): # type: ignore |
| 539 | self.translate(text, src_lang, dest_lang) |
| 540 | except GLib.Error as exc: |
| 541 | logging.error(exc) |
| 542 | self.send_notification(_("Couldn’t read selection clip board!")) |
| 543 | |
| 544 | def queue_selection_translation(self, src_lang: str | None, dest_lang: str | None): |
| 545 | """Call `translate_selection` or queue it until the window is focused""" |
no test coverage detected