- 1. 作業振り分け Env.py
1. 作業振り分け Env.py
「Env.py」は、「CLI」から各種デスクトップの処理への橋渡しを行うクラスになります。
また、各デスクトップで行う共通的な処理もこのクラス内でメソッドを提供しています。
このソースは長いので、変更部分のみ掲載します。
##################################################################################
##
# LibreOffice の項目行の実行文、アイコンを設定する
# @param line 対象行
# @param nextline 対象行の次の行
# @param label 項目名
# @param exe_sentence 実行文
# @param icon アイコンファイル(拡張子なし)
def update_libreoffice(self, line, nextline, label, exe_sentence, icon):
try:
[line, nextline] = self.desktop.update_libreoffice(line, nextline, label, exe_sentence, icon)
except:
print('in Env Exception update_libreoffice')
return [line, nextline]
134~148行、まるまる新規です。
「LibreOffice」の実行モジュールとアイコンを組み立てる処理を各環境のクラスに渡しています。
######
# @brief 終了メニュー設定
# @return None 戻り値なし
# @details 終了メニューを設定すべきメニューであれば、終了メニューを設定する
def set_end_menu(self, lines):
try:
self.desktop.set_end_menu(self, lines)
except AttributeError:
pass
を下記へ変更
######
# @brief 終了メニュー設定
# @details 終了メニューを設定すべきメニューであれば、終了メニューを設定する
# @param dic_exec_icon exec → icon 辞書
# @return None 戻り値なし
def set_end_menu(self, dic_exec_icon, lines):
try:
self.desktop.set_end_menu(self, dic_exec_icon, lines)
except AttributeError:
pass
終了メニューを作成するメソッドへの引数に「実行モジュール → アイコン」辞書を増やしています。
######
# @brief デスクトップクラスに search_icon メソッドが存在すればコールする
# @return dic_exec_icon exec → icon 辞書
def get_dic_exec_icon(self):
## exec → icon 辞書
dic_exec_icon = {}
for filepath in self.find_all_file(self.directory_app):
name, extend = os.path.splitext(filepath)
if (extend != '.desktop'):
continue
f = open(filepath, "r") ## File Open
lines = f.readlines() ## Read
f.close() ## Close
pname = None ## ロードモジュール名
iname = None ## アイコン名
for i in range(0, len(lines)-1):
str = lines[i].rstrip('\n') ## 行末の改行削除
if (str.startswith('Exec')): ## ロードモジュールの行
head, pname = str.split('=', 1)
if (str.startswith('Icon')): ## icon
head, iname = str.split('=', 1)
iname = iname.lower() ## icon はすべて小文字にしちゃう
if ((pname != None) and (iname != None)): ## ロードモジュールとアイコン共に検出
pname = pname.split(' ')[0] ## 実行文はロードモジュール名のみにする
dic_exec_icon[pname] = iname ## 辞書に追加したら終了
break ## アイコンが見つかったらループは終了
try:
dic_exec_icon = self.desktop.get_dic_exec_icon(self, dic_exec_icon)
except AttributeError:
dic_exec_icon = {}
return dic_exec_icon
を
######
# @brief デスクトップクラスに search_icon メソッドが存在すればコールする
# @param dic_libreoffice_icon LibreOffice 項目名→アイコン 辞書
# @return dic_exec_icon exec → icon 辞書
def get_dic_exec_icon(self, dic_libreoffice_icon):
## exec → icon 辞書
dic_exec_icon = {}
for filepath in self.find_all_file(self.directory_app):
name, extend = os.path.splitext(filepath)
if (extend != '.desktop'):
continue
f = open(filepath, "r") ## File Open
lines = f.readlines() ## Read
f.close() ## Close
pname = None ## ロードモジュール名
iname = None ## アイコン名
for i in range(0, len(lines)-1):
if ((pname != None) and (iname != None)): ## ロードモジュールとアイコン共に検出
pname = pname.split(' ')[0] ## 実行文はロードモジュール名のみにする
dic_exec_icon[pname] = iname ## 辞書に追加したら終了
break ## アイコンが見つかったらループは終了
str = lines[i].rstrip('\n') ## 行末の改行削除
if (str.startswith('Exec')): ## ロードモジュールの行
head, pname = str.split('=', 1)
if (str.startswith('Icon')): ## icon
head, iname = str.split('=', 1)
iname = iname.lower() ## icon はすべて小文字にしちゃう
for value in dic_libreoffice_icon.values(): ## LibreOffice のアイコン
dic_exec_icon[value] = value ## 辞書に追加
try:
dic_exec_icon = self.desktop.get_dic_exec_icon(self, dic_exec_icon)
except AttributeError:
dic_exec_icon = {}
return dic_exec_icon
204行、「LibreOffice 項目名 → アイコン」辞書を入力引数として追加しています。
223~226行の、ロードモジュールとアイコンのキーワードを検出したら「break」する処理を、ループの末尾からループの先頭へ移動しました。
|