2013-05-11 37 views
1

我只是在編寫一個小幫手腳本來將X剪貼板內容轉換爲QR碼並顯示結果,以便我可以使用我的掃描代碼手機。在黑色全屏背景下顯示圖像,關閉任何用戶事件

基本上,這條線的bash作品(錯誤處理,這是十行):

xclip -o | qrencode -s 5 -o - | display -backdrop -background "#000" 

我得到集中在全屏黑色背景的QR碼。尼斯。但是在這種情況下,GraphicsMagick的顯示實用程序有一個可用性問題:我不能輕易退出。我需要右鍵單擊圖像(而不是背景),然後選擇現在呈現黑色文本的菜單上的最後一項。

我看到多種方法解決這個問題,但沒有看到解決其中任何一個:

  1. 獲取GraphicsMagick工具的display實用程序退出任何事件,無論是點擊鼠標或按鍵。
  2. 開始display到後臺並以某種方式捕獲UI事件。然後殺display
  3. 使用不同的圖像查看器,可以更容易地退出。沒有找到具有背景特徵的人。

基本上,我正在尋找的是從一個bash腳本,爲中心的當前X屏幕上有一個黑色的背景(獎金:半透明的黑色背景)顯示圖像的簡單方法,駁回一鼠標點擊或按鍵。此外,圖片下面的一些自由形式的文字說明會很好,所以我不用再用graphicsmagick來將它添加到圖片中。

回答

0

好吧,不知何故,我最終編寫了這個圖像查看器我自己...在飛行...與內聯蟒蛇和Tkinter。如果有人想使用它,並且在bash中嵌入的python不是太可怕的想法,這是我的「Clipboard to QR Code」bash腳本。將它保存在某個地方,使其可執行,並將其註冊到桌面環境中以在< Ctrl-Q >上運行或在面板中分配啓動器。

依賴關係:蟒蟒-TK qrencode XCLIP

#!/bin/bash 

TMPDIR=$(mktemp -d) 
trap 'rm -rf $TMPDIR; exit 1' 0 1 2 3 13 15 

if xclip -o | qrencode -s 2 -m 2 -o - > $TMPDIR/qrcode.png 
then 
    TXT=$(xclip -o) 
elif xclip -o -selection clipboard | qrencode -s 2 -m 2 -o - > $TMPDIR/qrcode.png 
then 
    TXT=$(xclip -o -selection clipboard) 
else 
    STXT=$(echo "$(xclip -o)" | head -n 1 | cut -c 1-50) 
    notify-send -i unknown "Conversion Error" "Cannot provide a QR Code for the current clipboard contents:\ 
    \ 
    $STXT ..." 
    exit 0 
fi 
echo "$TXT" > $TMPDIR/content.txt 
python - <<PYEND 
import Tkinter,Image,ImageTk 
tk = Tkinter.Tk() 
tk.geometry("%dx%d+0+0" % (tk.winfo_screenwidth(), tk.winfo_screenheight())) 
tk.wm_focusmodel(Tkinter.ACTIVE) 
def handler(event): 
    tk.quit() 
    tk.destroy() 
tk.bind("<Key>", handler) 
tk.bind("<KeyPress>", handler) 
tk.bind("<Button>", handler) 
tk.protocol("WM_DELETE_WINDOW", tk.destroy) 
txt = "" 
tkim = None 
try: 
    img = Image.open("$TMPDIR/qrcode.png").convert() 
    while (img.size[1] < tk.winfo_screenheight() * 0.4) and (img.size[0] < tk.winfo_screenwidth() * 0.45): 
     img = img.resize(([x*2 for x in img.size]), Image.NONE) 
    tkim = ImageTk.PhotoImage(img) 
    txt = file("$TMPDIR/content.txt").read() 
except Exception as e: 
    txt = "Error while retrieving text: " + str(e) 

lh = Tkinter.Label(tk, text="QR Code from Clipboard", font=("sans-serif", 12), background="#000", foreground="#FFF", justify=Tkinter.CENTER).pack(fill=Tkinter.BOTH, expand=1) 
li = Tkinter.Label(tk, image=tkim, background="#000", foreground="#FFF", justify=Tkinter.CENTER).pack(fill=Tkinter.BOTH, expand=1) 
lt = Tkinter.Label(tk, text=txt, font=("sans-serif", 9), background="#000", foreground="#FFF", justify=Tkinter.LEFT, wraplength=tk.winfo_screenwidth()*0.9).pack(fill=Tkinter.BOTH, expand=1) 
tk.overrideredirect(True) 
tk.lift() 
tk.focus_force() 
tk.grab_set() 
tk.grab_set_global() 
tk.mainloop() 
PYEND 
rm -rf $TMPDIR 
trap 0 1 2 3 13 15 

更新:現在還GitHub上:https://github.com/orithena/clip2qr