简体   繁体   English

Lubuntu 终端 Python 桌面快捷方式

[英]Lubuntu Terminal Python Desktop Shortcut

So im trying to create a desktop shortcut for a terminal mp3player i made in python.所以我试图为我在 python 中制作的终端 mp3player 创建一个桌面快捷方式。 I'm using Lubuntu.我正在使用 Lubuntu。

My program looks like this我的程序看起来像这样

#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import sys
import random
from sys import stdout

from pygame import mixer # Load the required library


class mp3Player(object):
    def __init__(self):
        self.mix = mixer
        self.mix.init()

    def play(self, filelist):
        for root, mp3file in filelist:
            try:
                stdout.write(root + '\n')
                stdout.write("Playing %s\n"%mp3file)

                self.mix.music.load(os.path.join(root, mp3file))
                self.mix.music.play()

                while self.mix.music.get_busy():
                    choice = raw_input("[skip, exit, pause, shuffle]\n")
                    if choice == "skip":
                        break
                    elif choice == "pause":
                        self.mix.music.pause()
                        raw_input("Press enter to continiue.")
                        self.mix.music.unpause()
                    elif choice == "shuffle":
                        random.shuffle(filelist)
                        break
                    elif choice == "exit":
                        raise KeyboardInterrupt
                    else:
                        pass

            except KeyboardInterrupt, e:
                self.mix.music.stop()
                print("User Interrupted")
                sys.exit(0)

            stdout.flush()

class mp3Files(object):
    def __init__(self):
        self.mp3player = mp3Player()
        self.filelist = []

    def search(self):
        for root, dirs, files in os.walk(os.getcwd()):
            for mp3file in files:
                if mp3file.endswith(".mp3"):
                    self.filelist.append((root, mp3file))

        self.mp3player.play(self.filelist)

def main():
    mp3 = mp3Files()
    mp3.search()

if __name__ == "__main__":
    main()

You will need pygame in order to test it and i would recommend to execute it in your music folder because it searches the current directory recursivly for mp3 files and when it's done it plays the list.您将需要 pygame 来测试它,我建议在您的音乐文件夹中执行它,因为它递归地搜索当前目录以查找 mp3 文件,并在完成后播放列表。 However, this is my .desktop file.但是,这是我的 .desktop 文件。

[Desktop Entry]
Version=1.0
Name=mp3playa
Comment=Terminal mp3player
Exec=/media/jan/Volume/Musik/mp3playa
TryExec=/media/jan/Volume/Musik/mp3playa
Terminal=true
Categories=Application
Type=Application
GenericName=Simple terminal mp3player

When i double click it, it only opens a terminal without executing the script.当我双击它时,它只打开一个终端而不执行脚本。 What am i doing wrong?我究竟做错了什么? oO oO

Thanks in advance.提前致谢。

Edit:编辑:

The file is executable and i executed该文件是可执行的,我执行了

 sudo update-desktop-database

and got a warning并收到警告

Warning in file "/usr/share/applications/gnumeric.desktop": usage of
MIME type "zz-application/zz-winassoc-xls" is discouraged ("zz-
application/zz-winassoc-xls" should be replaced with 
"application/vnd.ms-excel")

Finally found what i was missing.终于找到了我缺少的东西。

Had to start the lxterminal first with the script as command argument.必须首先使用脚本作为命令参数启动 lxterminal。

Exec=lxterminal --command="/home/jan/Schreibtisch/mp3playa/mp3playa"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM