我正在 python.net 中编写一个事件处理程序,当弹出一个对话框并且我希望事件处理程序回答对话框时调用这个事件处理程序。
我想知道是否有办法从 Dialog 对象本身(类似于 args.Dialog.DialogResult='OK' 等)中回答 windows 窗体对话框,还是我必须求助于模拟人类交互(即 - 将对话框带到前面,定位按钮坐标并模拟鼠标点击)。
我附上了我用来处理事件的示例代码(来自 Agilent - http://nbviewer.ipython.org/github/jonnojohnson/Agilent/blob/master/Python_Automation/N5990A_Python_Automation.ipynb):
def my_DialogPopUp(source, args):
#args.Dialog.ShowDialog() #Uncomment to show Valiframe dialog box for all cases
msgbox = args.DialogText
# Definition for args.DialogType
#Member name Value Description
#Form 0 General Form if the dialog is not one of the other dialog types
#MessageBox 1 Standard Windows.Forms.MessageBox.
#ConnectionDialog 2 Connection dialog. The dialog which pops up if a connection change is required.
#UserInformationDialog 3 User Information Dialog, which contains a text and one button.
#UserDecisionDialog 4 User Decision Dialog, which contains one text and 2 buttons.
#InfoDialog 5 Info Dialog, which is the same as the UserInformationDialog (obsolete, will be removed in one of the next releases).
if args.DialogType == 0:
raw_input('General Form Dialog: '+str(msgbox))
# add actions here.....
# args.Dialog.ShowDialog() #Uncomment to show dialog box for this case
elif args.DialogType == 1:
raw_input('Standard Windows.Forms.MessageBox: '+str(msgbox))
# add actions here.....
# args.Dialog.ShowDialog() #Uncomment to show dialog box for this case
elif args.DialogType == 2:
raw_input('Connection Dialog: '+str(msgbox))
# add actions here.....
# args.Dialog.ShowDialog() #Uncomment to show dialog box for this case
elif args.DialogType == 3:
raw_input('UserInformationDialog: '+str(msgbox))
# add actions here.....
# args.Dialog.ShowDialog() #Uncomment to show dialog box for this case
elif args.DialogType == 4:
raw_input('UserDecisionDialog: '+str(msgbox))
# add actions here.....
# args.Dialog.ShowDialog() #Uncomment to show dialog box for this case
elif args.DialogType == 5:
raw_input('InfoDialog: '+str(msgbox))
# add actions here.....
# args.Dialog.ShowDialog() #Uncomment to show dialog box for this case
else:
raw_input('Message not handled: '+str(msgbox))