1. Ali Gholami Rudi
  2. noor

Commits

Ali Gholami Rudi  committed 103443f

gtk: add y command for copying current aya to clipboard

  • Participants
  • Parent commits d4c916b
  • Branches default

Comments (0)

Files changed (1)

File noorgtk.pyw

View file
  • Ignore whitespace
 import noor.gtkhelper.tool
 import noor.gtkhelper.writer
 import noor.i18n
-from noor import uihelpers
+from noor import uihelpers, quran
 
 
 def repeatable(func):
     def _toggle_note(self, *args, **kwds):
         self.notes.toggle()
 
+    def _copy_to_clipboard(self, text):
+        board = gtk.clipboard_get()
+        primary = gtk.clipboard_get("PRIMARY")
+        board.set_text(text)
+        if primary:
+            primary.set_text(text)
+
+    def _copy_aya(self, *args, **kwds):
+        if self.current_sura and self.current_aya:
+            text = quran.get_aya(self.quran, self.current_sura,
+                                 self.current_aya)
+            self._copy_to_clipboard(text)
+
+    def _copy_trans(self, *args, **kwds):
+        if self.current_sura and self.current_aya:
+            text = quran.get_aya(self.trans, self.current_sura,
+                                 self.current_aya)
+            self._copy_to_clipboard(text)
+
     keys = {
         gtk.keysyms.BackSpace: _backspace_number,
         gtk.keysyms.Down: _next_line,
         ord('m'): _add_bookmark,
         ord('n'): _next_aya, ord('p'): _prev_aya,
         ord('q'): _quit, ord('r'): _show_home,
-        ord('s'): _goto_sura,}
+        ord('s'): _goto_sura,
+        ord('y'): _copy_aya,}
     c_keys = {
         gtk.keysyms.Return: _goto_sura,
         ord('['): _back,
         ord('K'): _stop_player,
         ord('M'): _list_bookmarks,
         ord('A'): _add_note,
-        ord('N'): _toggle_note,}
+        ord('N'): _toggle_note,
+        ord('Y'): _copy_trans,}
     cm_keys = {
         gtk.keysyms.Return: _goto_juz,
         ord('G'): _goto_juz,