Python - MenuMaker 日本語化 - アイコン - IceWM

クラウディア 
1. IceWM
2. ソース

1. IceWM

 これは、「IceWM」の処理を行うモジュールです。  「IceWM」のメニューファイルは

~/.icewm/menu
 で、メニューの構造は

menu "カテゴリ名" アイコンファイル名 {
    prog "アイテム名" アイコンファイル名 ロードモジュール
    prog "アイテム名" アイコンファイル名 ロードモジュール
}
 という形式になっています。  サブカテゴリを分ける場合は、「menu」をネストさせます。  「アイコンファイル名」は、オリジナルの「MenuMaker」では、カテゴリがすべて「folder」(フォルダのアイコン)となっており、「prog」の行はすべて省略形を示す「-」になっています。  「.png」も「.svg」も表示できるので、変換がないため、短いソースになります。  メニューの下に、「JWM」の再起動等のメニューが続くのですが、これの変更方法がまだわかりません(2020年6月11日)。

2. ソース

 ソースは、以下になります。
##
# @file IceWM.py
# @version 0.1
# @author 作成:show.kit
# @date 作成:2020年6月5日
# @brief IceWM の環境変数設定ファイル

import os
import pprint

##
# @class IceWM
# @brief IceWM の環境変数設定

class IceWM:

    ## IceWM::__init__
    # @brief 初期化関数
    # @return 戻り値なし

    def __init__(self):

        ## デスクトップ名
        self.frontend = 'IceWM'

        ## メニューファイル名
        self.filename = os.environ.get('HOME') + '/.icewm/menu'

        ## 項目名の先頭括弧
        self.prefix = "menu \""

        ## 項目名の括弧閉じ
        self.suffix = "\""

        ## メニューのプログラム行検出キーワード
        self.exec_keyword = 'prog'

    ##
    # メニューのカテゴリ行を日本語に変える
    # @param env            環境クラス(Openbox では未使用)
    # @param line           対象行
    # @param label_en       カテゴリ名英語
    # @param label_jp       カテゴリ名日本語
    # @param directory_icon カテゴリアイコンのディレクトリ
    # @param icon           アイコンファイル(拡張子なし)

    def update_category(self, env, line, label_en, label_jp, directory_icon, icon):

        ## カテゴリ名を英語から日本語へ

        line = line.replace(self.prefix + label_en + self.suffix, self.prefix + label_jp + self.suffix)

        ## icon 追加

        line = line.replace(' folder ', ' '+ directory_icon + '/' + icon +'.svg ')

        return line

#####
    # @brief applications/*.desktop を検索して
    #    プログラム名 → アイコンファイル名の辞書を返す
    #    Fluxbox と違って png で良い
    # @param env           環境変数クラス
    # @param dic_exec_icon .desktop より取得した編集前の exec → icon 辞書
    # @return exec → icon ファイル名フルパス の辞書

    def get_dic_exec_icon(self, env, dic_exec_icon):

        ## 有効な拡張子、ディレクトリ(どちらも優先順位順)

        effect_extend = [ '.xpm', '.png', '.svg' ]
        effect_directory = [ env.directory_xpm, env.directory_png, env.directory_icon_apps ]

        for key, value in dic_exec_icon.items():                                ## exec → icon 辞書作成
            if (os.path.exists(value)):                                         ## icon が存在する
                continue                                                        ## 終了

            elif(not '.' in value):                                             ## icon が存在しない . を含まない

                for extend in effect_extend:                                    ## 拡張子として有効なものを検索

                    for directory in effect_directory:
                        icon = directory + '/' + value + extend                 ## icon ファイル名組み立て

                        if (os.path.exists(icon)):                              ## 存在する
                            dic_exec_icon[key] = icon                           ## icon として設定する
                            break                                               ## break
                    else:
                        continue
                    break
            else:                                                               ## . を含む
                ## 苦し紛れの特殊処理(これは、あんまりだけれども)

                if (value == 'org.gnome.nautilus'):
                    value += '.svg'

                for directory in effect_directory:                              ## 有効なディレクトリ順に検索

                    icon = directory + "/" + value

                    if (os.path.exists(icon)):                                  ## フルパス/ファイル名 が存在する
                        dirname, name, extend = env.mysplit(icon)               ## フルパスを分解

                        for ef_extend in effect_extend:                         ## 拡張子として有効なものを検索
                            if (ef_extend == extend):                           ## 有効なものであれば
                                dic_exec_icon[key] = icon                       ## icon として設定する
                                break                                           ##
                else:
                    continue
                break

        return dic_exec_icon;

#####
    # @brief  icon をメニューに設定する
    # @param  line     メニューの対象行
    # @param  nextline 対象行の次の行(IceWM では使用しない)
    # @param  dic_exec_icon exec → icon 辞書
    # @return line 更新した行

    def set_menu_icon(self, line, nextline, dic_exec_icon):

        head, exeall = line.split('" - ')                                       ##
        exeall  = exeall.split(' ')
        exename = exeall[0].rstrip('\n')

        if (exename in dic_exec_icon):                                          ## exec → icon 辞書に exe が存在するならば
            line = line.replace('" - ', '" '+dic_exec_icon[exename]+' ')        ## icon 設定

        return line                                                             ## 更新がない場合そのまま返す

 これは、終了メニューやらなにやら入れているので、すごく長いソースになっています。
earthcar(アースカー)
5G CONNECT