我是 osx 编程的新手。我正在使用 pyobjc 创建警报。我对模态窗口或对话框的理解是,模态窗口需要用户进行操作才能继续。但是,如果我使用 NSAlert 的 runModal,我仍然可以在仍然显示警报时转到其他应用程序。我对模态对话框的理解是否不正确。
class Alert(object):
def __init__(self, messageText):
super(Alert, self).__init__()
self.messageText = messageText
self.informativeText = ""
self.buttons = []
def displayAlert(self):
alert = NSAlert.alloc().init()
alert.setMessageText_(self.messageText)
alert.setInformativeText_(self.informativeText)
# alert.setAlertStyle_(NSInformationalAlertStyle)
alert.setAlertStyle_(NSCriticalAlertStyle)
for button in self.buttons:
alert.addButtonWithTitle_(button)
NSApp.activateIgnoringOtherApps_(True)
self.buttonPressed = alert.runModal()
def alert(message="Default Message", info_text="", buttons=["OK"]):
ap = Alert(message)
ap.informativeText = info_text
ap.buttons = buttons
ap.displayAlert()
return ap.buttonPressed