我有一个python2.7程序,可以将文本报告转换成Excel电子表格。你知道吗
它是通过将文件拖放到桌面图标来运行的。你知道吗
程序运行时会打开一个Windows CMD窗口。你知道吗
程序完成后,我会显示一个windows消息框:
windll.user32.MessageBoxA(None,"Finished","gen2xls",0)
消息框会出现在屏幕上,但会立即移到CMD窗口的后面,这样您就看不到它了。你知道吗
似乎只要消息框出现在屏幕上,焦点就会立即切换到CMD窗口。你知道吗
有没有办法在单击消息框之前将焦点保持在消息框上?你知道吗
如果您查看下面的代码,会有一个测试来查看文件是否属于两种类型之一。如果文件不是这两种类型中的一种,则存在一个print语句“print”文件似乎不是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)
目前没有回答
相关问题 更多 >
编程相关推荐