首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在尝试运行/home/andy/bin/python3 3 paste_snippets.py时出错,它是链接到键的

在尝试运行/home/andy/bin/python3 3 paste_snippets.py时出错,它是链接到键的
EN

Ask Ubuntu用户
提问于 2018-07-18 20:09:46
回答 1查看 58关注 0票数 0

我做了键盘快捷键。但当我试图运行它时,我会收到这条信息。

代码语言:javascript
复制
Error while trying to run /home/andy/bin/python3 paste_snippets.py which is
linked to the key(<Primary>Alt>a)

主键实际上是Ctrl键。

代码语言:javascript
复制
#!/usr/bin/env python3

import os
import subprocess

home = os.environ["HOME"]
directory = home+"/.config/snippet_paste"
if not os.path.exists(directory):
    os.mkdir(directory)
# create file list with snippets
files = [
    directory+"/"+item for item in os.listdir(directory) \
         if not item.endswith("~") and not item.startswith(".")
    ]
# create string list
strings = []
for file in files:
    with open(file) as src:
        strings.append(src.read())
# create list to display in option menu
list_items = ["manage snippets"]+[
    (str(i+1)+". "+strings[i].replace("\n", " ").replace\
     ('"', "'")[:20]+"..") for i in range(len(strings))
    ]
# define (zenity) option menu
test= 'zenity --list '+'"'+('" "')\
      .join(list_items)+'"'\
      +' --column="text fragments" --title="Paste snippets Ctrl V"'
# process user input
try:
    choice = subprocess.check_output(["/bin/bash", "-c", test]).decode("utf-8")
    if "manage snippets" in choice:
        subprocess.call(["nautilus", directory])
    else:
        i = int(choice[:choice.find(".")])
        # copy the content of corresponding snippet
        copy = "xclip -in -selection c "+"'"+files[i-1]+"'"
        subprocess.call(["/bin/bash", "-c", copy])
        # paste into open frontmost file
        paste = "xdotool key Control_L+v"
        subprocess.Popen(["/bin/bash", "-c", paste])
except Exception:
    pass

它在16.04很好,但在18.04不行。

我做错什么了吗?

7/18/18当从命令行运行时。

即使窗口弹出,我得到的只是

代码语言:javascript
复制
Gtk-Message: 21:23:49.927: GtkDialog mapped without a transient parent.         
This is discouraged.
EN

回答 1

Ask Ubuntu用户

发布于 2018-07-19 15:55:44

我不得不换掉这条线

代码语言:javascript
复制
   subprocess.call(["nautilus", directory])

使用

代码语言:javascript
复制
    subprocess.call(["thunar", directory]) 

我没有无名氏,但使用苏纳尔作为我的档案管理。

票数 0
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1057357

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档