From: NeilBrown Date: Fri, 6 Oct 2023 22:28:30 +0000 (+1100) Subject: Add QRCODE to selection menu X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=d16e2ed10049ca5af231bb20156ff26f710a2c93;p=edlib.git Add QRCODE to selection menu Signed-off-by: NeilBrown --- diff --git a/DOC/TODO.md b/DOC/TODO.md index e25e9a12..95d7d81c 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -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 diff --git a/data/modules.ini b/data/modules.ini index 74c5592f..9db8470d 100644 --- a/data/modules.ini +++ b/data/modules.ini @@ -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 index 00000000..b4702654 --- /dev/null +++ b/python/lib-qrcode.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright Neil Brown ©2023 +# 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)