MCPcopy Create free account
hub / github.com/dialect-app/dialect / translate_selection

Method translate_selection

dialect/window.py:533–542  ·  view source on GitHub ↗

Runs `translate` with the selection clipboard text

(self, src_lang: str | None, dest_lang: str | None)

Source from the content-addressed store, hash-verified

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

Callers 2

_on_is_active_changedMethod · 0.95

Calls 3

translateMethod · 0.95
send_notificationMethod · 0.95
errorMethod · 0.80

Tested by

no test coverage detected