2016-08-21 4 views
1

私はpip経由でretextをインストールしました。私はそれのためのアイコンをダウンロードする必要がありますが、私はretextのフォルダに "retext"を実行しない限り、それは動作しません(メニューにアイコンなし)を実現します。この「参加」は何をしていますか?

私はそれを修正しようとしましたが、私のパイソンのスキルはあまり強くありません。

現時点では、icon_pathに必要なパスを強制します。

#icon_path = 'icons/' 
icon_path = '/usr/local/lib/python3.5/site-packages/retext/icons/' 

この行の仕組みは誰か教えてください。

datadirs = [join(d, 'retext') for d in datadirs] 

ありがとうございます。

import sys 
import markups 
import markups.common 
from os.path import dirname, exists, join 

from PyQt5.QtCore import QByteArray, QLocale, QSettings, QStandardPaths 
from PyQt5.QtGui import QFont 

app_version = "6.0.1" 

settings = QSettings('ReText project', 'ReText') 

if not str(settings.fileName()).endswith('.conf'): 
     # We are on Windows probably 
     settings = QSettings(QSettings.IniFormat, QSettings.UserScope, 
       'ReText project', 'ReText') 

datadirs = QStandardPaths.standardLocations(QStandardPaths.GenericDataLocation) 
datadirs = [join(d, 'retext') for d in datadirs] 

if sys.platform == "win32": 
     # Windows compatibility: Add "PythonXXX\share\" path 
     datadirs.append(join(dirname(sys.executable), 'share', 'retext')) 

if '__file__' in locals(): 
     datadirs = [dirname(dirname(__file__))] + datadirs 

#icon_path = 'icons/' 
icon_path = '/usr/local/lib/python3.5/site-packages/retext/icons/' 
for dir in datadirs: 
     if exists(join(dir, 'icons')): 
       icon_path = join(dir, 'icons/') 
       break 
+4

'join'は最終的なimport文から来ます:' from os.path import dirname、exists、join'です。パスセグメントの結合に使用されます。詳細については、os.pathの公式のPythonドキュメントを読んでください。 'datadirs = [datadirsのdのための(d、 'retext')]は、[list comprehension](https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions)です。 'datadirs'のディレクトリパスを' retext''というパスセグメントで置き換えます。基本的に 'datadirs'のすべてのディレクトリパスのretextサブフォルダを取得しています。 –

答えて

1

これはos.path.join()です:

os.path.join(path, *paths)

がインテリジェントに一つ以上のパスコンポーネントに参加します。戻り値は、最後の部分が空の場合にのみ結果が区切り文字で終了することを意味する、末尾以外の各空白以外の部分に続く正確に1つのディレクトリ区切り文字(os.sep)を持つ*pathsのパスと任意のメンバーの連結です。コンポーネントが絶対パスの場合、以前のコンポーネントはすべて破棄され、絶対パスコンポーネントから継続します。

それがここにインポートされます:問題の

from os.path import dirname, exists, join 

ので、ライン:

datadirs = [join(d, 'retext') for d in datadirs] 

[ ... ]は、結果のリストを作成リスト内包でありますjoin(d, 'retext')datadirsの各ディレクトリに適用されます。

ので、datadirsが含まれている場合:

['/usr/local/test', '/usr/local/testing', '/usr/local/tester'] 

を次に:

[join(d, 'retext') for d in datadirs] 

は生成します:設定と

['/usr/local/test/retext', '/usr/local/testing/retext', '/usr/local/tester/retext'] 

を問題:

icon_path = '/usr/local/lib/python3.5/site-packages/retext/icons/' 

ループはforループで上書きされているので、適切なパスが見つからない限り上書きされます。

関連する問題