]> git.neil.brown.name Git - edlib.git/commitdiff
Add QRCODE to selection menu
authorNeilBrown <neil@brown.name>
Fri, 6 Oct 2023 22:28:30 +0000 (09:28 +1100)
committerNeilBrown <neil@brown.name>
Sun, 8 Oct 2023 08:09:22 +0000 (19:09 +1100)
Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
data/modules.ini
python/lib-qrcode.py [new file with mode: 0644]

index e25e9a12e00c218d2011dacfe8dc584e7080b7e2..95d7d81c96036b60e57406fe196561562186e9b4 100644 (file)
@@ -9,6 +9,8 @@ the file.
 
 ### Triage
 
+- [ ] when search succeeds near eof then trying again loops back to
+      there, redraw is strange
 - [ ] There is a "window:close" and a "Window:close" and they are
       different.  Fix this!
 - [X] unknown keysequence should be reported so e.g. if keyboard
@@ -29,7 +31,7 @@ the file.
 - [X] selection-menu item to show git-commit from list of known git
       trees
 - [ ] selection-menu item for word-count
-- [ ] selection-menu item for QR-code
+- [X] selection-menu item for QR-code
 - [ ] selection-menu sub-menu for UPPER lower Caps ??
 - [ ] selection-menu item for text-fill
 - [ ] selection-menu item for spell-check ??
@@ -212,7 +214,7 @@ Module features
 
 ### lib-qrcode
 
-- [ ] pop up window to show selection as QR code
+- [X] pop up window to show selection as QR code
 - [ ] text qrcode (qr --ascii foo) don't look right in xcb display
 
 ### workspaces
index 74c5592faa26eb0fccbeef76f2e58ea2955bb0a0..9db8470d9e1ea318d3c906af2db98b6e02cc1798 100644 (file)
@@ -172,3 +172,7 @@ lib-git =
        doc:appeared-git
        selection-menu:add-02-git
        git:view-selected-commit
+
+lib-qrcode =
+       selection-menu:add-02-qrcode
+       qrcode:view-selected-text
diff --git a/python/lib-qrcode.py b/python/lib-qrcode.py
new file mode 100644 (file)
index 0000000..b470265
--- /dev/null
@@ -0,0 +1,51 @@
+# -*- coding: utf-8 -*-
+# Copyright Neil Brown ©2023 <neil@brown.name>
+# May be distributed under terms of GPLv2 - see file:COPYING
+#
+# Create an image document from a string.  This will typicially
+# be displayed with render-imageview.
+#
+
+from edlib import *
+import qrcode
+import io
+import base64
+
+def make_qrcode_doc(focus, str1):
+    if not str1:
+        return Efalse
+    qr = qrcode.make(str1, box_size=1)
+    i = qr.get_image()
+    buf = io.BytesIO(b'')
+    i.save(buf, "PNG")
+    d = focus.call("doc:from-text", "*qr*",
+                   base64.b64encode(buf.getvalue()).decode(), ret='pane')
+    d['doc-type'] = "image"
+    d['render-default'] = "imageview"
+    d['view-default'] = "base64"
+    d['imageview:integral'] = 'yes'
+    return d
+
+def show_qr(key, focus, **a):
+    pt,mk = focus.call("doc:point", ret='marks')
+
+    if not pt or not mk:
+        return 1
+    focus.call("selection:claim")
+    focus.call("selection:discard")
+    txt = focus.call("doc:get-str", pt, mk, ret='str')
+    if not txt:
+        return 1;
+
+    d = make_qrcode_doc(focus, txt)
+    p = focus.call("PopupTile", "MD3tsa", ret='pane')
+    d.call("doc:attach-view", p, 1)
+    return 1
+
+def qr_selection_menu(key, focus, **a):
+    focus.call("menu-add", "QRCODE", " qrcode:view-selected-text")
+    return Efallthrough
+
+editor.call("global-set-command", "selection-menu:add-02-qrcode",
+                  qr_selection_menu)
+editor.call("global-set-command", "qrcode:view-selected-text", show_qr)