2016-03-30 8 views
2

私はpythonで作られた端末mp3playerのデスクトップショートカットを作成しようとしています。私はLubuntuを使用しています。Lubuntu Terminal Pythonデスクトップショートカット

私のプログラムは、この

#!/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() 

のように見える

あなたはそれをテストするために、pygameのダウンロードが必要になりますし、それはmp3ファイルの現在のディレクトリrecursivlyを検索するため、それが終了したとき、私はあなたの音楽フォルダでそれを実行することをお勧めしますリストを再生します。 しかし、これは私の.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 

ダブルクリックすると、スクリプトを実行せずに端末を開くだけです。 何が間違っていますか? oO

ありがとうございます。

編集:

ファイルが実行可能であると私は

sudo update-desktop-database 

を実行し、警告

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") 
+1

コマンドラインで "Exec"エントリを実行しようとしましたか?言い換えれば、スクリプトが実際に実行可能であることを確かめてください。それを実行しようとすると(ランチャーに変わる前に)正しいことが起こるのだろうか?そして、ちょうどあなたがランチャーを変更した後に "sudo update-desktop-database"を実行したことを確かめてください。変更後にランチャーを起動する前に更新が反映されていることを確認しますか? – GhostCat

+0

はい、コマンドラインから実行可能です。ターミナルに./mp3playaと入力すると実行されます。私は "sudo update-desktop-database"を試して、 "/usr/share/applications/gnumeric.desktop"ファイルで警告を受け取りました:MIMEタイプ "zz-application/zz-winassoc-xls"の使用はお勧めしません( "zz- application/zz-winassoc-xls "は" application/vnd.ms-excel "に置き換えてください)。 .desktopファイルのためにこの警告が表示されますか? :/ – BigZ

+0

まあ、警告はgnumeric.desktopファイルを指していることをはっきりと示しています。これはあなたのスクリプトとはまったく関係がありません。 – GhostCat

答えて

1

は最終的に私は欠けていたものを見つけました。

コマンド引数としてスクリプトを使用して最初にlxterminalを起動する必要がありました。

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

これは実際にはPythonスクリプトです。 "Exec = python/bla/script"も試してみてください。 – GhostCat

+0

私もそれを試しましたが、Lubuntuのlxterminalが明らかにこのような実行コマンドを望んでいるようです。 – BigZ

関連する問題