我正在编写一个小助手脚本,将X剪贴板内容转换为QR代码并显示结果,这样我就可以使用智能手机扫描代码了。
基本上,这一行bash可以工作(对于错误处理,它是10行):
xclip -o | qrencode -s 5 -o - | display -backdrop -background "#000"我得到的QR代码以全屏幕黑色背景为中心。好的。但是GraphicsMagick的display实用程序在这个场景中有一个可用性问题:我不能轻易退出它。我需要右键点击图片(而不是背景),并选择菜单上的最后一个项目,现在显示它的文本黑色的黑色。
我看到了解决这个问题的多种方法,但没有看到任何解决方案:
display实用程序退出任何事件,无论是鼠标单击还是按下键。display并以某种方式捕获UI事件。那就杀了display。基本上,我要寻找的是一种简单的方法来显示来自bash脚本的图像,以当前的X屏幕为中心,带有黑色背景(奖励:半透明的黑色背景),鼠标点击或按下键就会被驳回。另外,图片下面的一些自由形式的文字标题会很好,所以我不需要把它添加到图像中。
发布于 2013-05-11 21:48:25
好吧,不知怎么我自己写了那个图像查看器..。在飞行..。内嵌的蟒蛇和Tkinter。如果有人想要使用它,并且嵌入到bash中的python不是太可怕的想法,下面是我的“剪贴板到QR代码”bash脚本。将其保存在某个地方,使其可执行,并在您的桌面环境中注册,以便在您的面板上运行或分配启动程序。
依赖关系: python python-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上
https://stackoverflow.com/questions/16499670
复制相似问题