我正在python.net中编写一个事件处理程序,当弹出一个对话框并且我希望事件处理程序回答对话框时,会调用此事件处理程序。
我想知道是否有办法从Dialog对象本身回答Windows窗体对话框(类似于args.Dialog.DialogResult ='OK'等')或者我是否必须采用模拟人工交互(即 - 将对话框置于前面,找到按钮坐标并模拟鼠标点击。)
我附上用于处理事件的示例代码(来自安捷伦 - 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))
答案 0 :(得分:0)
您可以使用AutoPy自动与表单和GUI,键盘和鼠标进行交互,我不确定如何为GUI传递的默认值,但您可以随时添加某种计时器如果在一个时间范围内没有提供任何互动,那将会做出决定......