テキスト レポートを Excel スプレッドシートに変換する python2.7 プログラムがあります。
ファイルをデスクトップ アイコンにドラッグ アンド ドロップすることで実行されます。
プログラムの実行中に Windows CMD ウィンドウが開きます。
プログラムが終了すると、Windows メッセージ ボックスが表示されます。
windll.user32.MessageBoxA(None,"Finished","gen2xls",0)
メッセージ ボックスは画面に表示されますが、すぐに CMD ウィンドウの背後に移動するため、表示されません。
メッセージ ボックスが画面に表示されるとすぐに、フォーカスが CMD ウィンドウに変わるようです。
メッセージ ボックスがクリックされるまでフォーカスを維持する方法はありますか?
以下のコードを見ると、ファイルが 2 つのタイプのいずれかであるかどうかを確認するテストがあります。ファイルが 2 つのタイプのいずれでもない場合は、print ステートメント 'print 'file does not appear to be a gencount'' があり、その後に continue ステートメントが続きます。これがトリガーされると、「完了」ボックスが CMD 画面の前に表示されますが、ジョブが完了するまで実行されると、メッセージ ボックスが表示されるとすぐにフォーカスが CMD ウィンドウに変更されます。
コードの主な部分は次のとおりです。
def runexcel(args):
sheets = []
"""Convert LSC gencount to Excel file
"""
sawerror = False
print "Running gen2xls"
if len(args) == 1:
windll.user32.MessageBoxA(None,"Error: Please drag at least one file","gen2xls",0)
sys.exit(1)
try:
for fname in args[1:]:
file = open(fname,"r")
get_type = get_gen_type(file)
if get_type == -1:
print 'file does not appear to be a gencount'
continue #skip file if not a gencount (only tests for presence of pagefeed char)
if get_type[0] == 'laur':
sheets = get_l_sheets(file) #LAURA'S FORMAT:
else:
if get_type[0] == 'serg':
sheets = get_s_sheets(file,get_type[1],get_type[2]) #SERGEI'S FORMAT:
make_sheets(sheets,fname)
print "Finished Processing %s" % fname
windll.user32.MessageBoxA(None,"Finished","gen2xls",0)
except:
traceback.print_exc()
print "Errors occurred, please check the above messages"
windll.user32.MessageBoxA(None,"Error: Problems occurred, please check them and try again","gen2xls",0)
##########################################################################################
##########################################################################################
if __name__ == "__main__":
runexcel(sys.argv)